New *basic* Script to insert fake plays from iPod

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan » Thu Mar 13, 2008 9:14 am

Ok, thank you, will try running it again.

Nyn

EDIT: This is awesome, I had alot that needed fake plays.
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files

brianon
Posts: 78
Joined: Wed Dec 07, 2005 4:48 am

Post by brianon » Thu Mar 13, 2008 11:56 am

Christoph. You can take full control now if you like :)
Image

Christoph
Posts: 236
Joined: Fri Jan 25, 2008 12:43 pm

Post by Christoph » Thu Mar 13, 2008 12:16 pm

Ok, thank you very much.
Is it ok for you to write "Based on the FakePlays script by brianon. Now developed by Christoph."?

nynaevelan, from your point of you, could it be right, that your songs needed many fake plays? In my archive, it's right because I increase the play counter by myself when I played some songs on my mp3 player.

Christoph

brianon
Posts: 78
Joined: Wed Dec 07, 2005 4:48 am

Post by brianon » Thu Mar 13, 2008 12:20 pm

Christoph wrote:Ok, thank you very much.
Is it ok for you to write "Based on the FakePlays script by brianon. Now developed by Christoph."?

Christoph
Thats cool. And good work btw.
Image

Christoph
Posts: 236
Joined: Fri Jan 25, 2008 12:43 pm

Post by Christoph » Thu Mar 13, 2008 12:28 pm

Thanks. :)
I'll try my best. I'm totally new to VBScript. This is my first project with this language. ;) Usually I'm working with JS, PHP, C# and so on. I'm thinking about an extended version which gives more control about the play dates. I think I would create it with C#. Let's see.

Christoph

nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan » Thu Mar 13, 2008 1:11 pm

Christoph wrote:Ok, thank you very much.
Is it ok for you to write "Based on the FakePlays script by brianon. Now developed by Christoph."?

nynaevelan, from your point of you, could it be right, that your songs needed many fake plays? In my archive, it's right because I increase the play counter by myself when I played some songs on my mp3 player.

Christoph
Yes it would be because there was a time when I was beta testing before the import database feature was available that I used Berny's import play counts script, so I was not suprised I had over 2000 that needed at least 1 fake date. I wanted the report because I wanted to check to make sure it consisted mostly of my "favorites". Also, since MM doesn't import play data from a Creative device, I had to manually change some play counts using the Set Playcount script. I am very eager to get home and try it on my main database to see how the true numbers will affect my Play History stats.

Thanks for this one.

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files

Christoph
Posts: 236
Joined: Fri Jan 25, 2008 12:43 pm

Post by Christoph » Thu Mar 13, 2008 3:02 pm

Ok, in this case, all should be correct.
I noticed that the script adds floats in the played table with the wrong separator "," if you're working with a German windows.

I've added a little correction option that will fix this issue. You can activate it in line 32.

Christoph

Edit: Removed old code.
Last edited by Christoph on Sun Mar 16, 2008 4:06 pm, edited 1 time in total.

nynaevelan
Posts: 5559
Joined: Wed Feb 07, 2007 11:07 pm
Location: New Jersey, USA
Contact:

Post by nynaevelan » Sun Mar 16, 2008 3:49 pm

Question:

If the script scans 8000 tracks and it finds 80 that need to have fake plays inserted, why does it tag all 8000 tracks, shouldn't it only be making adjustments to the 80 that need the fake plays??

Nyn
3.2x - Win7 Ultimate (Zen Touch 2 16 GB/Zen 8GB)
Link to Favorite Scripts/Skins

Join Dropbox, the online site to share your files

Christoph
Posts: 236
Joined: Fri Jan 25, 2008 12:43 pm

Post by Christoph » Sun Mar 16, 2008 4:00 pm

Hi Nyn,
that's right. I'll look into it.

Christoph

Christoph
Posts: 236
Joined: Fri Jan 25, 2008 12:43 pm

Post by Christoph » Sun Mar 16, 2008 4:05 pm

Hello again,
this issue should be fixed now.

Christoph

Code: Select all

' MediaMonkey Script
'
' NAME: FakePlays
'
' AUTHOR: Based on the FakePlays script by brianon. Now developed by Christoph.
' Start Date : 29-03-2008
'
'---------------------------------------------------------------------------------------------------------
' Ver 1.3.2 (16 Mar 2008)
'---------------------------------------------------------------------------------------------------------

