by Grondane » Sun Nov 21, 2010 6:45 am
I couldn't get Sizzly's Dashboard solution to work, so I will be sticking to the existing plugin for now. Given the frustrations of losing a long history when it fails, though, I decided to try to find a way to recover from the problem ie to scrobble the files that should have been scrobbled but weren't.
I have therefore put together the script below, which will generate a .scrobbler.log file (the same as are generated by portable players) for the selected tracks in the Now Playing window, based on their LastPlayed date/time. The log file can then be uploaded using standard mechanisms such as via the web, eg
http://scroblr.net/ or via a standalone tool, eg
http://code.google.com/p/logscrobbler/.
It has scrobbled the Unicode characters in the tracks I have, so I am hoping that it will resolve the problems with foreign characters.
Also, it is my first attempt at a MediaMonkey script, and first bit of coding for a few years, so please be gentle
Instructions
1. Save the following code into a text file with the name "CreateScrobblerLog.vbs", in the subfolder "Scripts" of the main MediaMonkey folder.
Code: Select all
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' CreateScrobblerLog
' by Grondane
'
' Version 0.1 - 20 Nov 2010
'
' A script that allows you to recover when you
' discover that the MediaMonkey scrobbler plugin
' has failed to scrobble a bunch of the tracks
' you have been listening to.
'
' To use: select the tracks you want to Scrobble in
' the Now Playing window and run the script. A
' .scrobbler.log file will be created that can be
' uploaded to Last.fm here:
' http://scroblr.net/
' or by using a standalone tool such as this one:
' http://code.google.com/p/logscrobbler/
'
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Option Explicit
function UDate(dateval)
'Dates are scrobbled as Unix timestamps, so
'this function converts dates into that format.
UDate = DateDiff("s", "01/01/1970 00:00:00", dateval)
end function
Sub CreateLog
Dim list ' list of songs to be exported
Dim res ' results of dialogs calls
Dim win ' window
Dim winS ' window with focus
Dim daycount ' how many days to check back
daycount = 32
' Move focus to Now Playing panel, on the principle that
' only those items should be scrobbled.
Set win = SDB.UI
winS=win.MainWindowFocus
win.MainWindowFocus = 4
' Get the list of songs to be logged.
Set list = SDB.SelectedSongList
If list.count=0 Then
res = SDB.MessageBox( SDB.Localize("Select tracks to be logged, please."), mtError, Array(mbOk))
Exit Sub
End If
' Open inifile and get last used directory.
Dim iniF
Set iniF = SDB.IniFile
' Let user select the output path.
Dim path
path = iniF.StringValue( "CreateScrobblerLog", "LastCreateDir")
path = SDB.SelectFolder( path, SDB.Localize( "Select where to create the Scrobbler log."))
If path="" Then
Exit Sub
End If
If Right( path, 1)<>"\" Then
path = path & "\"
End If
' Write selected directory to the ini file.
iniF.StringValue( "CreateScrobblerLog", "LastCreateDir") = path
Set iniF = Nothing
' Use progress to notify user about the current action.
Dim Progress, ExpText
Set Progress = SDB.Progress
ExpText = SDB.Localize("Creating Log...")
Progress.Text = ExpText
' Connect to the FileSystemObject
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
' Create the output file. Creates Unicode file for compatibility with Last.fm.
Dim fout
Set fout = fso.CreateTextFile( path & ".scrobbler.log", True, True)
' Write header lines.
fout.Write "#AUDIOSCROBBLER/1.1" & CHR(10)
fout.Write "#TZ/UNKNOWN" & CHR(10)
fout.Write "#CLIENT/MEDIAMONKEY v" & SDB.VersionString & CHR(10)
Progress.MaxValue = list.count
' Iterate through the list of songs.
Dim i, itm
for i=0 to list.count-1
Set itm = list.Item(i)
' Check that the song has been played at all. Stop processing tracks if it hasn't.
If UDate(itm.LastPlayed)<0 Then
' The extra spaces in the message box are because my font is set at >100%.
' Modify to fit your settings as necessary.
res = SDB.MessageBox( SDB.Localize("Cannot Scrobble unplayed track '" & itm.Title & "'. "), mtError, Array(mbOk))
Exit For
End If
' Check when the song was last played. If more than 'daycount' days ago,
' ask whether it should be Scrobbled. Mainly intended as a sanity check.
' Note: 32 is set as the default on the assumption that NowPlaying lists won't
' last for more than a month.
If (UDate(Date)-UDate(itm.LastPlayed))>(86400 * daycount) Then
res = SDB.MessageBox( SDB.Localize("You listened to '" & itm.Title & "' over " & _
CStr(daycount) & " days ago. Do you want to stop? "), mtWarning, Array(mbYes,mbNo))
If res = 6 Then
Exit For
End If
End If
' Write the information for each track to the file.
' Note: LastPlayed is the time the track finished, but Last.fm uses the time it started, so it has to be converted.
fout.Write Join( Array(itm.ArtistName, itm.AlbumName, itm.Title, itm.TrackOrderStr, _
CStr(CInt(itm.SongLength/1000)), "L", CStr(UDate(itm.LastPlayed)-CInt(itm.SongLength/1000)), _
""), CHR(9)) & CHR(10)
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next
' Close the output file and finish.
fout.Close
' Return focus to original panel.
win.MainWindowFocus = winS
' hide progress.
Set Progress = Nothing
res = SDB.MessageBox( SDB.Localize("Log Created. "), mtInformation, Array(mbOk))
End Sub
2. In the same "Scripts" subfolder, open the "Scripts.ini" file (as an Administrator if in Windows 7 etc) and add the text below to the end of the file before saving it.
Code: Select all
[CreateScrobblerLog]
FileName=CreateScrobblerLog.vbs
ProcName=CreateLog
Order=60
DisplayName=Create a Last.FM Scrobbler Log...
Description=Generates a Log from the selected tracks in the Now Playing window.
Language=VBScript
ScriptType=0
3. Restart MediaMonkey and the script should be in the Tools/Scripts menu. Select some files in the Now Playing window, run the script, decide where you want to save it, and everything should hopefully work out OK.
I couldn't get Sizzly's Dashboard solution to work, so I will be sticking to the existing plugin for now. Given the frustrations of losing a long history when it fails, though, I decided to try to find a way to recover from the problem ie to scrobble the files that should have been scrobbled but weren't.
I have therefore put together the script below, which will generate a .scrobbler.log file (the same as are generated by portable players) for the selected tracks in the Now Playing window, based on their LastPlayed date/time. The log file can then be uploaded using standard mechanisms such as via the web, eg http://scroblr.net/ or via a standalone tool, eg http://code.google.com/p/logscrobbler/.
It has scrobbled the Unicode characters in the tracks I have, so I am hoping that it will resolve the problems with foreign characters.
Also, it is my first attempt at a MediaMonkey script, and first bit of coding for a few years, so please be gentle :)
[u]Instructions[/u]
1. Save the following code into a text file with the name "CreateScrobblerLog.vbs", in the subfolder "Scripts" of the main MediaMonkey folder.
[code]
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' CreateScrobblerLog
' by Grondane
'
' Version 0.1 - 20 Nov 2010
'
' A script that allows you to recover when you
' discover that the MediaMonkey scrobbler plugin
' has failed to scrobble a bunch of the tracks
' you have been listening to.
'
' To use: select the tracks you want to Scrobble in
' the Now Playing window and run the script. A
' .scrobbler.log file will be created that can be
' uploaded to Last.fm here:
' http://scroblr.net/
' or by using a standalone tool such as this one:
' http://code.google.com/p/logscrobbler/
'
'!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Option Explicit
function UDate(dateval)
'Dates are scrobbled as Unix timestamps, so
'this function converts dates into that format.
UDate = DateDiff("s", "01/01/1970 00:00:00", dateval)
end function
Sub CreateLog
Dim list ' list of songs to be exported
Dim res ' results of dialogs calls
Dim win ' window
Dim winS ' window with focus
Dim daycount ' how many days to check back
daycount = 32
' Move focus to Now Playing panel, on the principle that
' only those items should be scrobbled.
Set win = SDB.UI
winS=win.MainWindowFocus
win.MainWindowFocus = 4
' Get the list of songs to be logged.
Set list = SDB.SelectedSongList
If list.count=0 Then
res = SDB.MessageBox( SDB.Localize("Select tracks to be logged, please."), mtError, Array(mbOk))
Exit Sub
End If
' Open inifile and get last used directory.
Dim iniF
Set iniF = SDB.IniFile
' Let user select the output path.
Dim path
path = iniF.StringValue( "CreateScrobblerLog", "LastCreateDir")
path = SDB.SelectFolder( path, SDB.Localize( "Select where to create the Scrobbler log."))
If path="" Then
Exit Sub
End If
If Right( path, 1)<>"\" Then
path = path & "\"
End If
' Write selected directory to the ini file.
iniF.StringValue( "CreateScrobblerLog", "LastCreateDir") = path
Set iniF = Nothing
' Use progress to notify user about the current action.
Dim Progress, ExpText
Set Progress = SDB.Progress
ExpText = SDB.Localize("Creating Log...")
Progress.Text = ExpText
' Connect to the FileSystemObject
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
' Create the output file. Creates Unicode file for compatibility with Last.fm.
Dim fout
Set fout = fso.CreateTextFile( path & ".scrobbler.log", True, True)
' Write header lines.
fout.Write "#AUDIOSCROBBLER/1.1" & CHR(10)
fout.Write "#TZ/UNKNOWN" & CHR(10)
fout.Write "#CLIENT/MEDIAMONKEY v" & SDB.VersionString & CHR(10)
Progress.MaxValue = list.count
' Iterate through the list of songs.
Dim i, itm
for i=0 to list.count-1
Set itm = list.Item(i)
' Check that the song has been played at all. Stop processing tracks if it hasn't.
If UDate(itm.LastPlayed)<0 Then
' The extra spaces in the message box are because my font is set at >100%.
' Modify to fit your settings as necessary.
res = SDB.MessageBox( SDB.Localize("Cannot Scrobble unplayed track '" & itm.Title & "'. "), mtError, Array(mbOk))
Exit For
End If
' Check when the song was last played. If more than 'daycount' days ago,
' ask whether it should be Scrobbled. Mainly intended as a sanity check.
' Note: 32 is set as the default on the assumption that NowPlaying lists won't
' last for more than a month.
If (UDate(Date)-UDate(itm.LastPlayed))>(86400 * daycount) Then
res = SDB.MessageBox( SDB.Localize("You listened to '" & itm.Title & "' over " & _
CStr(daycount) & " days ago. Do you want to stop? "), mtWarning, Array(mbYes,mbNo))
If res = 6 Then
Exit For
End If
End If
' Write the information for each track to the file.
' Note: LastPlayed is the time the track finished, but Last.fm uses the time it started, so it has to be converted.
fout.Write Join( Array(itm.ArtistName, itm.AlbumName, itm.Title, itm.TrackOrderStr, _
CStr(CInt(itm.SongLength/1000)), "L", CStr(UDate(itm.LastPlayed)-CInt(itm.SongLength/1000)), _
""), CHR(9)) & CHR(10)
Progress.Value = i+1
if Progress.Terminate then
Exit For
end if
next
' Close the output file and finish.
fout.Close
' Return focus to original panel.
win.MainWindowFocus = winS
' hide progress.
Set Progress = Nothing
res = SDB.MessageBox( SDB.Localize("Log Created. "), mtInformation, Array(mbOk))
End Sub
[/code]
2. In the same "Scripts" subfolder, open the "Scripts.ini" file (as an Administrator if in Windows 7 etc) and add the text below to the end of the file before saving it.
[code]
[CreateScrobblerLog]
FileName=CreateScrobblerLog.vbs
ProcName=CreateLog
Order=60
DisplayName=Create a Last.FM Scrobbler Log...
Description=Generates a Log from the selected tracks in the Now Playing window.
Language=VBScript
ScriptType=0
[/code]
3. Restart MediaMonkey and the script should be in the Tools/Scripts menu. Select some files in the Now Playing window, run the script, decide where you want to save it, and everything should hopefully work out OK.