Calling a script from Outside of MM, to edit MMdb

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

Volition
Posts: 92
Joined: Sat Jul 08, 2006 4:03 am
Location: Deep South, Mainland Australia.
Contact:

Calling a script from Outside of MM, to edit MMdb

Post by Volition »

Hi Everyone,

In an effort to sync MediaMonkey to Squeezecenter. I need to workout how to run the script below from Squeezecenter. I know that this script is being run however, i am getting no action. I also no the script works as i've run it with minor variable changes as a script within Mediamonkey.

What needs to be done to get it to work. I need to run this from a PERL script in another program. I don't want to Have MM open either.

Code: Select all

    Option Explicit

    Sub SqueezeSync(path)
       Dim str, arr, songpath, sit, itm, playdate, newrate, pldat, propdat
       Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
       if fso.FileExists(path) then
          Dim txt : Set txt = fso.OpenTextFile(path,1,False)
          SDB.Database.BeginTransaction
          Do While Not txt.AtEndOfStream
             SDB.ProcessMessages
             str = Trim(txt.ReadLine)
             arr = Split(str,"|")

    'arr(0) is Title
    'arr(1)
    'arr(2)
    'arr(3) is SongPath
    'arr(4) is Played or Rated
    'arr(5) is Date in this format 20081209074549 yyyymmddhhmmss

    'arr(6) is Rating

             songpath = Mid(arr(3),2)
             newrate = arr(6)
             Set sit = SDB.Database.QuerySongs("AND (Songs.SongPath = '"&Replace(songpath,"'","''")&"')")
             If Not (sit.EOF) Then
                Set itm = sit.Item
                if arr(4) = "rated" then
                   itm.rating = newrate
                else
                      itm.Playcounter = itm.Playcounter + 1
                      pldat = arr(5)
                         propdat = Left(pldat, 4) & "-" & Mid(pldat, 5, 2) & "-" & Mid(pldat, 7, 2) & " " & mid(pldat, 9, 2) & ":" & mid(pldat, 11, 2) & ":" & right(pldat, 2)
                         playdate = FormatDateTime(propdat)
                     if DateValue(itm.LastPlayed) < DateValue(playdate) then
                        itm.LastPlayed = playdate
                     end if
              end if
             itm.UpdateDB
             End If
          Loop
          Set sit = Nothing
          SDB.Database.Commit
       else
        exit sub
       end if
    End sub

So for example, this script basically updates the DB with track played information whenever the squeezecenter plays it. As Squeezecenter has been designed to never write to files or edit tags, it is just a player. It is a way of syncing my plays. I also use MM do create my playlists and autoplaylists as they are exceptional. Which Squeezecenter picks up. And of course i use MM to sync my ipod. So that way all my plays, ratings playtimes are updated.

I have to acknowledge the help of Erland Isaksson, who has written the Squeezecenter plugin to hang this off. Thanks kindly.

Any help would get me my dream of Squeezecenter, Mediamonkey & ipod syncronization, automated. Woohoo. Then i can move on to World Domination of course.
Peke
Posts: 17493
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Calling a script from Outside of MM, to edit MMdb

Post by Peke »

Hmm, interesting, may I suggest that you use this piece of code when executing MM from external script.

Code: Select all

Dim SDB, WSHShell, MMpath, Command, Result
Set WSHShell = CreateObject("WScript.Shell")
Result = WSHShell.AppActivate("MediaMonkey")
If Not(Result) Then
  MMpath = WSHShell.RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MediaMonkey_is1\InstallLocation")
  If MMpath <> "" Then
    Command = Chr(34)&MMpath&"mediamonkey.exe"&Chr(34)
    Result = WSHShell.Run(Command,1,0)
    While WSHShell.AppActivate("MediaMonkey") = False 
    Wend
  End If 
End If

Set SDB = CreateObject("SongsDB.SDBApplication")

SDB.ShutdownAfterDisconnect = true
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
Volition
Posts: 92
Joined: Sat Jul 08, 2006 4:03 am
Location: Deep South, Mainland Australia.
Contact:

Re: Calling a script from Outside of MM, to edit MMdb

Post by Volition »

Ahhh. thanks Peke.

However, How does our script fall into the code you provided. Does it go at the bottom, top, do I insert it in the middle.
Can you advise as to how our script falls into the code you provided?

Kind regards
DazB
Posts: 409
Joined: Mon Jun 11, 2007 4:09 am
Location: Yorkshire, UK

Re: Calling a script from Outside of MM, to edit MMdb

Post by DazB »

Hi,

It goes first. However as you ultimately want to do this with Perl, then may I suggest you control MM from it using CreateObject. I don't do Perl, so can't give any example code, but see the Wiki article for pointers.

Daz
Volition
Posts: 92
Joined: Sat Jul 08, 2006 4:03 am
Location: Deep South, Mainland Australia.
Contact:

Re: Calling a script from Outside of MM, to edit MMdb

Post by Volition »

I'll give it a go.

I'm also guessing a paste it in after the "Option Explicit" part

Stay tuned.
Peke
Posts: 17493
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Calling a script from Outside of MM, to edit MMdb

Post by Peke »

My code should go first as it Checks For Started MM and If MM i s not started It Starts it. Set SDB = CreateObject("SongsDB.SDBApplication") created ComObject variable that connects to Started MM and SDB.ShutdownAfterDisconnect = true closes MM after script is done (Note: It will End MM process overriding Shutdown procedure).

I also do not use perl but it should not be too hard to make port as all commands are standard WindowsAPI.
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
Post Reply