Skip to content

Instantly share code, notes, and snippets.

@drench
Created July 22, 2011 04:18
Show Gist options
  • Save drench/1098879 to your computer and use it in GitHub Desktop.
Save drench/1098879 to your computer and use it in GitHub Desktop.
reads the iTunesDB from an iPod and converts (most of it) to JSON
#!/usr/bin/env python
import gpod
import json
import sys
ipodpath = sys.argv[1]
itdb = gpod.itdb_parse(ipodpath, None)
songs = []
for track in gpod.sw_get_tracks(itdb):
song = {}
song['title'] = track.title
song['album'] = track.album
song['artist'] = track.artist
song['genre'] = track.genre
song['filetype'] = track.filetype
song['comment'] = track.comment
song['category'] = track.category
song['composer'] = track.composer
song['grouping'] = track.grouping
song['description'] = track.description
song['podcasturl'] = track.podcasturl
song['podcastrss'] = track.podcastrss
# song['chapterdata'] = track.chapterdata
song['subtitle'] = track.subtitle
song['tvshow'] = track.tvshow
song['tvepisode'] = track.tvepisode
song['tvnetwork'] = track.tvnetwork
song['albumartist'] = track.albumartist
song['keywords'] = track.keywords
song['sort_artist'] = track.sort_artist
song['sort_title'] = track.sort_title
song['sort_album'] = track.sort_album
song['sort_albumartist'] = track.sort_albumartist
song['sort_composer'] = track.sort_composer
song['sort_tvshow'] = track.sort_tvshow
song['id'] = track.id
song['size'] = track.size
song['tracklen'] = track.tracklen
song['cd_nr'] = track.cd_nr
song['cds'] = track.cds
song['track_nr'] = track.track_nr
song['tracks'] = track.tracks
song['bitrate'] = track.bitrate
song['samplerate'] = track.samplerate
song['samplerate_low'] = track.samplerate_low
song['year'] = track.year
song['volume'] = track.volume
song['soundcheck'] = track.soundcheck
song['time_added'] = track.time_added
song['time_modified'] = track.time_modified
song['time_played'] = track.time_played
song['bookmark_time'] = track.bookmark_time
song['rating'] = track.rating
song['playcount'] = track.playcount
song['playcount2'] = track.playcount2
song['recent_playcount'] = track.recent_playcount
song['transferred'] = track.transferred
song['BPM'] = track.BPM
song['app_rating'] = track.app_rating
song['type1'] = track.type1
song['type2'] = track.type2
song['compilation'] = track.compilation
song['starttime'] = track.starttime
song['stoptime'] = track.stoptime
song['checked'] = track.checked
song['dbid'] = track.dbid
song['drm_userid'] = track.drm_userid
song['visible'] = track.visible
song['filetype_marker'] = track.filetype_marker
song['artwork_count'] = track.artwork_count
song['artwork_size'] = track.artwork_size
song['samplerate2'] = track.samplerate2
song['unk126'] = track.unk126
song['unk132'] = track.unk132
song['time_released'] = track.time_released
song['unk144'] = track.unk144
song['explicit_flag'] = track.explicit_flag
song['unk148'] = track.unk148
song['unk152'] = track.unk152
song['skipcount'] = track.skipcount
song['recent_skipcount'] = track.recent_skipcount
song['last_skipped'] = track.last_skipped
song['has_artwork'] = track.has_artwork
song['skip_when_shuffling'] = track.skip_when_shuffling
song['remember_playback_position'] = track.remember_playback_position
song['flag4'] = track.flag4
song['dbid2'] = track.dbid2
song['lyrics_flag'] = track.lyrics_flag
song['movie_flag'] = track.movie_flag
song['mark_unplayed'] = track.mark_unplayed
song['unk179'] = track.unk179
song['unk180'] = track.unk180
song['pregap'] = track.pregap
song['samplecount'] = track.samplecount
song['unk196'] = track.unk196
song['postgap'] = track.postgap
song['unk204'] = track.unk204
song['mediatype'] = track.mediatype
song['season_nr'] = track.season_nr
song['episode_nr'] = track.episode_nr
song['unk220'] = track.unk220
song['unk224'] = track.unk224
song['unk228'] = track.unk228
song['unk232'] = track.unk232
song['unk236'] = track.unk236
song['unk240'] = track.unk240
song['unk244'] = track.unk244
song['gapless_data'] = track.gapless_data
song['unk252'] = track.unk252
song['gapless_track_flag'] = track.gapless_track_flag
song['gapless_album_flag'] = track.gapless_album_flag
song['obsolete'] = track.obsolete
# song['artwork'] = track.artwork
song['mhii_link'] = track.mhii_link
song['reserved_int1'] = track.reserved_int1
song['reserved_int2'] = track.reserved_int2
song['reserved_int3'] = track.reserved_int3
song['reserved_int4'] = track.reserved_int4
song['reserved_int5'] = track.reserved_int5
song['reserved_int6'] = track.reserved_int6
# song['priv'] = track.priv
# song['reserved2'] = track.reserved2
# song['reserved3'] = track.reserved3
# song['reserved4'] = track.reserved4
# song['reserved5'] = track.reserved5
# song['reserved6'] = track.reserved6
song['usertype'] = track.usertype
# song['userdata'] = track.userdata
song['path'] = ipodpath + track.ipod_path.replace(':', '/')
songs.append(song)
print json.dumps(songs, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment