Auto DJ - RadioFreeMonkey

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Auto DJ - RadioFreeMonkey

Post by Risser »

This is a variation of RadioFreeMonkey as an AutoDJ script. It randomly chooses the next song based on the following criteria:
- It chooses higher rated songs more often than lower rated songs
- If you've listened to a song recently, it won't repeat for X number of days (defined in the script)
- It boosts the chances of a song being selected based on when it was last played (or added to the DB if it hasn't been played)

Also, I'm on MM3. The 'CASE WHEN' won't work in MM2, you'd have to make it an 'iif' statement. Of course, I'm not even sure if auto DJ was available in MM2.

Anyway, give it a try and let me know what you think.
Thanks,
Peter

Code: Select all

' An AutoDJ version of Radio Free Monkey
' by Peter Risser
' v1.0
' 2009-05-07

Option Explicit
'
' [AutoDJRadioFreeMonkey]
' FileName=autoDJ-RFM.vbs
' DisplayName=Radio Free Monkey
' Language=VBScript
' ScriptType=4

' %%% Add 1 to weighting for each X days since last played
Const DayFactor = 30

' %%% Anything rated this or below will not receive the 'date boost'
Const DateBoostCutoff = 1.5

' %%% The minimum number of days that must pass before a song is repeated.  Zero means, go ahead
'     and repeat it right away.
Const MinDaysRepeat = 4


Dim weightedRatingFormula, dateBoostFormula, ratingFormula, weightedPlayCountFormula
Dim daysSinceAdded : daysSinceAdded = "round((julianday('now') - julianday('1899-12-30') - Songs.DateAdded),0)"
Dim daysSincePlayed : daysSincePlayed = "round((julianday('now') - julianday('1899-12-30') - Songs.LastTimePlayed),0)"
Dim numberOfDays : numberOfDays = "CASE WHEN (lastTimePlayed > 0) THEN "&daysSincePlayed&" ELSE "&daysSinceAdded&" END"
dateBoostFormula = "Round((Songs.rating > "&(DateBoostCutoff*20)&") * "&numberOfDays &" / "&DayFactor&",3)"
ratingFormula = "((Songs.rating > 0) * Songs.rating / 10)"
weightedRatingFormula = ratingFormula & " + " & dateBoostFormula

 
Sub InitConfigSheet( Panel)
  ' TODO: Make the configurable items actual options in the dialog.
End Sub
 
 
' Panel = Panel where UI controls were previously placed by the script
' SaveConfig = Whether user pressed Ok and values in the dialog should be applied and saved (to registry, ini file, or so)
Sub CloseConfigSheet( Panel, SaveConfig)
  ' TODO: Save values to Registry, apply them to our internal variables.
End Sub
 
 
Function GenerateNewTrack
  Dim SQLStatement, TotalsSQLStatement
  Dim SELECT_Clause, SELECT_TOTALS_Clause, FROM_Clause, WHERE_Clause, ORDER_Clause
  Dim Iter, res, total, max, min, delta, cutoff, ID
  Randomize
  SELECT_Clause = " SELECT Songs.Id, "&weightedRatingFormula&" as rate "
  SELECT_TOTALS_Clause = " SELECT count(Songs.Id), max("&weightedRatingFormula&"), min("&weightedRatingFormula&") "
  FROM_Clause = " FROM Songs "
  WHERE_Clause = " WHERE " &  daysSincePlayed & " > " & MinDaysRepeat
  ORDER_Clause = " ORDER BY random(*)"
  TotalsSQLStatement = SELECT_TOTALS_Clause & FROM_Clause & WHERE_Clause
'res = SDB.MessageBox(SQLStatement, mtError, Array(mbOk))
  Set Iter = SDB.Database.OpenSQL(TotalsSQLStatement)
  total = Iter.ValueByIndex(0)
  max = Iter.ValueByIndex(1)
  min = Iter.ValueByIndex(2)
  delta = max - min
  cutoff = rnd() * delta + min

  SQLStatement = SELECT_Clause & FROM_Clause & WHERE_Clause & " and rate >= "&cutoff& ORDER_Clause

  Set Iter = SDB.Database.OpenSQL(SQLStatement)
  ID = Iter.ValueByIndex(0)
'res = SDB.MessageBox("max: "&max&"; cutoff:"&cutoff&"; result:"&Iter.ValueByIndex(1), mtError, Array(mbOk))
  Set Iter = SDB.Database.QuerySongs( "ID=" & ID)
  Set GenerateNewTrack = Iter.Item
End Function
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by nynaevelan »

Looks interesting, but out of curiosity why are AutoDJ scripts always created based on ratings? Is it possible to create them based on the number of plays, and to limit them based on certain genre's or filters?

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by rovingcowboy »

nice to see risser doing scripting he's not around much.

it wouldn't be a dj script then nynaevelan it would be a played count script.

yes it has been done but not for making play lists it has been done as part of the rating scripts to be able to set the ratings.

i also would like that little script you want just to keep the songs from repeating too often which monkey seems to do a lot of on short play sessions.

by short play sessions i mean anything shorter then 18 hours in length. 8)
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by Teknojnky »

Risser wrote:Of course, I'm not even sure if auto DJ was available in MM2.
Auto-DJ scripts are MM 3.x or higher feature.
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by nynaevelan »

rovingcowboy wrote:nice to see risser doing scripting he's not around much.

it wouldn't be a dj script then nynaevelan it would be a played count script.

yes it has been done but not for making play lists it has been done as part of the rating scripts to be able to set the ratings.

i also would like that little script you want just to keep the songs from repeating too often which monkey seems to do a lot of on short play sessions.

by short play sessions i mean anything shorter then 18 hours in length. 8)

RC:

I'm confused as to your post. I am not looking for a script to set ratings nor a script to create playlists. I want an autodj script that would make it's selections based on the playcounts instead of ratings but to exclude certain genre's, such as holiday. Or if not exclude the particular genre's, then to select the tracks from a certain filter. How is this different?? My ratings system is based on playcounts so I want the script to select songs which I like, ie I've played them over a certain amount of times. I already have playlists created for when I want to listen to those least played tracks. Every now and again I would like to have someone else pick the tracks I listen to but none of the autodj scripts meet my needs except there was an external one but I don't know sql and I prefer internal scripts so that one was not usable for me. Should I open a request for such a script??
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by rovingcowboy »

hey Teknojnky there was a script in mm 2. that would automaticlly pick songs from a playlist and add to the now playing list when all the songs in that now playing list had been played.

it was called non stop music or something like that.



nynaevelan i had thought you were wanting a script that would pick songs from any place in the library and play them, but doing so according to playcount not ratings.

:-?
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by trixmoto »

That was an "OnPlay" script, Teknojnky is correct that the "AutoDJ" scripts are new to MM3 and allow you to create a new source for MM's auto DJ rather than adding tracks manually to Now Playing as we had to before.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Guest

Re: Auto DJ - RadioFreeMonkey

Post by Guest »

nynaevelan wrote:I'm confused as to your post. I am not looking for a script to set ratings nor a script to create playlists. I want an autodj script that would make it's selections based on the playcounts instead of ratings but to exclude certain genre's, such as holiday.
Maybe RadioDJ can help you there.
Set all the weightings for the ratings to the same value -- thus effectively disabling this feature.
RadioDJ uses playlists as input and it can boost entries that come before others.
So when you are able to create a playlist (or maybe auto playlist) that is sorted according your criteria, you have what you want.

Hope that helps.
CIAo, uwe..
Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Re: Auto DJ - RadioFreeMonkey

Post by Risser »

nynaevelan wrote: I'm confused as to your post. I am not looking for a script to set ratings nor a script to create playlists. I want an autodj script that would make it's selections based on the playcounts instead of ratings but to exclude certain genre's, such as holiday. Or if not exclude the particular genre's, then to select the tracks from a certain filter. How is this different?? My ratings system is based on playcounts so I want the script to select songs which I like, ie I've played them over a certain amount of times. I already have playlists created for when I want to listen to those least played tracks. Every now and again I would like to have someone else pick the tracks I listen to but none of the autodj scripts meet my needs except there was an external one but I don't know sql and I prefer internal scripts so that one was not usable for me. Should I open a request for such a script??
So, something that weights based on playcount? If I'm reading correctly, you'd like things that have a higher playcount to be played more often?

That should be easy.

Let me see...

(5 minutes later)

I don't know if this works, but it's close. I basically subbed playcount for the complicated rating calc. So things with higher playcounts have a greater chance of getting played.
It's got the same bias problems that the other one has, but it's quick.

Peter

Edit: I forgot to exclude genres. Again this is totally untested so it probably won't work straight out of the gate, but you should be able to tweak it to make it work.

Code: Select all

' An AutoDJ the plays items with a higher playcount more often and exclude some genres
' by Peter Risser
' v1.0
' 2009-05-08

Option Explicit
'
' [AutoDJPlayCount]
' FileName=autoDJ-PlayCount.vbs
' DisplayName=Higher Play Counts are Played More Often
' Language=VBScript
' ScriptType=4


' %%% The minimum number of days that must pass before a song is repeated.  Zero means, go ahead
'     and repeat it right away.
Const MinDaysRepeat = 4

' %%% A pipe delimited list of genres to ignore.
Const ignoreGenres = "Holiday|Polka|" & _
			"Bubblegum|Cheese"



Dim daysSincePlayed : daysSincePlayed = "round((julianday('now') - julianday('1899-12-30') - Songs.LastTimePlayed),0)"
Dim badGenreList : badGenreList = Split(ignoreGenres,"|")
Dim badGenreExclusionClause : badGenreExclusionClause = ""
For i = 0 to UBound(badGenreList)
	badGenreExclusionClause = badGenreExclusionClause & " AND Songs.Genre <> '"&badGenreList(i)&"'"
Next


Sub InitConfigSheet( Panel)
  ' TODO: Make the configurable items actual options in the dialog.
End Sub
 
 
' Panel = Panel where UI controls were previously placed by the script
' SaveConfig = Whether user pressed Ok and values in the dialog should be applied and saved (to registry, ini file, or so)
Sub CloseConfigSheet( Panel, SaveConfig)
  ' TODO: Save values to Registry, apply them to our internal variables.
End Sub
 
 
Function GenerateNewTrack
  Dim SQLStatement, TotalsSQLStatement
  Dim SELECT_Clause, SELECT_TOTALS_Clause, FROM_Clause, WHERE_Clause, ORDER_Clause
  Dim Iter, res, total, max, min, delta, cutoff, ID
  Randomize
  SELECT_Clause = " SELECT Songs.Id, "&weightedRatingFormula&" as rate "
  SELECT_TOTALS_Clause = " SELECT count(Songs.Id), max(Songs.PlayCounter), min(Songs.PlayCounter) "
  FROM_Clause = " FROM Songs "
  WHERE_Clause = " WHERE " &  daysSincePlayed & " > " & MinDaysRepeat & badGenreExclusionClause
  ORDER_Clause = " ORDER BY random(*)"
  TotalsSQLStatement = SELECT_TOTALS_Clause & FROM_Clause & WHERE_Clause
'res = SDB.MessageBox(SQLStatement, mtError, Array(mbOk))
  Set Iter = SDB.Database.OpenSQL(TotalsSQLStatement)
  total = Iter.ValueByIndex(0)
  max = Iter.ValueByIndex(1)
  min = Iter.ValueByIndex(2)
  delta = max - min
  cutoff = rnd() * delta + min

  SQLStatement = SELECT_Clause & FROM_Clause & WHERE_Clause & " and Songs.PlayCounter >= "&cutoff& ORDER_Clause

  Set Iter = SDB.Database.OpenSQL(SQLStatement)
  ID = Iter.ValueByIndex(0)
'res = SDB.MessageBox("max: "&max&"; cutoff:"&cutoff&"; result:"&Iter.ValueByIndex(1), mtError, Array(mbOk))
  Set Iter = SDB.Database.QuerySongs( "ID=" & ID)
  Set GenerateNewTrack = Iter.Item
End Function
Last edited by Risser on Fri May 08, 2009 1:04 pm, edited 1 time in total.
nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by nynaevelan »

Thanks, I'll give it a whirl this weekend.

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files
rovingcowboy
Posts: 14163
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Re: Auto DJ - RadioFreeMonkey

Post by rovingcowboy »

trixmoto wrote:That was an "OnPlay" script, Teknojnky is correct that the "AutoDJ" scripts are new to MM3 and allow you to create a new source for MM's auto DJ rather than adding tracks manually to Now Playing as we had to before.
i wasn't saying he was wrong there, i just said there was a script i thought that was like the autodj scripts.
but thanks for the confirm.. 8)
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy A51 5G Android ) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.
Guest

Re: Auto DJ - RadioFreeMonkey

Post by Guest »

Am I right to conclude that this is differnt than the old RADIOFREEMONKEY script?

/Jeff
kazadharri
Posts: 109
Joined: Fri Jul 28, 2006 1:07 am

Re: Auto DJ - RadioFreeMonkey

Post by kazadharri »

My bad forgot to log in.
Risser
Posts: 184
Joined: Thu Mar 03, 2005 11:28 am

Re: Auto DJ - RadioFreeMonkey

Post by Risser »

Guest wrote:Am I right to conclude that this is differnt than the old RADIOFREEMONKEY script?
Yeah, sorta. It uses the same rating algorithm to determine which songs should be more likely to be heard, based on rating & time since last played. But it pulls the actual songs using a different (easier/less accurate) algorithm. Also, it's an autoDJ script, rather than a script that pulls up 20 random songs into a window.

So, yeah.

I've updated the RFM script for MM3 if y'all want that too.
Peter
jomtones
Posts: 145
Joined: Mon Jul 02, 2007 5:06 pm
Location: London, UK

Re: Auto DJ - RadioFreeMonkey

Post by jomtones »

Forgive me but how do I install this? I tried saving the code as AutoDJRadioFreeMonkey.vbs in the C:\Program Files\MediaMonkey\Scripts\Auto folder but can't see it after a reboot...
Post Reply