New Script - Remove Last Play Info

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

lasiandra
Posts: 21
Joined: Sat Jan 14, 2006 10:15 pm
Location: Rochester, NY

New Script - Remove Last Play Info

Post by lasiandra » Fri Jan 20, 2006 1:52 am

The other night I accidently left Media Monkey playing while I was downstairs. To make it worse it was my playlist of new songs that I haven't listened to yet. I wanted to remove the last played date and play counter for those songs that played while I wasn't there so I created this script.

Code: Select all

' MediaMonkey Script
'
' NAME: RemoveLastPlay.vbs
'
' DESCRIPTION: This script will remove the last played date from the database
'	and decrement the play count by 1 for the selected songs.  If the song
'	was previously played then the last played date will be the previous date
'	played.  Otherwise the last played date will be blank and the play count
'	will be set to zero.  Although the Media Monkey database is immediately 
'	updated, you will need to refresh the screen (F5) to see the changes.
'
' AUTHOR: Lasiandra ( www.lasiandra.com/MediaMonkey.html )
' DATE: January 18, 2006
'
' INSTALL: Copy to MM Scripts directory and update Scripts.ini as follows
'
'   [RemoveLastPlay]
'   FileName=RemoveLastPlay.vbs
'   ProcName=RemoveLastPlay
'   Order=7
'   DisplayName=Remove the last play information
'   Description=Change the last played date & counter back to its previous value
'   Language=VBScript
'   ScriptType=0 
'   Shortcut=Shift+BkSp
'
'   You can replace Order=7 with a value that better fits your sorting order
'   Shortcut is optional and can be removed or changed as desired
'
' INFO: This script was inspired by the following thread. Thank you for the ideas.
'	http://www.mediamonkey.com/forum/viewtopic.php?t=1461



Option Explicit 'Make sure all variables are declared

  Dim confirm	'Determines if confirmation messages should be displayed
  dim process	'Determines if the current song should be processed
  Dim result	'For the message box
  Dim msg	    'Message text
  Dim list	    'The list of selected songs
  Dim itm	    'Used to process song list
  Dim i		    'Just a loop counter
  dim sid	    'The ID of the current song
  dim lpd	    'The last played date
  dim cnt	    'The Song Play Count
  dim SQL	    'The SQL statement to execute
  dim iter	    'For traversing the returned values

Sub RemoveLastPlay 
  'Get list of selected tracks from MediaMonkey
  If SDB.SelectedSongList.count > 0 Then
	Set list = SDB.SelectedSongList
  else
    SDB.MessageBox "No tracks selected!  Please select one or more tracks.", mtError, Array(mbOk)
    Exit Sub
  End If
  
  'Assume song by song confirmation and processing
  confirm = "yes"	'Set to no to have the script process without asking
  process = "yes"
  
  'Process all selected tracks
  For i=0 To list.count-1
	Set itm = list.Item(i)
	
	'Ask for confirmation before continuing
	if confirm = "yes" then
		msg = "Remove Last Played info for song: " & itm.Title
		result = SDB.MessageBox(msg, 3, Array(mbYes,mbYesToAll,mbNo,mbNoToAll))
	
		'If response is 'yes' then process this song
		if result = 6 then	'mbYes
			process = "yes"
			
		'If response is 'yes to all' then stop asking and just process the songs
		elseif result = 10 then	'mbYesToAll
            confirm = "no"
            process = "yes"
		
		'If response is 'no' then skip this song
		elseif result = 7 then	'mbNo
			process = "no"
		
		'If response is 'no to all' then cancel the script
		elseif result = 9 then	'mbNoToAll
			confirm = "no"
			process = "no"
			msg = "Exiting without making further changes."
			SDB.MessageBox msg,1,Array(mbOk)
			exit sub
		'If response is anything else then warn and quit	
		else
		confirm = "no"
			process = "no"
			msg = "Your response was not understood, no songs were changed"
			SDB.MessageBox msg,1,Array(mbOk)
			exit sub
		end if
	end if
  
	if process = "yes" then
		ProcessSong
	end if
   Next
  
End Sub 

Sub ProcessSong	
	sid = itm.songId

	'*****	
	'Delete the last played date from Played table
	'*****
    SQL= "DELETE IDPlay FROM Played WHERE PlayDate = "
	SQL = SQL & "(SELECT Max(PlayDate) FROM Played WHERE IdSong = " & sid & ")"
	SDB.database.execSQL(SQL)
	itm.UpdateDB
	
	'*****
	'Update the Song Table to reflect the new last played date
	'*****
	'Get the New Last played date for the selected song
    SQL = "SELECT Max(PlayDate) FROM Played WHERE IdSong = " & sid
    set iter = SDB.Database.OpenSQL(SQL)

	If iter.EOF OR iter.StringByIndex(0) = "" Then
		'No Last Played Date exists so clear Last Played in Song table
		'and make the Play Counter 0
		SQL = "UPDATE Songs SET Songs.LastTimePlayed = null,"
		SQL = SQL & "PlayCounter = 0 "
		SQL = SQL & "WHERE (Songs.ID = " & sid & ")"
		SDB.database.execSQL(SQL)
	Else
		'Update the Song table with new Last Played Date from Played
		'And decrement the Play Counter by 1
		lpd = iter.StringByIndex(0)
		cnt = (itm.PlayCounter - 1)
		if cnt < 0 then cnt = 0 'make sure count does not become negative
		SQL= "UPDATE Songs SET Songs.LastTimePlayed = '"  & lpd & "', "
		SQL = SQL & "PlayCounter= " & cnt 
		SQL = SQL & " WHERE (Songs.ID = " & sid & ")"
		SDB.database.execSQL(SQL)
		itm.playCounter = itm.playCounter 
	End If
	
End Sub
It is the first script that I wrote so any feedback or advice would be appreciated.

Thanks.
~Lasiandra :o

TheseusWrex
Posts: 2
Joined: Thu Jun 30, 2016 10:13 am

Re: New Script - Remove Last Play Info

Post by TheseusWrex » Sat May 13, 2017 12:52 pm

I added this script to my scripts folder, but I don't see it under the Scripts menu when I start up MM. Am I missing something?

Peke
Posts: 11203
Joined: Tue Jun 10, 2003 7:21 pm
Location: Serbia
Contact:

Re: New Script - Remove Last Play Info

Post by Peke » Sun May 21, 2017 8:16 pm

I guess you haven't follow "INSTALL: Copy to MM Scripts directory and update Scripts.ini as follows"

Code: Select all

[RemoveLastPlay]
FileName=RemoveLastPlay.vbs
ProcName=RemoveLastPlay
Order=7
DisplayName=Remove the last play information
Description=Change the last played date & counter back to its previous value
Language=VBScript
ScriptType=0
Shortcut=Shift+BkSp
Best regards,
Pavle
MediaMonkey lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
How to add Images to forum

Post Reply