Page 2 of 17
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 2:41 pm
by Benn
This is great ZvezdanD, a real help if my DB ever gets corrupted again.
Soon, I will be using a laptop in addition to my PC, where I store all of my music. Considering I also have an exact backup of this on my external HD, which the laptop would use for music: would I be able to merge the playhistory of my laptop onto my PC .db using this script?
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 2:55 pm
by nynaevelan
Benn wrote:
... would I be able to merge the playhistory of my laptop onto my PC .db using this script?

I was thinking the same thing.
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 3:34 pm
by nynaevelan
Z:
My system seems to lock up for several minutes when switching databases.

Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:00 pm
by ZvezdanD
Benn wrote:would I be able to merge the playhistory of my laptop onto my PC .db using this script?
Yes, you would if you turn off the
Clear Played... option and, of course, if your tracks have same paths or checksums in both databases.
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:05 pm
by ZvezdanD
nynaevelan wrote:My system seems to lock up for several minutes when switching databases.

Well, this is expected since every time when you change database file, the script generates table of matching tracks. You could see the result of that operation in the panel on the bottom of dialog box saying: Backup: xxx, current DB: yyy, matched tracks: zzz.
I could move that operation to be executed after you click on the Replace button, but it should be executed anyway and in that case you would lose mentioned information about number of matched tracks.
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:18 pm
by nynaevelan
I suppose I will have to deal with it, it is only annoying when it happens to have the system locked up at the end of the playing song.
But I have another problem, the tracks only seem to restore the playcounts when I have the Clear Played table... option checked. Prior to running script I reset the playcounts to zero for the test tracks.
Nyn
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:30 pm
by Mizery_Made
Code: Select all
UPDATE Songs
SET PlayCounter = (SELECT COUNT(*) FROM Played WHERE Played.IDSong = Songs.ID GROUP BY Played.IDSong),
LastTimePlayed = (SELECT MAX(PlayDate) FROM Played WHERE Played.IDSong = Songs.ID GROUP BY Played.IDSong)
WHERE Songs.ID IN
(SELECT IDSong FROM Played, Songs WHERE Played.IDSong = Songs.ID GROUP BY IDSong
HAVING PlayCounter<>COUNT(*) OR CAST(LastTimePlayed AS TEXT)<>CAST(MAX(PlayDate) AS TEXT))
Bex gave that SQL statement a while back, for fixing the difference between Play Count and History Plays (caused by iPod sinking I believe), and I believe it calculates the number of plays in the Played table and sets the Playcount of the track to the number. I believe it also sets Last Played based on the newest play in said table as well.
For the "Merge" ability, something like this might need to be implemented to run after the IDs are updated or whatnot. Then again, you might already have something like this under the hood (as I have not peeked inside the script) and it's simply breaking due to a type or something. Or maybe you didn't include such a feature, as it would erase these ghost iPod plays. *Shrugs*
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:33 pm
by ZvezdanD
nynaevelan wrote:I have another problem, the tracks only seem to restore the playcounts when I have the Clear Played table... option checked.
If you turn off the
Clear Played... option you would get merged playing history from backup database with the current one. Maybe you have turned on the
Restore data for filtered tracks only option and your test track is excluded with the active filter. What you got in the panel on the bottom saying matched tracks: zzz?
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:44 pm
by nynaevelan
The tracks and everything matches, here is what it looks like:
Nyn
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:52 pm
by ZvezdanD
nynaevelan wrote:Prior to running script I reset the playcounts to zero for the test tracks.
Mizery_Made wrote:Bex gave that SQL statement a while back, for fixing the difference between Play Count and History Plays (caused by iPod sinking I believe
Well, I think you are right. Nyn is cleared playcount data from the Songs table, but her Played table remained intact, so she has the difference between those two data. When I merge data from the backup with the current database I calculate the number of different records between Played tables and add that number to the playcount field - since both backup and current database have same Played table in her case, there is not addition to the playcount field in Songs table. So Nyn, you should have consistent data between playcount field and Played table before you use this script.
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 4:55 pm
by nynaevelan
ZvezdanD wrote:nynaevelan wrote:Prior to running script I reset the playcounts to zero for the test tracks.
Mizery_Made wrote:Bex gave that SQL statement a while back, for fixing the difference between Play Count and History Plays (caused by iPod sinking I believe
Well, I think you are right. Nyn is cleared playcount data from the Songs table, but her Played table remained intact, so she has the difference between those two data. When I merge data from the backup with the current database I calculate the number of different records between Played tables and add that number to the playcount field - since both backup and current database have same Played table in her case, there is not addition to the playcount field in Songs table. So Nyn, you should have consistent data between playcount field and Played table before you use this script.
Actually guys these tracks do not have any data in the played table, they only have playcounts because they were added by the Track Redirection script. And yes I used Bex's AddRemove Playstats script prior to selecting my test tracks just to be sure.
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 5:12 pm
by ZvezdanD
nynaevelan wrote:Actually guys these tracks do not have any data in the played table, they only have playcounts because they were added by the Track Redirection script. And yes I used Bex's AddRemove Playstats script prior to selecting my test tracks just to be sure.
Only thing that comes to my mind is that your Played table in the backup database is empty as well. There is no help in that case. I simply cannot add any number to the playcount field because I don't know which plays are same between those two databases and which plays are new only to the current database.
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 5:23 pm
by nynaevelan
So if the played table is empty for the selected tracks, then you have to have the Clear Played.... option selected??
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 5:43 pm
by ZvezdanD
nynaevelan wrote:So if the played table is empty for the selected tracks, then you have to have the Clear Played.... option selected??
I am ready for any suggestion, but if I want to merge two databases I cannot simply add playcounts from the backup to the current database. I need to find which plays was same in both databases and which are different, but it cannot be done in your case since your Played table is empty. As I said, your Played table should be consistent with the Playcount field in the Songs table if you want the correct value.
It is totally different thing if you choose the Clear Played... option. In that case the play history data from the backup database would be simply copied over same data in the current database.
Re: Restore Play History/Date Added 1.2 (2009-08-23) [MM3]
Posted: Sun Aug 23, 2009 5:51 pm
by nynaevelan
Ok:
I think I understand now, I do not think you need to make any changes, these redirected tracks do not have any playhistory so they would not be something that will be restored anyway. I'll test this on my "true" tracks in my test account.
Nyn