Dim region
Dim simu
Sub FakePlays
	Dim DB : Set DB = SDB.Database
	Dim list, itm, i
	Dim trackPlayCount, trackPlayDates, fakePlaysToCreate
	Dim strSQL, sqlQry
	Dim formattedAddedDate, dateToInsert
	Dim secondsDiff
	Dim lastSyncDate
	Dim bHasSyncDate
	Dim corr
	
	If CDbl("1,0")=1.0 Then
		region=true
	Else
		region=false
	End If

	simu=True 'Activate this for report generation
'	corr=True 'Activate this for correcting the "," problem in the "played" database


	If corr=True Then
		SDB.Progress.Text="Correcting..."
		Set sq=SDB.Database.OpenSQL("SELECT IDPlayed,PlayDate FROM Played WHERE playdate LIKE '%,%'")
		While Not sq.EOF
			DB.ExecSQL("UPDATE Played SET PlayDate="&Replace(sq.StringByName("PlayDate"),",",".")&" WHERE IDPlayed="&sq.StringByName("IDPlayed"))
			sq.Next
		WEnd
		Set sqlQry=Nothing
		SDB.Database.Commit
		SDB.Progress=Nothing
		Exit Sub
	End If
	
	'Create any temp tables we want and remove any from previous release if required.
	DB.ExecSQL("CREATE TABLE IF NOT EXISTS tmpLastFakeSync (SongId INTEGER PRIMARY KEY, SyncDate VbDateTime)")
	'DB.ExecSQL("DROP TABLE tmpLastFakeSync")

	'Set up progress
	Set Progress = SDB.Progress

	'Get list of selected tracksfrom MediaMonkey
	Set list = SDB.CurrentSongList
	If list.Count=0 Then
	Exit Sub
	End If

	Progress.Text = "Processing tracks..."

	'Create the Report File
	If Simu=True Then
		Set f=CreateObject("Scripting.FileSystemObject")
		Set file=f.OpenTextFile(Script.ScriptPath&".log",2,true)
		file.WriteLine "FakePlay Log"
		file.WriteLine "------------"
	End If

	'Process all selected tracks
	SDB.Database.BeginTransaction
	For i=0 To list.count-1
		Progress.Text = "Processing track "&(i+1)&"/"&list.count&"..."
		Set itm = list.Item(i)

		'Get the start (BEGIN) date
		Set sqlQry = SDB.Database.OpenSQL("SELECT tmpLastFakeSync.SyncDate AS LastSyncDate FROM tmpLastFakeSync WHERE tmpLastFakeSync.SongId="&itm.ID)
		lastSyncDate = prepareDouble(sqlQry.StringByName("LastSyncDate"))


		If lastSyncDate = "" Then
			bHasSyncDate = false

			'here we get the date this track was added to the library
			Set sqlQry = SDB.Database.OpenSQL("SELECT Songs.DateAdded AS TrackAddedDate FROM Songs WHERE Songs.ID="&itm.ID)
			lastSyncDate = prepareDouble(sqlQry.StringByName("TrackAddedDate"))
			formattedSyncDate = FormatDateTime(lastSyncDate,2)&" "&FormatDateTime(lastSyncDate,3)
		Else
			bHasSyncDate = True
			formattedSyncDate = FormatDateTime(lastSyncDate,2)&" "&FormatDateTime(lastSyncDate,3)
		End If

		'here we get the playcount of the current track
		trackPlayCount = itm.PlayCounter

		'here we get the number of time/date entries for this track from SQL query
		Set sqlQry = SDB.Database.OpenSQL("SELECT Count(Played.IdSong) AS CountOfPlays FROM Played WHERE Played.IdSong="&itm.ID)
		trackPlayDates = sqlQry.StringByName("CountOfPlays")

		'get the difference
		fakePlaysToCreate = trackPlayCount - trackPlayDates
		If Simu=True Then
		End If

		' only continue if we have fake plays to create
		' **TODO: could increment/decrement playcounter to match actual plays ?
		If fakePlaysToCreate > 0 Then

			'now we need to determine how many seconds we should add to our starting date each time
			'we add a fake entry
			secondsToAdd = calcSecondsToAdd(formattedSyncDate, fakePlaysToCreate)

			If Simu=True Then
				file.WriteLine "Insert "&fakePlaysToCreate&" fake plays: "&itm.Path&"("&itm.ID&")"
			Else

				dateToInsert = formattedSyncDate
				'now create 'X' fake plays. For each play missing, add a 'dummy'
				For x=0 To fakePlaysToCreate-1

					dateToInsert = DateAdd("s",secondsToAdd, dateToInsert)
					DB.ExecSQL("INSERT INTO Played (IdSong, PlayDate) VALUES ("&itm.ID&",'"&Replace(Cdbl(dateToInsert),",",".")&"')")
				Next
				' update the last played date
				If itm.lastPlayed<CDbl(dateToInsert) Then
					itm.lastPlayed=CDbl(dateToInsert)
				End If

				' now update our FakeSynList or add a new entry
				If bHasSyncDate = true Then
					DB.ExecSQL("UPDATE tmpLastFakeSync SET SyncDate = '" & Now() &"' WHERE SongId = " &itm.ID)
				Else
					DB.ExecSQL("INSERT INTO tmpLastFakeSync (SongId, SyncDate) values ("& itm.ID &", '" & Now() &"')")
				End If
			End If


		ElseIf trackPlayCount>0 Then
			Set sqlQry = SDB.Database.OpenSQL("SELECT PlayDate FROM Played WHERE IDSong="&itm.ID&" ORDER BY PlayDate DESC LIMIT 0,1")
			dateToInsert = prepareDouble(sqlQry.StringByName("PlayDate"))
			formattedSyncDate = FormatDateTime(dateToInsert,2)&" "&FormatDateTime(dateToInsert,3)
			If DateDiff("s",itm.lastPlayed,formattedSyncDate)>0 Then
				If simu=True Then
					file.WriteLine "Update PlayDate: "&itm.Path
				Else
					itm.lastPlayed=formattedSyncDate
					itm.UpdateDB
				End If
			End If
		End If
	Next
	Set Progress = Nothing
	Set sqlQry=Nothing
	SDB.Database.Commit
	If Simu=True Then
		file.Close
	End If
