Downloading RSTP streams.

The BBC has a heap of stuff available on their website as part of the Beethoven Experience, but I found my copy of RealPlayer had expired. I’d rather dump the data to disk and listen to it later (on my iPod, probably). But, the only ways I could find to do this didn’t work with the software I had. Specifically:

1    mplayer -dumpstream rtsp://

fails, as does using VLC. I’m downloading newer versions of both of these, but I’m not that hopeful. Mplayer seems to not want to access network protocols, VLC cannot decode. Nor can it just dump to disk, without interpreting the data.

iTunes Shared Library Checker

I now have the code to check the library XML file and see if there are missing tracks (ie, the files are not where they are expected to be). This code is quite slow, but simple to follow. (It took around 2 min to run). I also have the code that gets a list of the files in the library directory. It must be simple to combine this information, and work out which ones are:

  1. Files that are ‘new’: they only exist on disk, not in the library. Chances are they were added by another user.
  2. Files that have become detached: there is a file and a library location, but they don’t quite match up. This is probably because the users have ‘Keep Library Arranged’ turned on, and one of them has made a change to a track name, artist or album; or made a change to the compilation flag.

The trick will be having the list of files, and removing items from the list that have been located in the library. This will leave list that just need to be sorted into alpha and beta above.

 1    import os
 2    import urllib
 4    library = os.path.expanduser('~')+'/Music/iTunes/iTunes Music Library.xml'
 5    startpath = '/Volumes/Media/Music'
 6    def greppy(library)
 7        data = open(library).readlines()
 8        tracks = {}
 9        this_track = 0
10        for line in data:
11            if line.count('<key>Track ID'):
12                this_track = line.split('integer>')[1][:-2]
13            elif line.count('<key>Location</key>'):
14                tracks[this_track] = urllib.url2pathname(
15                         line.split('string>')[1][16:-2]).replace(
16                         '&#38;','&')
18    findstr = "find "+startpath+"-type f -not -name .aacgained -not -name ._* -not -name .DS_Store | sort"
19    treedata = os.popen(findstr).readlines()
21    data = greppy(library)
23    missing = {}
24    surplus = treedata[:]
26    for i in data:
27        try:
28            surplus.remove(urllib.urlopen(data[i]).url[7:]+'\n')
29        except IOError:
30            missing[i] = data[i]
31        except ValueError:
32            pass

This leaves two data structures of interest: missing, a dictionary with the ‘missing tracks’ from iTunes, and surplus, a list with files that do not have an associated iTunes library entry. Note: I’ve turned off comments, as this post seems to get a lot of comment spam.