Work in progress - Modify Play Counter via script
Thanks for checking that out, Pablo. I guess it's one of those properties that Jiri thought only MM should be updating and thus made it read only via the Item object?
And double thanks for coming up with the workaround! I'll give it a shot.
I also like some of the other touches in your script such as the progress bars. I had one in my script at first, but I took it out when I wanted to reduce the script to the bare minimum to make sure that nothing else was causing me a problem. Now that you've confirmed that UpdateDB doesn't work, I'll feel safer about adding the progress bar back into my script.
Thanks again for all of your efforts.
And double thanks for coming up with the workaround! I'll give it a shot.
I also like some of the other touches in your script such as the progress bars. I had one in my script at first, but I took it out when I wanted to reduce the script to the bare minimum to make sure that nothing else was causing me a problem. Now that you've confirmed that UpdateDB doesn't work, I'll feel safer about adding the progress bar back into my script.
Thanks again for all of your efforts.
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp
Computer: p4, 2.5 ghz, 3 gb ram, win xp
I just implemented the ExecSQL method in my script, and it works great! Now, my next question: How can my script refresh the list of selected songs (or the entire Tracks pane)? Even though the database has been updated, I can't see it in MM until I manually do a refresh.
Not a big deal, but it would be nice to do...
Not a big deal, but it would be nice to do...
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp
Computer: p4, 2.5 ghz, 3 gb ram, win xp
I think there is no way to tell MM to refresh the view, but we can use what you discovered to our advantage .
Just add the lines
right after the execSQL statement. We know that does update the value of the counter in the view (not in the DB, but we took care of that with the execSQL).
Of course this solutions relies on a bug so I doubt it will still work in the next release of the scripting system, but for now it works .
Pablo
Just add the lines
Code: Select all
itm.playCounter = itm.playCounter + 1
itm.updateDB
Of course this solutions relies on a bug so I doubt it will still work in the next release of the scripting system, but for now it works .
Pablo
That's a good idea! This, then, is the latest version of my IncrPlayCntr script:
I like your scripts because of their flexibility, but this is an alternative for those cases where you might just want a "quick and dirty" PlayCounter increment. If you figure out how to update the LastPlayed column with today's date, I'll add that to the script too; otherwise, I think this version will work nicely as is.
One final question. I notice that you set Progress = Nothing in your script. In my VB programs, I usually set objects = nothing after using them, but I haven't done that in these VB Scripts because I didn't see that in some of the examples in this forum. Would it be a good idea to not only set Progress, but also List and Itm = Nothing at the end of the script too?
Code: Select all
'increments play counter
Option Explicit
Sub IncrPlayCntr
' Define variables
Dim list, itm, i
' Get list of selected tracks from MediaMonkey
Set list = SDB.SelectedSongList
If list.count=0 Then
Set list = SDB.AllVisibleSongList
End If
' Process all selected tracks
For i=0 To list.count-1
Set itm = list.Item(i)
'must use sql because itm.UpdateDB does not update the PlayCounter property
SDB.database.execSQL("UPDATE Songs SET PlayCounter=" & (itm.PlayCounter + 1) & " WHERE Id=" & itm.songID)
'refreshes screen
itm.playcounter = itm.playcounter + 1
itm.UpdateDB
Next
End Sub
One final question. I notice that you set Progress = Nothing in your script. In my VB programs, I usually set objects = nothing after using them, but I haven't done that in these VB Scripts because I didn't see that in some of the examples in this forum. Would it be a good idea to not only set Progress, but also List and Itm = Nothing at the end of the script too?
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp
Computer: p4, 2.5 ghz, 3 gb ram, win xp
Roylayer,
I'm not sure why I set Progress=nothing... I think I've seen that in another script, but it probably makes no difference at all.
With your help with date formatting, it's possible to set the LastPlayed with today's date. Just add the following after your ExecSQL statement:
This sets just the date, the hour will be 12:00 am. I tried using Now() instead of Date(), but the format doesn't match what Access expects. Do you know what is the right format for Date AND Time?
Another thing is that the LastPlayed field is not automatically refreshed. Maybe a trick similar to what I did for the counter works, but I'm not sure...
Pablo
I'm not sure why I set Progress=nothing... I think I've seen that in another script, but it probably makes no difference at all.
With your help with date formatting, it's possible to set the LastPlayed with today's date. Just add the following after your ExecSQL statement:
Code: Select all
SDB.database.execSQL("UPDATE Songs SET LastTimePlayed=#" & Date() & "# WHERE Id=" & itm.songId)
Another thing is that the LastPlayed field is not automatically refreshed. Maybe a trick similar to what I did for the counter works, but I'm not sure...
Pablo
You are correct - Setting Progress = Nothing doesn't affect the operation of the script. It does release your reference to the RAM allocated to that object, however. Depending on how VB Script (or MediaMonkey itself) works, not setting objects = Nothing could cause that RAM to stay allocated after the script ends or even after MM ends. And it could be a cumulative affect if new RAM gets allocated every time you run the script. I know how all that stuff works in VB, but I'm not sure how it works in a VBS routine executed from MM.
#2/17/2004 12:21:46 PM# is an example date/time from the LastTimePlayed column. (You can see that by viewing the Songs table from within Access. If you don't have Access, there are some freeware apps that let you view Access tables. Some of them also let you update the tables.) I hope that helps!
I'll try updating LastTimePlayed with my SQL. Thanks again.
#2/17/2004 12:21:46 PM# is an example date/time from the LastTimePlayed column. (You can see that by viewing the Songs table from within Access. If you don't have Access, there are some freeware apps that let you view Access tables. Some of them also let you update the tables.) I hope that helps!
I'll try updating LastTimePlayed with my SQL. Thanks again.
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp
Computer: p4, 2.5 ghz, 3 gb ram, win xp
here's an update of IncrPlayCntr.vbs
Thanks for the good work. Incrementing the "played#" counter was something I was looking for for quite a while now!
In case anyone is still reading this topic, I have made some minor modifications to your IncrPlayCntr script that I wanted to give back to the forum.
I don't know much about VBS programming, but it seems that what I've done is actually working:
- Now it also works on a Windows with a non-English regional setting.
- LastTimePlayed is set to "Now" which also includes the exact time of day.
- Now also the separate "Played" DB table is updated with the new data so that the information stays consistent across the database.
Hope you like it.
In case anyone is still reading this topic, I have made some minor modifications to your IncrPlayCntr script that I wanted to give back to the forum.
I don't know much about VBS programming, but it seems that what I've done is actually working:
- Now it also works on a Windows with a non-English regional setting.
- LastTimePlayed is set to "Now" which also includes the exact time of day.
- Now also the separate "Played" DB table is updated with the new data so that the information stays consistent across the database.
Hope you like it.
Code: Select all
' increments play counter
' Source: http://www.mediamonkey.com/forum/viewtopic.php?t=1461
' modified to work with a non-English date format and to also update the "Played" table.
Option Explicit
Sub IncrPlayCntr
' Define variables
Dim list, itm, i
' Get list of selected tracks from MediaMonkey
Set list = SDB.SelectedSongList
If list.count=0 Then
Set list = SDB.AllVisibleSongList
End If
' Process all selected tracks
For i=0 To list.count-1
Set itm = list.Item(i)
'must use sql because itm.UpdateDB does not update the PlayCounter property
SDB.database.execSQL("UPDATE Songs SET PlayCounter=" & (itm.PlayCounter + 1) & " WHERE Id=" & itm.songID)
SDB.database.execSQL("UPDATE Songs SET LastTimePlayed='" & Now() & "' WHERE Id=" & itm.songId)
' there is another DB table that stores when the song was played,
' so in order to stay consistent, we update this, too.
' This table is used for the "50 last played songs" playlist
SDB.database.execSQL("INSERT INTO Played (IdSong, PlayDate) VALUES (" & itm.songId & ", '" & Now() & "')")
'refreshes screen
itm.playcounter = itm.playcounter + 1
itm.UpdateDB
Next
End Sub
Thanks for sharing your work, popper! I use this script all of the time - just seconds ago, as a matter of fact. (I'm listening to some mp3s burned on a DVD through my stereo system and want to update the played# counter for them.)
I don't have time to play with your script right now, but it looks good. One thing that I think could be done is to combine the execsql statements for playcounter and lasttimeplayed into one. That should reduce the amount of time needed to do the updates, although I don't know how noticeable it would be. The format of the the update statement would be something like:
update songs set playcounter = xxx, lasttimeplayed = yyy where...
I haven't tried it myself, but it should work.
Also, thanks for your other improvements. Someone previously tried to make now() work but wasn't able to do so. I don't think that I even knew about the Played table when I first wrote the script, so it's good that you have made everything consistent now.
Thanks again!
I don't have time to play with your script right now, but it looks good. One thing that I think could be done is to combine the execsql statements for playcounter and lasttimeplayed into one. That should reduce the amount of time needed to do the updates, although I don't know how noticeable it would be. The format of the the update statement would be something like:
update songs set playcounter = xxx, lasttimeplayed = yyy where...
I haven't tried it myself, but it should work.
Also, thanks for your other improvements. Someone previously tried to make now() work but wasn't able to do so. I don't think that I even knew about the Played table when I first wrote the script, so it's good that you have made everything consistent now.
Thanks again!
That is very strange indeed. I have been using the script for a year and never had this problem, yet it happened to me tonight, before reading your note! In my case, I was trying to update far more tracks than I normally would with the script. Darn!
Happy user of MediaMonkey Gold version 2.5.5.998
Computer: p4, 2.5 ghz, 3 gb ram, win xp
Computer: p4, 2.5 ghz, 3 gb ram, win xp
I discovered it by initially trying it out on a few tracks...no probs
Tried some more OK
Tried a heap...boom
Tried less OK
Tried 37 tracks..OK
Tried 49..OK
Tried 34..boom
The quantity didn't seem to cause the problem.
I was modifying fields in a an auto playlist that showed unheard songs and wasn't refreshing the list, maybe this was the problem?
Tried some more OK
Tried a heap...boom
Tried less OK
Tried 37 tracks..OK
Tried 49..OK
Tried 34..boom
The quantity didn't seem to cause the problem.
I was modifying fields in a an auto playlist that showed unheard songs and wasn't refreshing the list, maybe this was the problem?