End Sub

Function calcSecondsToAdd(addedDate, playsToCreate)
	calcSecondsToAdd = DateDiff("s",addedDate, Now)/(playsToCreate+1)
End Function

Function prepareDouble(number)
	If region=True Then
		prepareDouble=Replace(number,".",",")
	Else
		prepareDouble=number
	End If
End Function

Spazz
Posts: 243
Joined: Tue Jan 11, 2005 9:49 pm

Post by Spazz » Fri Mar 28, 2008 1:11 pm

Sorry, I think this was mentioned before, but would it be possible for the lastplayed field to be populated if it's empty?
Image

Christoph
Posts: 236
Joined: Fri Jan 25, 2008 12:43 pm

Post by Christoph » Fri Mar 28, 2008 1:21 pm

Hey Spazz,
could you describe it a little bit more please?
The script already updates the lastplayed field if there is a newer play entry.

Christoph

Spazz
Posts: 243
Joined: Tue Jan 11, 2005 9:49 pm

Post by Spazz » Fri Mar 28, 2008 2:06 pm

Here is my issue. when you import the itunes playcounts and stats it does not import the last played date. So I get all the playcounts but no playdate. What I'd like to do is give them all played dates even if they are a bit inaccurate. I tried using the last version of this script and it didn't update my lastplayed.
Image

Christoph
Posts: 236
Joined: Fri Jan 25, 2008 12:43 pm

Post by Christoph » Fri Mar 28, 2008 2:14 pm

Hey,
ok, I tested the following:
I imported a song to my lib. Then I changed the playcount to 3. After that I executed the fakeplays script. And it works.

Maybe you didn't deactivated the simulation mode before running the script. You have to do this before applying it to your lib.

Just comment line 31:

Code: Select all

'	simu=True 'Activate this for report generation
Christoph

Spazz
Posts: 243
Joined: Tue Jan 11, 2005 9:49 pm

Post by Spazz » Fri Mar 28, 2008 2:30 pm

Perfect, thank you. Maybe I should read before I use next time.
Image

Post Reply