Script: Radio-DJ [MM3]

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

Moderators: Peke, Gurus

uwuerfel
Posts: 76
Joined: Tue Jan 08, 2008 3:29 pm
Location: Germany

Script: Radio-DJ [MM3]

Post by uwuerfel »

V1.2.0
- you can now specify how many songs (in %) shall be ingnored in the next shuffle list
- you can now specify how much songs should be favored that you have not heared in a long time
- progresbar while filling node
- separate ini-file
- made it a Media-Monkey installation package (mmip)

==========================================

V1.1.0
- using shuffle instead of true random
- added additional param to option dialog due to shuffle

==========================================

V1.0.0
- made it an auto script
- Cleaned up the code a bit.
- Fixed wrong trace output

==========================================

V0.4.3
Changed the code when and where options are saved to and loaded from file.

Changed logging to use random filenames for each script instance.
Logging still disabled by default.

==========================================

V0.4.2
The strange messagebox saying "Unknown name" doesn't appear anymore.
It turned out, that the subs "InitOptionSheet" and "SaveOptionSheet"
must exist, even if they are not used.

chooseWheigtedRating checks if songlists for a randomly chosen rating
are empty. If they are, another rating is generated.

Logging is disabled by default.

==========================================

V0.4.1
- I changed the error checking code completely
- A few other bugfixes (e.g. unknown variable ratesSongLists)
- changed the ratings to ranges (as Big_Berny sugested)

==========================================

Hi Folks,

I have written a script that plays music based on their ratings.


Keywords:
Auto-DJ, AutoDJ, Rating, Weighting, Radio, Radio-DJ, highly configurable


Short description:
Play music based on their rating. Allows user defined weightingsand is highly configurable. Supports Auto-DJ. Uses a Playlist as input.


Reason / Motivation:
I wanted a script where
- I could define my own weightings (and save them)
- I could define which music files should be used.
- I could use as Auto-DJ.

I searched around and found for example scripts like "RadioFreeMonkey" or "JustPlaySomething" (to mention just the best of the scripts i found), but they had not (all of) the above mentioned functionality I wanted.

All scripts I found used the whole music library.
I could either not modify the weightings or just by editing the source code.
In one case the 11 ratings of MM were internally reduced to 2 (two!) rating classes :-(

So I decided to write my own :)

Since in this forum there were some people asking for exactly such a script I post it to this forum. Have fun!

If you find bugs, have questions or have ideas for this script
please post them in this thread.

Please be patient. I will probably only have time on weekends to answer your questions.



Description for users:

Installation:
See download link at the end of this posting.
It is a MediaMonkey instalattion package, so you just have to execute it.


Note:
I use a separate ini-file sinve V1.2.0 to store the settings.
When you have used V1.1 or earlier, your settings will be copied to the new ini-file. The old values will then be removed. That means: if you want to use an earlier version afterwards, it will revert to default settings.




If you prefer to install the script manually do the following:

Copy the file RadioDJ.vbs from the installation package to the directory ...\MediaMonkey\Scripts\auto.
Edit the file ...\MediaMonkey\Scripts\Scripts.ini.
Add the following lines:

[RadioDJasAutoDJ]
FileName=auto\RadioDJ.vbs
DisplayName=Radio-DJ as Auto-DJ Plug-in
Language=VBScript
ScriptType=4

How to use:
After starting MM you have a new options dialog in "Tools / Options / RadioDJ Options".
You also have a new node "Radio-DJ Vx.x.x", but for the moment the options
are more important.

In the new Options dialog you can configure the weightings. For each rating (e.g.
bomb, half star, one star etc.) you can define a number which is the weighting.
In addition you must define the name of a playlist where the script takes the
songs from. Default name for that playlist is "RadioDJ_Input", but you can use whatever name you like.
If you want to use your whole library, just create an auto-playlist
with Status="is reachable". Personaly I prefer a playlist where I choose some genre and
a minimum rating.

Go to the Options page for Auto-DJ and select "Radio-DJ as Auto-DJ Plug-in" from the drop down list.

To start Radio-DJ open the menu "play" and enable "Auto-DJ".
Start the player.

Now you should hear songs randomly but according to the weightings you have
defined in the options dialog.

In addition to the Auto-DJ functionality there is also a new node in the MM-Tree
called "Radio-DJ Vx.x.x". This Node is populated with songs each time you enter
it. It also uses the mentioned weightings. The amount of songs that is put below
this node is also defined in the options dialog. Just change maxSongs to the
amount you prefer.


