iTunes 'Random' and stuff

Discussion in 'General Mac Discussion' started by wowser, Apr 26, 2004.

  1. wowser macrumors 6502a


    Jan 25, 2004
    Inglaterra, Europa
    Well, I enjoy the iTunes 'random' button, but is it actually random? i have 2gb of sonmgs (not a huge amount, but a godd selection) and it seems to play the same old stuff all the time, makingvery predictable changes of what it will play next (i'm sure it works of some sort of playlist thing). I heard that it actually tries to pick songs that work together, which even if it is true, i do not want as a feature most of the time. Is there any way i can get a genuinly random selection, like in winamp?

    secondly, the 'top 25 most played' is also absolute crap. the list it has come up with is just wrong and it gives very conservative 'stats' on how many times a song has been played. basically, i think it lies :mad:

    thirdly, am i the only person who spends half an hour before making a post trying to fit it into one of the badly thought out forum sub-sections? :confused:
  2. HexMonkey Administrator


    Staff Member

    Feb 5, 2004
    New Zealand
    I've heard that the randomizer in iTunes might be biased, but I haven't seen any evidence. I wrote a script you can use that is definately random, although I'm not sure if it's exactly what you want.

    Basically it creates a new playlist and puts a number of random songs in it. You can edit the initial properties to customize it, changing the name of the destination playlist, the source (main library or selected playlist) and whether you are asked how many songs to get or to use the default number.

    I've tried to add sufficient error checking to the script, so hopefully it will be informative if there's an error. Also note that when the new playlist is created, if there is already a playlist with that name it is deleted (although this code can be removed easily enough). The script works by generating random numbers and using them to select songs from the source playlist.

    To use the script follow these steps:
    1. Copy the code below
    2. Open /Applications/AppleScript/Script Editor
    3. Paste the code
    4. Save it as script, in [home]/Library/iTunes/Scripts/. You may need to create the Scripts folder if it isn't there already.
    5. You should now be able to run the script from the Scripts menu in iTunes

    property playlist_Name : "Random" --Name of the destination playlist
    property random_source : true --Set this to true to use the Library as the source or false to use the selected playlist as the source
    property ask_for_number : true --If true, asks for the number of songs to add to the random playlist. If false, it uses the default number
    property default_number : "20" --Default number of random songs to get, used if ask_for_number is set to false
    tell application "iTunes"
    	if ask_for_number is true then
    		set {numTracks, button} to {text returned, button returned} of (display dialog "How many random tracks?" buttons {"Cancel", "OK"} default button "OK" default answer default_number)
    		set button to "OK"
    		set numTracks to default_number
    	end if
    	if button is equal to "OK" then
    		set cont to true
    			set theCount to numTracks as integer
    			if theCount is less than 1 then
    				display dialog "Number must be greater than 0" buttons "OK" default button "OK"
    				set cont to false
    			end if
    		on error
    			display dialog "That is not a number" buttons "OK" default button "OK"
    			set cont to false
    		end try
    		if cont then
    			if exists playlist playlist_Name then
    				delete playlist playlist_Name
    			end if
    			set randPlay to make new user playlist with properties {name:playlist_Name}
    			if random_source is equal to true then
    				set theMainPlaylist to playlist "Library"
    				set theMainPlaylist to view of browser window 1
    			end if
    			set theTracks to every track of theMainPlaylist
    			if theCount is greater than (count of theTracks) then
    				set theCount to count of theTracks
    				display dialog "Too many tracks. The script will continue with the maximum number possible" buttons "OK" default button "OK"
    			end if
    			repeat until theCount is 0
    				set newTrackNum to random number from 1 to count of theTracks
    				set newTrack to (item newTrackNum of theTracks)
    				if not (exists track (name of newTrack) in randPlay) then
    					duplicate (item newTrackNum of theTracks) to randPlay
    					set theCount to theCount - 1
    				end if
    			end repeat
    			set view of browser window 1 to randPlay
    		end if
    	end if
    end tell
    As for playcounts, I doubt that they are wrong. For a song's playcount to be increased the end of the song must be played, so if you change songs half way through its playcount won't change.
  3. wowser thread starter macrumors 6502a


    Jan 25, 2004
    Inglaterra, Europa
    That's excellent and i will be definitely using the script. it will be the first applescript i have used, too :)
    that also solves my concern of the top 25 thing, too
  4. sonofslim macrumors 6502a


    Jun 6, 2003
    yeah, that's just how it is... i've never been able to find a great explanation, other than iTunes tends to favor songs you've rated higher. even so, the iTunes randomizer isn't the greatest. even with small collections, there are songs it will play seemingly all the time, and others it won't play at all.

    iTunes only increments a song's playcount when it plays the very end of a track; if you're doing a lot of skipping and/or fast-forwarding, it may not be counting every play.
  5. stoid macrumors 601


    Feb 17, 2002
    So long, and thanks for all the fish!
    When you click the random button, iTunes generates a shuffled list and plays through the songs in that order. I think that you may have to quit and reopen iTunes if you want it to regenerate the list.
  6. Hemingray macrumors 68030


    Jan 9, 2002
    Ha ha haaa!
    Nope, just Option+Click the random button. It will force it to create a new random list.
  7. wowser thread starter macrumors 6502a


    Jan 25, 2004
    Inglaterra, Europa
    Actually, i really like the script - it's good to work with a shuffled selection that you can actually see.

    I suppose you could also make a random selection by organising the songs by song name (providing you have the song title in that field rather than the artist)
  8. G4scott macrumors 68020


    Jan 9, 2002
    Austin, TX
    Does anybody know what that "Copy to Play Order" item is that comes up when you right click on a song? Does it have to do with a queue? If so, that would be cool. It's one feature iTunes currently lacks (as far as I'm aware of), that would be really nice to have.

    Edit: Nevermind, I just found out what it does... It just saves that order in which they've been randomly shuffled, so when you turn the random thing off, they stay in that order...

Share This Page