Page 1 of 2

Auto DJ - RadioFreeMonkey

Posted: Thu May 07, 2009 11:41 am
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

Re: Auto DJ - RadioFreeMonkey

Posted: Thu May 07, 2009 11:56 am
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

Re: Auto DJ - RadioFreeMonkey

Posted: Thu May 07, 2009 1:34 pm
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)

Re: Auto DJ - RadioFreeMonkey

Posted: Thu May 07, 2009 1:43 pm
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.

Re: Auto DJ - RadioFreeMonkey

Posted: Thu May 07, 2009 5:18 pm
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??

Re: Auto DJ - RadioFreeMonkey

Posted: Fri May 08, 2009 1:03 am
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.

:-?

Re: Auto DJ - RadioFreeMonkey

Posted: Fri May 08, 2009 4:31 am
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.

Re: Auto DJ - RadioFreeMonkey

Posted: Fri May 08, 2009 6:05 am
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..

Re: Auto DJ - RadioFreeMonkey

Posted: Fri May 08, 2009 12:55 pm
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

Re: Auto DJ - RadioFreeMonkey

Posted: Fri May 08, 2009 12:59 pm
by nynaevelan
Thanks, I'll give it a whirl this weekend.

Nyn

Re: Auto DJ - RadioFreeMonkey

Posted: Fri May 08, 2009 3:52 pm
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)

Re: Auto DJ - RadioFreeMonkey

Posted: Sat May 09, 2009 2:23 pm
by Guest
Am I right to conclude that this is differnt than the old RADIOFREEMONKEY script?

/Jeff

Re: Auto DJ - RadioFreeMonkey

Posted: Sun May 10, 2009 12:04 pm
by kazadharri
My bad forgot to log in.

Re: Auto DJ - RadioFreeMonkey

Posted: Mon May 11, 2009 11:29 am
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

Re: Auto DJ - RadioFreeMonkey

Posted: Fri Aug 07, 2009 3:29 am
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...