Manually Adjust Play Count in iTunes?

Discussion in 'Mac Apps and Mac App Store' started by Traverse, May 14, 2015.

  1. Traverse macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #1
    I am restoring my system to install Yosemite. I've had the same iTunes library for years and it has suffered some corruption/glitch. Every time iTunes is launched it must "Analyze Gapless Playback."

    I can fix this by dragging the 4 library files to the trash and starting fresh with just my music, but then I loose my ratings and play count.

    Is there a way I can quickly restore my play count without having to sit their tediously and click through each song?
     
  2. sammich, May 14, 2015
    Last edited: May 14, 2015

    sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #2
    I had to write some AppleScript way back (almost 5 years now) for someone who was having Library issues just like you are.

    Attached is a zip file with three scripts:

    • info_into_comments - saves playcount and rating into the comment metadata field
    • info_out - extracts playcount and rating from comment field
    • clear_comments - sets comments to blank

    You install them by copying them into your ~/Library/iTunes/Scripts folder. If it doesn't exist, then create it. Alternatively, if you have a little script icon in iTunes Menu Bar to the right of 'Window', the top menu will take you there as well.

    These scripts have a prerequisite that you don't use the comments field in your music files because they will be replaced.

    Instructions:
    1. Select all music in library
    2. Run 'into comments' (store the metadata)
    3. Trash your library files (this is where you lose the playcounts)
    4. Restart iTunes
    5. Run 'info out' (get back your playcounts)
    6. Run 'clear comments' (housecleaning)

    EDIT: you could write a version that preserves any comments you might already have. Unfortunately, I'm a little strapped for time atm
     

    Attached Files:

  3. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #3
    Thank you! I'm also playing with some of "Doug's AppleScripts" and, forgive me for being paranoid, but how do I know that none of his are malicious?
     
  4. sammich macrumors 601

    sammich

    Joined:
    Sep 26, 2006
    Location:
    Sarcasmville.
    #4
    You should be able to open them in Script Editor to view the scripts.

    But I'll post them here anyway. You can recreate the scripts yourself.

    "Save Into Comments"
    Code:
    tell application "iTunes"
    	if selection is not {} then
    		set sel to selection
    		repeat with t in sel
    			set t to contents of t
    			if class of t is file track or class of t is URL track then
    				set comment of t to played count of t & "
    " & rating of t as string
    			end if
    		end repeat
    	end if
    end tell
    "Restore from Comments"
    Code:
    tell application "iTunes"
    	if selection is not {} then
    		set sel to selection
    		repeat with t in sel
    			set t to contents of t
    			if class of t is file track or class of t is URL track then
    				set content1 to comment of t
    				set content2 to words in content1
    				set played count of t to item 1 in content2
    				set rating of t to item 2 in content2
    			end if
    		end repeat
    	end if
    end tell
    "Clear comments"
    Code:
    tell application "iTunes"
    	if selection is not {} then
    		set sel to selection
    		repeat with t in sel
    			set t to contents of t
    			if class of t is file track or class of t is URL track then
    				set comments of t to ""
    			end if
    		end repeat
    	end if
    end tell
    Note: I wrote these way back before I was any kind of serious programmer. There is some room for improvement, if you want to do it yourself, non-destructive comments can be added.
     
  5. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #5
    Thank you! I'm going to save these.

    I appreciate it because I'm not experienced with scripting (yet).
     
  6. Partron22 macrumors 68000

    Partron22

    Joined:
    Apr 13, 2011
    Location:
    Yes
    #6
    I've been using them for years. Never met an evil one.
     
  7. Traverse thread starter macrumors 603

    Traverse

    Joined:
    Mar 11, 2013
    Location:
    Here
    #7
    Thanks. It took a few hours, but I'm back in business. I'm saving sammich's incase the issue comes back down the road.
     

Share This Page