Important to know:
Reagarding the repetition of a single song, there is not only the weighting important, but also the amount of songs per rating.

Lets have a look at this example:

Code: Select all

Let's say we have the following amount of songs in MM

            Amount of
Rating      songs         
--------    --------
5   Stars   20           
4   Stars   700          
3   Stars   1000          

This brings us to the following list where I have assumed a weighting that you maybe would use.
I also computed the resulting probability for each rating and what this means in terms of
"How often is a song from this rating in my playlist?". Finaly you can see after how many
songs a song from a rating gets repeated. 

                                            Probability         Every x-th           
                Amount of                   for this            song comes          repetition
Rating          songs        Weighting      rating              from this rating    after x songs
--------        --------     ---------      ------              ----------------    -------------
5 Stars         20           20             57,14%              1,75                35
4 Stars         700          10             28,57%              3,5                 2450
3 Stars         1000         5              14,29%              7                   7000


Now I have set all the weightings to the same number.
Surprisingly this doesn't mean, that every song is played as often as each other song.
It only means, that the probability for each rating is the same. But since we have only
very few songs in the 5 star rating, a song from the 5 star rating gets repeated much
more often than every other song.

                                            Probability         Every x-th           
                Amount of                   for this            song comes          repetition
Rating          songs        Weighting      rating              from this rating    after x songs
--------        --------     ---------      ------              ----------------    -------------
5 Stars         20           10             33,33%              3                   60
4 Stars         700          10             33,33%              3                   2100
3 Stars         1000         10             33,33%              3                   3000


This is just to show you, that even with a weighting in 5 stars, that is less than the weighting
of 4 stars, songs from 5 stars still get repeated more often than other songs.

                                            Probability         Every x-th           
                Amount of                   for this            song comes          repetition
Rating          songs        Weighting      rating              from this rating    after x songs
--------        --------     ---------      ------              ----------------    -------------
5 Stars         20           5              16,67%              6                   120
4 Stars         700          20             66,67%              1,5                 1050
3 Stars         1000         5              16,67%              6                   6000


In this example you can see which weightings you would need so that every song gets repeated
more or less the same. (just in this very special example)

                                            Probability         Every x-th           
                Amount of                   for this            song comes          repetition
Rating          songs        Weighting      rating              from this rating    after x songs
--------        --------     ---------      ------              ----------------    -------------
5 Stars         20           0,35           1,2%                85,7                1714,3
4 Stars         700          12             40,0%               2,5                 1750,0
3 Stars         1000         17             56,7%               1,8                 1764,7


Btw: if you want to know after how many songs a song from a rating will probably be 
repeated, you can use this formula:

repeat_after_n_songs = amount_of_songs_in_that_rating * sum_of_all_weightings / weighting_of_that_rating

So my advice is: play with the weightings until you have your prefered settings.


Each time the script is started, it builds internal lists with songs. One list per rating.
When populating the node or the playlist in Auto-DJ mode, each song that gets added to
the node / playlist is removed from the internal list. When an internal list is empty, it gets
recreated. That way we get the shuffle.

