MonkeyMagic - MusicMagic integration for MediaMonkey

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

Moderators: Peke, Gurus

nsurg
Posts: 51
Joined: Thu Feb 16, 2006 10:32 pm

Post by nsurg »

I have no real knowledge of programming, so I didn't look too closely at what I downloaded. But when I open it in notepad, I think there have been some formatting issues that cause the script to be flawed... even to my untrained eye. Can you check your linked script file to confirm that it is formatted as it ought to be?
I ended up deleting some odd characters that were inserted and splicing some lines together that seemed to be broken up, but I'm not sure if I did it correctly. I was eventually able to get mediamonkey to startup with no errors from the autostart script, but then I right click a song and choose "get mmm list" and I get the following error:

Error #438 - Microsoft VBScript runtime error
Object doesn't support this property or method
File: "c:\program files\mediamonkey\scripts\auto\monkeymagic.vbs", line 238, column: 4

And this is with the following script that I have spliced back together:

Option Explicit

Dim MonkeyPath, MagicPath, defaultServer, MmmApiUrlBase

'MonkeyPath and MagicPath should be set to the unique prefixes of the files in
'you MediaMonkey and MusicMagic libraries respectively. This is usually just
'the drive letter, but could be a preliminary path, for example on a network
'drive. If these paths are identical, leave them blank.
MonkeyPath = "c:\" 'Path prefix to MediaMonkey Library files
MagicPath = "c:\" 'Path prefix to MusicMagic Library files

'This is the hostname of the server on which the MusicMagic server is running.
defaultServer = "localhost"

'DO NOT CHANGE ANYTHING BELOW THIS LINE!!!

MmmApiUrlBase = "http://" & defaultServer & ":10002/api/"

Sub OnStartup
Dim UI

Set UI = SDB.UI

UI.AddMenuItemSep SDB.UI.Menu_Pop_TrackList_MoreFrom, -1, -1
UI.AddMenuItemSep SDB.UI.Menu_Pop_NP_MoreFrom, -1, -1

' ... and separate it from other items
UI.AddMenuItemSep UI.Menu_TrayIcon, -1, 2

Dim MenuItem
Set MenuItem = UI.AddMenuItem(UI.Menu_Pop_TrackList, -1, -1)
MenuItem.Caption = "Get MMM Playlist from song"
MenuItem.IconIndex = 37
MenuItem.OnClickFunc = "GetMMMPlaylist"
MenuItem.UseScript = Script.ScriptPath
'MenuItem.Hint = "Track"

Set MenuItem = UI.AddMenuItem(UI.Menu_Pop_NP, -1, -1)
MenuItem.Caption = "Get MMM Playlist from song"
MenuItem.IconIndex = 37
MenuItem.OnClickFunc = "GetMMMPlaylist"
MenuItem.UseScript = Script.ScriptPath
'MenuItem.Hint = "Track"

Set MenuItem = Nothing
End Sub

Sub GetMMMPlaylist(MenuItem)
If SDB.SelectedSongList.Count = 0 Then Exit Sub

Dim Song

Set Song = SDB.SelectedSongList.Item(0)

If Not IsSeedSongValid(Song) Then
MsgBox "Couldn't create playlist from selected song. " & Song.Path & " doesn't exist in you MusicMagic Library or is not valid for Mixing."
Exit Sub
End If

Dim playList
playList = DefaultMusicMagicMix(Song)

Dim fileNames, i

fileNames = GetFilenamesFromMMMPlaylist(playlist)

For i = 0 To UBound(fileNames)
Dim songid
songid = GetSongIDFromSongPath(GetSongPath(fileNames(i)))

If IsNull(songid) Or songid = "" Then
MsgBox "Song file " & fileNames(i) & " was returned by MusicMagic in its mix, but could not be located in the MediaMonkey library."
Else
Dim songdata
Set songdata = GetSongDataBySongID(songid)
If IsObject(songdata) Then SDB.Player.PlaylistAddTrack(songdata)
Set songdata = Nothing
End If
Next
End Sub

Function IsSeedSongValid(song)
Dim status

status = MusicMagicStatus(song)

If Len(status) = 0 Then
IsSeedSongValid = False
ElseIf Left(status, 1) = "0" Then
IsSeedSongValid = False
ElseIf Left(status, 1) = "1" Then
IsSeedSongValid = True
End If
End Function

Function GetFilenamesFromMMMPlaylist(playlist)
Dim i, filename, filenames

