Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Create iTunes playlists of rarely-played albums via script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create iTunes playlists of rarely-played albums via script
Authored by: Oops on Oct 03, '07 06:51:30AM
&Hello. I am the original submitter (who did not have any unplayed songs in his 2200 song library before I went out and bought one). Sorry about the gaff....but if the script were perfect, I wouldn't be named 'Oops'! Thank you to MacOSXHints and Doug Adams for getting a fixed version out there in the first place.

Anyway, here is a script which fixes the problem regarding the unplayed songs and which also makes it so that the user does not have to create any playlists to start with (which was the case of the original unposted script). I stuck to my own less efficient code just because its mine. Also, the one which eventually was posted gets my library age wrong by between 4 and 5 days and I haven't have time to figure out why yet. Also, the scripts which were posted also duplicated videos and digital booklets to the playlist, whereas I just wanted music in the dusty playlist (I don't have time to sit and look at either booklets or videos anyway and if someone has merely an iPod Shuffle like I do, then these are not desired in the playlist). If you want to include these, just remove "and kind contains "audio"" from each statement which has it. This script now eliminates those whose checkbox is unchecked (but this extra can be removed if you remove "and enabled is true"" from every line where it occurs).

If you like the dialog which allows you to delete the script generated playlists, then you can copy that portion of the originally posted script which Doug Adams put in (ince I am 'Oops' it makes me nervous to have 'delete' in any script which I give to someone else). I will later try to remove the use of names, and perhaps that will help when song names have unusual characters (if that indeed is a problem now). I'll also try to see what error I get if there are missing songs (exclamation points in the listing), but for now I would fix the exclamation points. Anyway, here are the updated scripts:


tell application "iTunes"
	set lastTimes to {}
	set longestTime to 0
	set lastTimes to the (played date of every track of library playlist 1 whose played count is greater than 0 and enabled is true and podcast is false and kind contains "audio")
	repeat with i in lastTimes
		set temporalVariable to (current date) - i
		if temporalVariable is greater than longestTime then
			set longestTime to temporalVariable
		end if
	end repeat
	set unplayedSongs to every track of library playlist 1 whose played count is equal to 0 and enabled is true and podcast is false and kind contains ("audio" as list)
	set daysAgo to (longestTime div 86400)
	set overDay to (longestTime / 86400) - daysAgo
	set decimalHours to (overDay * 24)
	set andHours to overDay div (1 / 24)
	set overHours to (overDay * 24) - andHours
	set andMinutes to overHours div (1 / 60)
	if daysAgo is 1 then
		set daysWord to " day"
	else
		set daysWord to " days"
	end if
	if andHours is 1 then
		set hoursWord to " hour"
	else
		set hoursWord to " hours"
	end if
	if andMinutes is 1 then
		set minutesWord to " minute"
	else
		set minutesWord to " minutes"
	end if
	display dialog "The oldest played song was last played " & daysAgo & daysWord & " and " & andHours & hoursWord & "  and " & andMinutes & minutesWord & " ago."
	if unplayedSongs is not {} then
		display dialog "...and some songs have never been played."
	end if
	set daysSincePlayed to ""
	display dialog "Enter the number of days since last played:" default answer the daysSincePlayed
	copy the result as list to {daysSincePlayed, the button_pressed}
	set targetDate to (current date) - daysSincePlayed * days
	set cobwebbedLibrary to the tracks of library playlist 1 whose kind contains "audio" and podcast is false and enabled is true as list
	if user playlist "Dustiest Albums" exists then
		display dialog "Dustiest Albums already exists; I'll add to that playlist new albums."
	else
		make new user playlist with properties {name:"Dustiest Albums", shuffle:false, song repeat:none}
	end if
	set dustiestSong to ""
	set dustiestAlbum to ""
	set dupedAlbums to {} as list
	if the (count of tracks of user playlist "Dustiest Albums") is 0 then
		set alreadylistedDusty to {}
	else
		set alreadylistedDusty to the name of every track of user playlist "Dustiest Albums"
	end if
	repeat with i from 1 to the count of cobwebbedLibrary
		set dustiestSong to item i of cobwebbedLibrary
		if played count of dustiestSong is greater than 0 then
			set playedDate to played date of dustiestSong
			if playedDate is less than targetDate then
				if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
					set dustiestAlbum to album of dustiestSong
					set dupedAlbums to dupedAlbums & dustiestAlbum
					duplicate (every track of library playlist 1 whose (album is dustiestAlbum and podcast is false and enabled is true and kind contains "audio")) to user playlist "Dustiest Albums"
				end if
			end if
		else
			if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
				set dustiestAlbum to album of dustiestSong
				set dupedAlbums to dupedAlbums & dustiestAlbum
				duplicate (every track of library playlist 1 whose (album is dustiestAlbum and podcast is false and enabled is true and kind contains "audio")) to user playlist "Dustiest Albums"
			end if
		end if
	end repeat
	display dialog "Transfer Complete"
end tell




Dustier Albums (those with at least half not having been played in x days or some not having ever been played)


tell application "iTunes"
	set lastTimes to {}
	set longestTime to 0
	set lastTimes to the (played date of every track of library playlist 1 whose played count is greater than 0 and enabled is true and podcast is false and kind contains "audio")
	repeat with i in lastTimes
		set temporalVariable to (current date) - i
		if temporalVariable is greater than longestTime then
			set longestTime to temporalVariable
		end if
	end repeat
	set unplayedSongs to every track of library playlist 1 whose played count is equal to 0 and enabled is true and podcast is false and kind contains ("audio" as list)
	set daysAgo to (longestTime div 86400)
	set overDay to (longestTime / 86400) - daysAgo
	set decimalHours to (overDay * 24)
	set andHours to overDay div (1 / 24)
	set overHours to (overDay * 24) - andHours
	set andMinutes to overHours div (1 / 60)
	if daysAgo is 1 then
		set daysWord to " day"
	else
		set daysWord to " days"
	end if
	if andHours is 1 then
		set hoursWord to " hour"
	else
		set hoursWord to " hours"
	end if
	if andMinutes is 1 then
		set minutesWord to " minute"
	else
		set minutesWord to " minutes"
	end if
	display dialog "The oldest song was last played " & daysAgo & daysWord & " and " & andHours & hoursWord & "  and " & andMinutes & minutesWord & " ago."
	if unplayedSongs is not {} then
		display dialog "...and some songs have never been played."
	end if
	set daysSincePlayed to ""
	display dialog "Enter the number of days since last played:" default answer the daysSincePlayed
	copy the result as list to {daysSincePlayed, the button_pressed}
	set targetDate to (current date) - daysSincePlayed * days
	set cobwebbedLibrary to (every track of library playlist 1 whose kind contains "audio" and podcast is false and enabled is true) as list
	if user playlist "Dustier Albums" exists then
		display dialog "Dustier Albums already exists; I'll add to that playlist new albums."
	else
		make new user playlist with properties {name:"Dustier Albums", shuffle:false, song repeat:none}
	end if
	set dustiestSong to ""
	set dustiestAlbum to ""
	set dupedAlbums to {} as list
	if the (count of tracks of user playlist "Dustier Albums") is 0 then
		set alreadylistedDusty to {}
	else
		set alreadylistedDusty to the name of every track of user playlist "Dustier Albums"
	end if
	repeat with i from 1 to the count of cobwebbedLibrary
		set dustiestSong to item i of cobwebbedLibrary
		if played count of dustiestSong is greater than 0 then
			set playedDate to played date of dustiestSong
			if playedDate is less than targetDate then
				if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
					set dustiestAlbum to album of dustiestSong
					set oldCount to 0
					set albumSize to 0
					set songNames to (every track of library playlist 1 whose album is dustiestAlbum)
					repeat with eachSong in songNames
						set albumSize to albumSize + 1
						set playedDate to the played date of eachSong
						if playedDate is less than or equal to targetDate then
							set oldCount to oldCount + 1
						end if
					end repeat
					if ((2 * oldCount) div albumSize) is greater than or equal to 1 then
						set dupedAlbums to dupedAlbums & dustiestAlbum
						duplicate (every track of library playlist 1 whose (album is dustiestAlbum and kind contains "audio" and enabled is true and podcast is false)) to user playlist "Dustier Albums"
					end if
				end if
			end if
		else
			if (album of dustiestSong is not in dupedAlbums) and (name of dustiestSong is not in alreadylistedDusty) then
				set dustiestAlbum to album of dustiestSong
				set dupedAlbums to dupedAlbums & dustiestAlbum
				duplicate (every track of library playlist 1 whose (album is dustiestAlbum and podcast is false and enabled is true and kind contains "audio")) to user playlist "Dustier Albums"
			end if
		end if
	end repeat
	display dialog "Transfer Complete"
end tell


[ Reply to This | # ]
Library age difference is because of videos
Authored by: Oops on Oct 03, '07 07:18:57AM

The Library age is different between these two scripts because the adjustment by Doug Adams includes the ages of videos and mine just includes the ages of songs. Removal of "and kind includes "audio"" from any line where it occurs in my script above will include videos and digital booklets in the playlist and will calculate the age accordingly.



[ Reply to This | # ]