MM starts this script quite often. Every click on the node starts this script
thus building the internal lists from scratch. When you enable or disable Auto-DJ,
the sript gets restarted. When you open / close the options dialog the script gets
restarted (you don't even need to enter the options page for Radio-DJ). And of
corse when you restart MM. (I'm not sure if this list is complete, but at least at
these occations I observed, that my script is restarted).

This could lead to the effect, that you have just heard a song. Then for some reason
the script gets restarted and you hear the same song again, since the internal list
would have been rebuilt.

To get around this situation, I have introduced the param "Skip most recently played". It means, that when populating the internal lists, for each rating the most recently x percent are ignored.

For this feature to work, the input playlist must be sorted by the atribute "Last Played" from Z..A (songs just played are on top, songs not played for a long tome are on the bottom). When usin static playlist as input for Radio-DJ, this sorting is done by the script. But if you use auto playlists as input for Radio-DJ (as I do), than you have to make sure, that the auto playlist is sorted, by yourself.

In addition you can define what I called a "Favor Factor". With this number (from 0..5) you can the the randomizer how much it should favor songs that have not been played for a long time. This is in addition the the weightings. First the weighting is choosen then within the weighting a song is choosen according to the Favor Factor. When you set the Favor Factor to zero (0) disable the Favor Factor and every song within this rating has the same posibillity (as in previous versions). When you set it to one (1), songs that have not been played for a long time get a slightly higher possibility. When you set it to five (5), songs that have not been played for a long time get a very stron emphasis.
As before: For this feature to work, the input playlist must be sorted by the atribute "Last Played" from Z..A.

Please have in mind, that MM may start this script twice (or more) at the same time
(e.g. Auto-DJ is working and click on the Radio-DJ node). If this happens, both instances
are completely independent of each other. The fact that you just created a long list of
songs in the Radio-DJ node has no influence on the songs that get played via Auto-DJ.




Description for the technically interested / script developers:


The engine of this script is a class called ratedSongList with three (main) functions called
- createRatedSongLists
- chooseRandomSong
- chooseWeightedRating

The last one (chooseWeightedRating) is probably the most important.
It returns a rating randomly but weighted. This uses the weightings i.e. the
distribution defined by the user in the option dialog.

To get the distribution, all the weightings are "added" or better, they
get placed one after another on a line.

Let's have a look at this example:
We have 3 Ratings: A, B, C
They are weighted like this:
A = 1
B = 15
C = 50

Drawn on a line this could look s.th. like this:

Code: Select all

0 1               16                                                 66
+-+---------------+--------------------------------------------------+
 A        B                                 C
The randomizer uses a uniform distribution and gives a result between 0 and 66.
If the result is between 16 and 66 the chosen weighting is C. If the result
is between 1 and 16 the chosen weighting is B. If the result is between 0
and 1 the chosen weighting is A.

Thus even if the randomizer uses a uniform distribution, the distribution
of the ratings is NOT uniform but weighted.


createRatedSongLists creates an array of SongLists.
In each SongList are only songs with the same rating. This is somewhat similar
to the rating node in MM. Just that it only has the songs coming from the
playlist defined in the options dialog and not all songs as in MM.
In addition the most recently played x% are ignored.


Finally chooseRandomSong returns a Song randomly. This uses the rating returned
by chooseRandomRating, i.e. the weighted distribution defined by the user.
The algorithm to return a song randomly but with the possibillity for the user to select a "Favor Factor" is somewhat complicated. It is documented in the code. Basically it involves the function y=(x+1)^n, where n is the Favor Factor and x is the position of the song in the sorted list. Since in the code I get a random number from which I must calculate the song, I have to build the integral of the above function and convert it to the inverse function. If somebody is really interested in this, pleas ask me in the forum. I will then be hapy to explain it in detail.


Additionally there is a class called DynamicArray. This class is the basic data structure
for the shuffle algorithm. Each item is accessible via an index, but items can be added
and removed. Internally it uses a dictionary object. When removing item, the sort oder can be kept (needs more time) or a fast remove can be done (destroys the order of the items).

Then there is a class called ConfigData that holds all the data from the options dialog.

All other code / classes is "normal" code; i.e. a class to read and write
the config data from the options dialog to an ini file. A class for trace
prints to a log file, the options dialog etc.



NOTE TO OTHER SCRIPTERS:
Do not post a modified copy or copy of the Radio-DJ script anywhere.
Modification should be posted in this thread only, and only the part
that is modified.





CIAo, uwe..


_______________________________________________________________________

Download:

http://www.mediafire.com/?sharekey=0630 ... f6e8ebb871

Installation instructions:
Just execute the installation package.
Last edited by uwuerfel on Tue Oct 27, 2009 3:21 pm, edited 12 times in total.
Peke
Posts: 17446
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Post by Peke »

Only thing you missing now is Installer ;) Good Script.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Post by Big_Berny »

Nice idea! Very useful IMHO.

But there's a problem if you use AutoRateAccurate (my autorating script) because it uses other ratings than "*0" (like 10, 20, etc.)

Ratings aren't only one number but ranges: (in the bracktes you find the default MM-rating you used)
-1 = Unknown
0-5 (0) = Bomb
6-15 (10) = 0.5
16-25 (20) = 1
26-35 (30) = 1.5
36-45 (40) = 2
46-55 (50) = 2.5
56-65 (60) = 3
66-75 (70) = 3.5
76-85 (80) = 4
86-95 (90) = 4.5
96-100 (100) = 5

If that could be fixed would be great! :)