ReDim filenames(-1)

Do While playlist <> ""
filename = ""

i = InStr(1, playlist, vbLf)

If i = 0 Then
filename = playlist
playlist = ""
Else
filename = Left(playlist, i - 1)
playlist = Mid(playlist, i)
If Left(playlist, 1) = vbLf Then playlist = Mid(playlist, 2)
End If

If filename <> "" Then
ReDim Preserve filenames(UBound(filenames) + 1)

filenames(UBound(filenames)) = filename
End If
Loop

GetFileNamesFromMMMPlaylist = filenames
End Function

Function GetSongIDFromSongPath(songPath)
Dim QueryRes

Set QueryRes = SDB.Database.OpenSQL( "SELECT id FROM Songs WHERE SongPath = '" & Replace(songPath, "'", "''") & "'")

GetSongIDFromSongPath = QueryRes.StringByIndex(0)

Set QueryRes = Nothing
End Function

Function GetSongDataBySongID(songid)
If IsNull(songid) Or songid = "" Then Exit Function

Dim songs
Set songs = SDB.Database.QuerySongs("AND songs.id = " & songid & "")

If Not songs.EOF Then
Set GetSongDataBySongID = songs.Item
End If

Set songs = Nothing
End Function

Function HttpGet(strURL)
Dim request

Set request = CreateObject("MSXML2.XMLHTTP")

request.Open "GET", strURL, False
request.send

httpget = request.responseText
End Function

Function MusicMagicStatus(song)
Dim url

url = MmmApiUrlBase & "status?song=" & URLEncode(MonkeyToMagic(song.Path))

MusicMagicStatus = HttpGet(url)
End Function

Function MusicMagicGetSong(song)
Dim url

url = MmmApiUrlBase & "getSong?song=" & URLEncode(MonkeyToMagic(song.Path))

MusicMagicGetSong = HttpGet(url)
End Function

Function DefaultMusicMagicMix(song)
DefaultMusicMagicMix = MusicMagicMix(defaultServer, song, "12", "tracks", "text")
End Function

Function MusicMagicMix(server, song, Size, sizeType, content)
Dim strScriptArgs

Dim url

If MagicPath <> MonkeyPath Then song = MonkeyToMagic(song.Path)

strScriptArgs = "song=" & URLEncode(song)
strScriptArgs = strScriptArgs & "&size=" & URLEncode(Size)
strScriptArgs = strScriptArgs & "&sizeType=" & URLEncode(sizeType)
strScriptArgs = strScriptArgs & "&content=" & URLEncode(content)

url = MmmApiUrlBase & "mix?" & strScriptArgs
MusicMagicMix = HttpGet(url)
End Function

Function MonkeyToMagic(strSong)
If UCase(Left(strSong, Len(MonkeyPath))) = UCase(MonkeyPath) Then
MonkeyToMagic = MagicPath & Mid(strSong, Len(MonkeyPath) + 1)
End If
End Function

Function MagicToMonkey(strSong)
If UCase(Left(strSong, Len(MagicPath))) = UCase(MagicPath) Then
MagicToMonkey = MonkeyPath & Mid(strSong, Len(MonkeyPath) + 1)
End If
End Function

Function GetSongPath(strSong)
Dim i
i = InStr(1, strSong, ":")
If i > 0 Then
GetSongPath = Mid(strSong, i)
Else
GetSongPath = strSong
End If
End Function

Function HexString(strText)
Dim intChar

For intChar = 1 To Len(strText)
HexString = HexString & HexChar(Mid(strText, intChar, 1))
Next
End Function

Function HexChar(strChar)
Dim hc

hc = Hex(Asc(strChar))
If Len(hc) = 1 Then hc = "0" & hc
HexChar = HexChar & "%" & hc
End Function

Function URLEncode(strText)
Dim intChar
Dim c
Dim i

For intChar = 1 To Len(strText)
c = Mid(strText, intChar, 1)
i = Asc(c)

If i >= Asc("a") And i <= Asc("z") Then
c = c
ElseIf i >= Asc("A") And i <= Asc("Z") Then
c = c
Else
c = HexChar(c)
End If

URLEncode = URLEncode & c
Next
End Function


I don't know what to make of this, and it may just be my problem... Thanks for your quick replies, by the way!
manmoth
Posts: 20
Joined: Mon Mar 20, 2006 11:04 pm
Location: Chi-town, USA
Contact:

I think I'm figuring it out

Post by manmoth »

