Play next in Party Shuffle.

Note to self: write a contextual menu item that plays the selected song next in party shuffle, after (if necessary) importing the song into iTunes.

iTunes Auto-Rater

One of the comments to my MacOSXHints.com hint about rating iTunes songs with ratings other than the simple 0-5 stars gave me an idea for a program. Basically, it’s a daemon/controller for iTunes, that sits there and monitors the currently playing track. The rationale is that if you listen to the whole track, you like the song and want to increase the rating, and if you skip it, you are getting a bit sick of it, so you want to reduce the rating. Since there is no way to determine when a track changes, you have to continually poll iTunes for the track info. What you could do is when a new song is discovered, store the track length in a variable. Then, keep track of the amount of time that that track remains playing, and if it is close to the full track length (say, 95%?) then increase the rating. If you only listened to a small part of it, then reduce the rating. You could even have it so the rating is increased/reduced by 1 for every 5% of the song either side of 50% that you listen to. Or, you could just have it so it either increases (by 10?) or reduces (by 5) at a certain threshold. Writing this program as an AppleScript Studio program should be quite simple. UPDATE: Visit AutoRater for details on the first working version.

iTunes Consolidate Library

The iTunes menu item ‘Consolidate Library’ gathers all music & files in the library, and copies them to the library folder if they aren’t already. However, if you have multiple users with a shared library folder, to reduce space usage, and both users consolidate to a new location, iTunes will create 2 copies of each track. What I’ll need to do now is delete the second copy of each track (seems simple, since all 2nd copies end in 1, but some songs also end in a 1!), and then find a way to ’re-attach’ the missing tracks to the file they should correspond to. To delete files:

1
2
$ cd <Music Folder>
$ find . -name "* 1.m??" -newer <file of correct age> -exec rm {} \;

To reattach:

1
2
3
4
5
6
tell application "iTunes"
    --if song location is unknown then 
    --attach file according to 
    --it's track_number, title, 
    --artist and album details
end tell

Transferrence (iTunes Library Migration)

I’m putting my whole iTunes Library, and all of my iPhoto pictures, and the various movies I’ve collected onto my NSLU2. To shift the iTunes library, I just changed the library location in the Advanced Preferences, and then Consolidated the Library. I’m hoping I’ll be able to do exactly the same with Jaq’s and it won’t actually have to copy the files across, as they will already be there. It will be interesting to see how clever it is. It takes a couple of hours to transfer the many gigabytes of music I’ve encoded, so hopefully it won’t have to be completely redone. Either way, it will keep all of my ratings, and so forth. My tip for sharing songs from a library between multiple users - just point all of the iTuneses at the same location for storing the files, and make sure all of them are set up the same in terms of organising. When one person adds songs, the others just need to drag the folder/disk onto the iTunes Library icon in iTunes, and only the new files will be added. There are occasionally issues when someone changes an album or track name, but iTunes seems to cope pretty well most of the time.

Most Played Music Meme

Most Played Music Meme Originally uploaded by Michael Heilemann.

Follow the instructions…

The Playlist Meme.

From The Tao of Mac, my next 10 tracks randomly from iTunes.

  1. Open up the music player on your computer.
  2. Set it to play your entire music collection.
  3. Hit the “shuffle” command.
  4. Tell us the title of the next ten songs that show up (with their musicians), no matter how embarrassing. That’s right, no skipping that Carpenters tune that will totally destroy your hip credibility. It’s time for total musical honesty. You can put the list in the comment thread, or write it up in your blog or journal and then post a link in the comments.
  5. If you get the same artist twice, you may skip the second (or third, or etc.) occurances. You don?t have to, but since randomness could mean you end up with a list of ten song with five artists, you can if you’d like.
  1. Enchanted Farm / Forbidden Five / Ultra-Lounge, Vol. 11: Organs In Orbit
  2. Tonight (King Britt’s Sexy Mix) / H-Foundation / The Chillout Session Summer Collection 2004
  3. Desafinado / George Michael / Ladies & Gentlemen : The Best Of George Michael
  4. Ocean Beach / Talbot And White / United States Of Mind
  5. Opus 40 / Mercury Rev / Deserter’s Songs
  6. Cruel Summer / Bananarama / Bananarama
  7. The Tower Of Learning / Rufus Wainwright / Poses
  8. Peer Gynt Suite No. 1 op. 46 In der Halle des Bergkönigs / Berlin Philharmonic Orchestra / Karajan Festival
  9. Sunday 8pm / Faithless / Sunday 8pm
  10. Double Violin Concerto in D Minor, BWV 1043: II. Largo ma non tanto / Bach (Composer) / Unknown
  11. Dub Be Good To Me / Beats International / The Mix

iPod timezone

Jaq bought an iPod some time ago, and I noticed at the time Adelaide was missing from the timezone properties. Should report this to Apple.

Export Artwork and Playlists

Exporting Artwork

Seeing as how XBMC won’t read the id3 tags from AAC files, I had to grab the artwork from each album and place it in a file (folder.jpg/folder.png) inside the album folder. This was actually easier with Windows (aargh!), since iTunes for Windows exports album art as BMP files, which can then be processed. Still, it took me most of the afternoon to do that by hand. I had had a bash at doing it with an AppleScript, but could not work out how to get the data from a <<class PNG/JPEG *>> structure into an image file. Until I came across a script that does that. It was then a trivial matter to make it so that it worked for multiple files, and only processed those files it needed to, and ignored those without artwork. Tip: iTunes will give you an Out Of Memory Error if you try to get the data from a song that has no artworks! (Took me a while to figure this out!) So, the finished script can be found below. I optimised it a bit, but it still takes a while to run, especially if you run it on lots of tracks. Since it’s not something you’ll want to run every day, this shouldn’t be too much of a problem.