EDIT: Didn't use it yet, just had a quick look on the code...
Last edited by Big_Berny on Sun Jan 13, 2008 4:37 pm, edited 1 time in total.
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design
m_bojangles
Posts: 105
Joined: Fri Jun 11, 2004 8:22 pm

Post by m_bojangles »

This sounds great, but I got some errors when trying to initialize the script via Tools -> Scripts

Error #5 - Microsoft VBScript runtime error
Invalid procedure call or argument: 'err.raise'
File: "C:\Program Files\MediaMonkey\Scripts\RadioDJ.vbs", Line: 586, Column: 8


After hitting OK on that, I got this second error box:
Error happened during script initialization:
Invalid procedure call or argument: 'err.raise'
uwuerfel
Posts: 76
Joined: Tue Jan 08, 2008 3:29 pm
Location: Germany

Post by uwuerfel »

m_bojangles wrote:Error #5 - Microsoft VBScript runtime error
Invalid procedure call or argument: 'err.raise'
File: "C:\Program Files\MediaMonkey\Scripts\RadioDJ.vbs", Line: 586, Column: 8
This happens if the playlist used has no songs in it.

If you have not yet defined a playlist in the options dialog, then the default list name is used "RadioDJ_Input".

Maybe it helps to just create a playlist with this name and the error disappears.

I will have a closer look how the script behaves if no playlist exists.
To be honest: that case I have never tested...


CIAo, uwe..
uwuerfel
Posts: 76
Joined: Tue Jan 08, 2008 3:29 pm
Location: Germany

Post by uwuerfel »

Big_Berny wrote:Nice idea! Very useful IMHO.
Thanks :)
Big_Berny wrote:But there's a problem if you use AutoRateAccurate (my autorating script) because it uses other ratings than "*0" (like 10, 20, etc.)

Ratings aren't only one number but ranges:
I will have a look at the code, but I think that could be fixed easily.
I didn't knew that the rarings are ranges.
Thanks for the hint.


CIAo, uwe..
uwuerfel
Posts: 76
Joined: Tue Jan 08, 2008 3:29 pm
Location: Germany

Post by uwuerfel »

Peke wrote:Only thing you missing now is Installer ;) Good Script.
I will see what I can do.
First I will fix the bugs that come up.
When it seems to be stable I'll probably provide an installer.


CIAo, uwe..
m_bojangles
Posts: 105
Joined: Fri Jun 11, 2004 8:22 pm

Post by m_bojangles »

uwuerfel wrote:If you have not yet defined a playlist in the options dialog, then the default list name is used "RadioDJ_Input".

Maybe it helps to just create a playlist with this name and the error disappears.
Thanks for the help. I created a playlist with the name you mention, basically just grabbing all my tracks.

I got a new error now:

Error #500
Variable is undefined: 'ratesSongLists'
File: blah blah, Line: 607, Column: 16
uwuerfel
Posts: 76
Joined: Tue Jan 08, 2008 3:29 pm
Location: Germany

Post by uwuerfel »

m_bojangles wrote:I got a new error now:

Error #500
Variable is undefined: 'ratesSongLists'
File: blah blah, Line: 607, Column: 16

I also found this one in the meantime... :oops:

I uploaded V0.4.1
This has all mentioned bugs corrected.

When no playlist is defined or when it has 0 songs, a messagebox appears with a warning, but the script continues. So you have a chance to set a valid playlist in the options dialog.

Thanks for trying my script and giving me feedback.


CIAo, uwe..
Guest

Post by Guest »

Hallo Uwe,

Super Sache, Dein Script. Genau, was ich suche!

Zuerst hat's mit dem neuen Update super geklappt, dann kam aber plötzlich folgende message:

Error #424 - Laufzeitfehler in Microsoft VBScript
Objekt erforderlich: 'song'
File: "C:\Programme\MediaMonkey\Scripts\RadioDJ.vbs", Line: 599, Column: 8

Irgendeine Idee?

Trotzdem nochmal ein großes Lob an Dich, mach weiter so!

Olli

_____________________________________________________________

In English: After the update to 0.4.1 the script worked fine for me a short while, then suddenly i got the message above (Object needed: 'song')
m_bojangles
Posts: 105
Joined: Fri Jun 11, 2004 8:22 pm

Post by m_bojangles »

Thanks for the fix, but I had disastrous results. I got farther this time. Initializing the script worked fine. I was able to look at the options panel. When I went into the options for AutoDJ, I set the playlist to RadioDJ plug-in for AutoDJ. When I hit OK on that options panel, I got this error:

Error #70
Permission denied
...RadioDJ.vbs, Line: 1632, Column: 12

Before and after that error a Windows pop-up box appeared that had the currently selected track in the Now Playing panel in the title bar of the window and a message that simply said "unknown name".

Then I turned on AutoDJ via the Play menu.
Then I played the third to last song in my Now Playing list.
I hit the Next Track button on the player and got the same VBS error I quoted above. It did skip to the 2nd to last track and started playing it.
I hit OK on the error message and then skipped to the last track in the Now Playing list.
Got the same error again. Hit OK.
Last song in Now Playing did start playing, but Now Playing list is not being padded with the new tracks that AutoDJ should grab.

I tried going back into Options to look at AutoDJ settings, but when I go Tools --> Options, I get the same error message and then a Windows pop-up that says Permission Denied and the Options won't open at all.

Then I turned off AutoDJ via the Play menu and tried to go to Options again and got the same error message and no Options window.

With AutoDJ off, I tried the third to last track again and then skipped ahead to the last track via the Next Track button. This time the tracks skipped ahead without the Permission Denied error.

Then I closed MM.

I restarted MM. Then I went Tools --> Options. The Windows pop-up box came up with the "Unknown name" message. I hit OK on that. It closed, but the Options never appeared.

Tried again to go Tools --> Options and this time got the same VBS Permission denied error Line 1632 that I got before.

Closed MM.

Went into my scripts folder and renamed RadioDJ.vbs to RadioDJ.vbs.org.

Restarted MM. Tried to go Tools --> Options and got this error message:
File C:\.......RadioDJ.vbs cannot be opened: The file is unavailable or you may not have permission to access it.
And I can choose Cancel, Retry, Ignore or Ignore to All.

I hit Ignore. The Windows pop-up box came up and said "Unknown name" again. And the Options panel won't appear.

Tried again and got same results.

Closed MM.

Opened my MediaMonkey.ini file. In the [Options] section, found an entry called AutoDJScriptName that was set to RadioDJ.vbs. Found a backup of the .ini file that shows that variable can be set to nothing. Scrolled down and removed the [RadioDJ] section and the [RadioDJ-Default] section. Saved the .ini file.

Restarted MM.

Went to Tools --> Options. It worked. Things seem back to normal.

It'd be great to get this script working. Is it a bug or am I doing something wrong?
Guest

Post by Guest »

Hi,

I have exactly the same problem, when setting autodj to the radiodj playlist :(

Would be a great plugin, if it worked!!!

Olli
uwuerfel
Posts: 76
Joined: Tue Jan 08, 2008 3:29 pm
Location: Germany

Post by uwuerfel »

@Olli

I hope to find and correct your bug quickly.
Unfortunately that won't help much, if I can't
find out what the other problem is.


@m_bojangles

Thanks for the detailed feedback.
This all sounds very strange and I can't reproduce it at the moment.
Here on my machine everything works fine.
I have to investigate deeper...

Please be paitient, this will probably take some time.


CIAo, uwe..
Guest

Post by Guest »

Hi Uwe,

I think, mine and m-bojangles problem is the same. Yesterday I forgot to set the Auto-DJ to the Auto-DJ-Plugin, when i got the first message.

After setting it, i experienced exactly the same as m_bojangles did.

Please, don't give up. Let's hope, it's not so difficult to fix.
I really like this plugin, although it isn't working 8)

The weighting procedure sounds great. Perfect for listening your own music instead of radio at work, as i do.

Olli
uwuerfel
Posts: 76
Joined: Tue Jan 08, 2008 3:29 pm
Location: Germany

Post by uwuerfel »

Anonymous wrote: Error #424 - Laufzeitfehler in Microsoft VBScript
Objekt erforderlich: 'song'
File: "C:\Programme\MediaMonkey\Scripts\RadioDJ.vbs", Line: 599, Column: 8
Hi Olli,

I don't understand why this happens.
There are error checks that should prevent exactly this error.

Can you reproduce it?

If you can: can you please reproduce it. When the dialogbox with the error appears, don't cklick on OK.
There is a trace file with logging information in the directory of your userprofile (see environment variable %USERPROFILE% for the path on your system). The name of the file is "trace.log".

Can you please send me this file.
Hopefully this helps me to understand what happens there.


CIAo, uwe..
Post Reply