Don't worry about not being a programmer - I am a programmer by trade and sometimes I think it's more trouble than it's worth. You're being very helpful and patient in helping me figure this out, by the way.

I won't go into the vagaries of what I think has been going on, but I think I have a handle on it now. Both the original and the second problem you mentioned (I got that one, too, btw).

Give me a chance to look at it when I get home today around 6:30 CST and I'll upload a new version on my site at

http://in2words.org/projects/MonkeyMagic

Download the version with the highest number (probably will be 0.1.3) and see what happens.
There may be no such thing as a stupid question, but I've sure met a lot of inquisitive idiots.
mjs93
Posts: 158
Joined: Fri Jun 17, 2005 3:28 am

Post by mjs93 »

Thanks to nsurg, I did get the API working by unchecking the other two boxes. Thanks for the tip, nsurg!

I will apply the 0.1.3 script when it goes up and let you know if it works. :)
manmoth
Posts: 20
Joined: Mon Mar 20, 2006 11:04 pm
Location: Chi-town, USA
Contact:

Let's try it now...

Post by manmoth »

Okay, a little later than advertised, but v0.1.3 is up now at

http://in2words.org/projects/MonkeyMagic/

Give it a go and let me know!
There may be no such thing as a stupid question, but I've sure met a lot of inquisitive idiots.
nsurg
Posts: 51
Joined: Thu Feb 16, 2006 10:32 pm

Post by nsurg »

Cool, thanks!
It works perfectly!

I am using the freeware MusicIP program, which allows for playlists that are longer than 12 without payment/registration codes, and I changed the value in your script from 12 to 100 as a test, and it works to give 100 (or probably any number)!

The one time I get errors is a fault of MusicIP, not the script... It seems that MusicIP requires constant attention to keep connected to the API thing... I can generate a playlist with your script a couple times in a row, and then for no apparent reason it quits working and gives errors. This seems to be caused by the fact the MusicIP "drops" the API service connection after about 30 (?) seconds or so. I guess it's still long enough to generate a very long playlist, though. Plus if the number for the playlist with MusicIP can be changed to generate long playlists, I guess its work is done with one lookup and connect.

It might be cool to consider prompting the user for the number of tracks to add in your script after the right-click is invoked... I'll bet that's easy to do, but I don't think I could figure it out--but this is great already. Again, thanks for sorting out the quirks.

Nice job, this will be a great way to get a "smart" shuffle based on song styles.
Last edited by nsurg on Wed Mar 22, 2006 10:07 pm, edited 1 time in total.
mjs93
Posts: 158
Joined: Fri Jun 17, 2005 3:28 am

Post by mjs93 »

Works for me! The playlist appears at the bottom of the Now Playing window. Thanks!
manmoth
Posts: 20
Joined: Mon Mar 20, 2006 11:04 pm
Location: Chi-town, USA
Contact:

How about a list of most desirable features...

Post by manmoth »

What features of MusicMagic/MusicIP would people most want implemented via MonkeyMagic?

- Dynamic mix size
- Mix size (# tracks / # MB / # minutes)?
- Artist style setting
- Variety setting

How about what to do with the generated playlist?

- Send to Now playing (what it does now)
- Create/Save/AddTo MediaMonkey playlist
- Save as normal m3u on disk
- Send to portable player

Other stuff

- Create "moods" / Create playlists from moods?
- Recreate library view like MusicMagic/MusicIP in MM
- Edit/save current default mix settings

Anything else? Which of these are people most interested in first? And is anyone interested in helping?

I'm thinking it would totally make sense to have a submenu, where you could have (just for starters)
- generate default mix (that could be set somehow) mix length/filters/genre/strictness/etc.
- generate mix dynamically selecting only the length
- advanced mix generation (presents a form)
Last edited by manmoth on Thu Mar 23, 2006 1:50 am, edited 2 times in total.
There may be no such thing as a stupid question, but I've sure met a lot of inquisitive idiots.
manmoth
Posts: 20
Joined: Mon Mar 20, 2006 11:04 pm
Location: Chi-town, USA
Contact:

Dropping connection on longer playlists?

Post by manmoth »

You got it exactly right by changing that value in the script. And yes, that's one of the first things I think it would make sense to do, is present some way to select the mix size dynamically when the user selects to generate a list. Any ideas more exactly how you'd like to see that happen?

I'll look into this apparent "dropped" connection. Does it happen only with long playlists, or short ones also? Does it ever happen the first time you use it (after not using it for a while)?
There may be no such thing as a stupid question, but I've sure met a lot of inquisitive idiots.
nsurg
Posts: 51
Joined: Thu Feb 16, 2006 10:32 pm

Post by nsurg »

The drop occurs regardless of anything that is done with scripts or mediamonkey or anything else (for me). I can hit the start button on MusicIP for connecting, and if I do nothing more than watch the preferences window for about 20 seconds the "stop" button eventually grays out (no longer available), at which time the connection seems to have dropped. It does not resume until I hit cancel, close the window, reopen the preferences window, then start it all over again for another brief moment.
It does this every single time I use musicIP, no exceptions. The program I'm using comes from http://www.musicip.com/listener/product ... -downloads

As far as automation and script revision wishes go, then, my personal desire for further options is to force the musicIP program to open, connect, generate a playlist, and close again... I'll bet that would be tough to do from within a script... but I have a setup and needs that may be different from other users. Your ideas sound great.

Thanks for this cool script.
mdhmdh31
Posts: 25
Joined: Sun Jul 04, 2004 6:54 am

Error: "Couldn't create playlist from selected song. &q

Post by mdhmdh31 »

I'm unable to get the script working. Would someone help me troubleshoot? It seems there's a problem with Function MusicMagicStatus (one of the called/nested functions), but I don't know nearly enough to fix.

Error: "Couldn't create playlist from selected song. [Song Path\name] doesn't exist in your MusicMagic library or is not valid for mixing."

Config:
- MusicIP 1.6 beta 2, with licensed registration. Installed to non-standard location C:\Program Files\Music\MusicIP Mixer.
- MediaMonkey 2.5.1.913, with licensed registration. Installed to standard location C:\Program Files\MediaMonkey, but the database is in a non-standard location D:\My Music\MediaMonkey
- VBS script MonkeyMagic.vbs is in C:\Program Files\MediaMonkey\Scripts\Auto
- VBS Script parameters set as:
-- MonkeyPath = "D:\"
-- MagicPath = "C:\"
-- defaultServer = "localhost"
- API service ON, Tivo and UPnP OFF

Other info:
- Get same error for any song I try
- I can see the songs in the library w/in MusicIP application, and generate playlist mixes fine from MusicIP
- I can open a browser window to http://localhost:10002/api, manually put in the path the song there, press "Playlist" and get a mix


Can someone help? Any assistance would be greatly appreciated!
Thanks,
David
mdhmdh31
Posts: 25
Joined: Sun Jul 04, 2004 6:54 am

Re: Error: "Couldn't create playlist from selected song

Post by mdhmdh31 »

mdhmdh31 wrote:I'm unable to get the script working. Would someone help me troubleshoot? It seems there's a problem with Function MusicMagicStatus (one of the called/nested functions), but I don't know nearly enough to fix.

Error: "Couldn't create playlist from selected song. [Song Path\name] doesn't exist in your MusicMagic library or is not valid for mixing."

Config:
- MusicIP 1.6 beta 2, with licensed registration. Installed to non-standard location C:\Program Files\Music\MusicIP Mixer.
- MediaMonkey 2.5.1.913, with licensed registration. Installed to standard location C:\Program Files\MediaMonkey, but the database is in a non-standard location D:\My Music\MediaMonkey
- VBS script MonkeyMagic.vbs is in C:\Program Files\MediaMonkey\Scripts\Auto
- VBS Script parameters set as:
-- MonkeyPath = "D:"
-- MagicPath = "C:"
-- defaultServer = "localhost"
- API service ON, Tivo and UPnP OFF

Other info:
- Get same error for any song I try
- I can see the songs in the library w/in MusicIP application, and generate playlist mixes fine from MusicIP
- I can open a browser window to http://localhost:10002/api, manually put in the path the song there, press "Playlist" and get a mix


Can someone help? Any assistance would be greatly appreciated!
Thanks,
David
Manmoth - Thanks very much for the help in resolving!

For others - in the configuration I had, the solution was to change MagicPath to D:\
Last edited by mdhmdh31 on Sat Mar 25, 2006 5:18 pm, edited 1 time in total.
mdhmdh31
Posts: 25
Joined: Sun Jul 04, 2004 6:54 am

Re: How about a list of most desirable features...

Post by mdhmdh31 »

manmoth wrote:What features of MusicMagic/MusicIP would people most want implemented via MonkeyMagic?

...

How about what to do with the generated playlist?

- Send to Now playing (what it does now)
- Create/Save/AddTo MediaMonkey playlist
- Save as normal m3u on disk
- Send to portable player

...

Anything else? Which of these are people most interested in first? And is anyone interested in helping?

I'm thinking it would totally make sense to have a submenu, where you could have (just for starters)
- generate default mix (that could be set somehow) mix length/filters/genre/strictness/etc.
- generate mix dynamically selecting only the length
- advanced mix generation (presents a form)
I'm all for early inclusion of "send to MM PlayLists." (Important for those of us who prefer to use WinAmp instead of the MM player.) It would be convenient to be able to send to .m3u as well, but to do that, there are two other options. (Use existing scripts to export .m3u from MM Playlist, or generate the .m3u natively in MusicIP.)

Thanks again,
david
Last edited by mdhmdh31 on Sat Mar 25, 2006 4:24 pm, edited 2 times in total.
manmoth
Posts: 20
Joined: Mon Mar 20, 2006 11:04 pm
Location: Chi-town, USA
Contact:

Song Path/Name doesn't exist in your MusicMagic library

Post by manmoth »

Just fyi, I already fixed mdhmdh31's problem via IM, but wanted to post the solution here for others' benefit.

MonkeyPath and MagicPath are references to the music/media library files from each of these respective programs, NOT references to the path to each of these program's application (.exe) files.

From the config posted, it was pretty clear both applications were running on the same machine, and so it was a safe assumption the library file paths would be identical. In this case, setting the two variable MonkeyPath and MagicPath both to the same path prefix, OR SETTING THEM TO "" (empty string) would work equally well.

Changing the variable to

MagicPath = "D:\"

fixed it.

Hope this helps.
There may be no such thing as a stupid question, but I've sure met a lot of inquisitive idiots.
mdhmdh31
Posts: 25
Joined: Sun Jul 04, 2004 6:54 am

Re: Song Path/Name doesn't exist in your MusicMagic library

Post by mdhmdh31 »

manmoth wrote:Just fyi, I already fixed mdhmdh31's problem via IM, but wanted to post the solution here for others' benefit.

MonkeyPath and MagicPath are references to the music/media library files from each of these respective programs, NOT references to the path to each of these program's application (.exe) files.

From the config posted, it was pretty clear both applications were running on the same machine, and so it was a safe assumption the library file paths would be identical. In this case, setting the two variable MonkeyPath and MagicPath both to the same path prefix, OR SETTING THEM TO "" (empty string) would work equally well.

Changing the variable to

MagicPath = "D:"

fixed it.

Hope this helps.
Manmoth - thanks for clarifying to me that I should have been looking for the drive the .mp3s were on, not the location of MusicIP's default.m3lib.

Great stuff you've built! Thanks again from all of us.
Last edited by mdhmdh31 on Sat Mar 25, 2006 5:16 pm, edited 1 time in total.
manmoth
Posts: 20
Joined: Mon Mar 20, 2006 11:04 pm
Location: Chi-town, USA
Contact:

Post by manmoth »

nsurg wrote:The drop occurs regardless of anything that is done with scripts or mediamonkey or anything else (for me). I can hit the start button on MusicIP for connecting, and if I do nothing more than watch the preferences window for about 20 seconds the "stop" button eventually grays out (no longer available), at which time the connection seems to have dropped. It does not resume until I hit cancel, close the window, reopen the preferences window, then start it all over again for another brief moment.
It does this every single time I use musicIP, no exceptions. The program I'm using comes from http://www.musicip.com/listener/product ... -downloads

As far as automation and script revision wishes go, then, my personal desire for further options is to force the musicIP program to open, connect, generate a playlist, and close again... I'll bet that would be tough to do from within a script... but I have a setup and needs that may be different from other users. Your ideas sound great.

Thanks for this cool script.
nsurg, I don't mean to seem as though I'm ignoring you or your problem. It sounds as though something is amiss with your MusicIP. If you could fix that (uninstall/reinstall, firewall/security software setting, etc. ?), then the script should work. Unfortunately, it would be next to impossible for me to troubleshoot your MusicIP installation.

Maybe if anyone else were experiencing the same sort of thing, there might be more information to go on?

Anyhow, you're very welcome for the script. Please still feel free to make any/all other suggested enhancements, and good luck with fixing your MusicIP so things will work for you again.
There may be no such thing as a stupid question, but I've sure met a lot of inquisitive idiots.
Post Reply