Exporting Playlists

I also thought it would be neat to get the playlists I use in iTunes (I use mostly smart playlists, such as 50’s - 00’s Music, Not Played Today, Recently Added and so on), and use them on XBMC. So, I wrote a script that does this, and then ftp’s the resulting files to the xbox. You will need to edit the first few lines: it should be obvious what needs to go where. Anyway, you can download Export Artwork and Export Playlists. You can also download Bracket Change, a small script that swaps the round & square brackets in a track name. (Right-click and choose to download them, else they will just open in your browser window). All of these files should go into ~/Library/iTunes/Scripts (User only) or /Library/iTunes/Scripts (System-wide) for best effect. Note: The first Script is no longer required, since more recent builds of XBMC can handle the data from AAC files.

More on Sharing iTunes Songs

After all of the mucking around with getting an AppleScript to work, and then using python anyway, I discovered a far faster method of adding tracks to iTunes: just drag the folder they all live in, and iTunes will only add the songs that aren’t in the Library yet! Probably well documented, but I didn’t find it! What you may need to do, particularly if multiple people need to be able to change MP3 Tags or artwork, is do the following:

  • Change the owner/group of the files to something that all people can access - I use shared/admin, since all non-admin users are scum, and do not need to be able to change stuff.
  • Change the protection bits of the files to allow owner R+W, group R+W, all R.

Code to do this should be easy: find ~shared/Music -name *.m* -not -perm 664 -exec chmod 664 {}; find ~shared/Music -name *.m* -not -owner shared -exec chown shared:admin {}; But bash interprets the ; itself, and gives the following error: find: -exec: no terminating ";" Bitch. Can’t be bothered figuring out how to use another shell, so knock up a script in python: UpdateShared.py This script also updates the owner/group and permissions for files in ~shared/Movies and ~shared/iPhotoLibrary. Update: the ; must be \; for the bash commands to work.

Sharing iTunes Songs

I finally got around to downloading the 10.3.4 OS X update, SharePoints, and Xbox Media Centre (XBMC). My aim for some time has been to share my iTunes library to my Xbox, which is connected up to the TV and Stereo in the lounge.

The MacOS X update provided (apparently) updated Samba sharing, but I still couldn’t get XMP (Xbox Media Player - the previous incarnation of XBMC) to connect to the SMB share I had set up, with all of my MP3s on it. SharePoints fixed that - all I had to do was create a publicly available share.

Setting up XBMC was a breeze, and it even has a cool interface! UnleashX is (almost) banished from my system, and XBMC is my main Dash.

Then I discovered that XCMC can play AAC files! So, I started (and have not yet finished) converting all of my MP3s to AAC. And not just converting, but re-importing, at a bitrate of 128 (small file size, but apparently equivalent to 256 in MP3). See this hint for some tips (and my comments).

I also wanted to re-jig how I had set up sharing my iTunes songs between users - I had a couple of links to the relevant files in each user’s ~/Music/iTunes, and all files were located in ~shared/Music (which all of admin can RW, and all of the world can R). I needed to have seperate Library files, so that we can have our own ratings (I hate Abba, and she isn’t that big a fan of Paul Kelly, for instance). So, I knocked up a script that scanned the ~shared/Music folder and compared any files found to the iTunes LIbrary. If they weren’t in it, it added them.

Here we go:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
set _tracks to “”
tell application “iTunes”
    set sel to tracks of playlist 1
    –set sel to get a reference to selection
    repeat with t in sel
        set _tracks to _tracks & “
” & (location of t as string)
    end repeat
end tell

tell application “Finder”
    set _files to “”
    set _library to “Macintosh HD:Users:Shared:Music”
    set _artists to folders of folder _library
    repeat with _artist in _artists
        set _albums to folders of _artist
        repeat with _album in _albums
            set temp to files of _album
            repeat with _file in temp
                set _files to _files & “
” & _file
            end repeat
        end repeat
    end repeat
end tell
set _missing to “”
repeat with para in paragraphs of _files
    set para to para as string
    if para is not in _tracks then
        set _missing to _missing & “
” & para
    end if
end repeat

tell application “iTunes”
    repeat with para in paragraphs of _missing
        set para to para as string
        if para is not “” then
            set _file to para
            add _file
        end if
    end repeat
end tell

Which worked, but was a bit slow. So I came up with the following system instead:

Create a file called ~/.last_check

Enter the following into a script, and then run it. (I’ve had to modify some lines to get it to look good - particularly the fp=os.popen… line).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/env python 
# Check for songs newer than ~/.last_check, and add them to iTunes

import os
import sys

fp = os.popen(
"find ~shared/Music -name *.m?? -newer ~/.last_check")

data = fp.readlines()

if len(data) == 0:
    print "No New Songs."
    sys.exit(0)
    
for line in data:
    filename = "Macintosh HD"+line[:-1]
    filename = filename.replace("/",":")
    print "Adding", filename
    os.system('''osascript < <END
tell application "iTunes"
add "'''+filename+'''"
end tell
END
''')

Should be pretty quick - I only tested it with a few files, but seems to work okay. iTunes is even smart enough to not re-add files that are already there (I think!), so it won’t add duplicates!

My library lives in ~shared/Music, yours may vary!

You will, however, need to use something like Super Remove Dead Tracks if you update one library with a new encoder!

I accept no responsibility if it screws up your iTunes Library file!