예제 #1
0
def copyInfo(mp):
    "Copy all info from iPod Database to a local file"
    import gpod
    artists = dict()
    i_itdb = gpod.itdb_parse(mp,None)
    for track in gpod.sw_get_tracks(i_itdb):
        album = track.album
        artist = track.artist
        song = dict()
        song['file']=gpod.itdb_filename_on_ipod(track)
        song['title']=track.title
        song['track number']=track.track_nr
        if artist not in artists:
            artists[artist]=dict()
            artists[artist]['name']=artist
            artists[artist]['albums']=dict()
        if album not in artists[artist]['albums']:
            artists[artist]['albums'][album]=dict()
            artists[artist]['albums'][album]['title']=album
            artists[artist]['albums'][album]['songs']=list()
        artists[artist]['albums'][album]['songs'].append(song)
    pass
    d = shelve.open(ipodDB)
    d[mp]=artists
    d.close()
예제 #2
0
def copyInfo(mp):
    "Copy all info from iPod Database to a local file"
    import gpod
    artists = dict()
    i_itdb = gpod.itdb_parse(mp, None)
    for track in gpod.sw_get_tracks(i_itdb):
        album = track.album
        artist = track.artist
        song = dict()
        song['file'] = gpod.itdb_filename_on_ipod(track)
        song['title'] = track.title
        song['track number'] = track.track_nr
        if artist not in artists:
            artists[artist] = dict()
            artists[artist]['name'] = artist
            artists[artist]['albums'] = dict()
        if album not in artists[artist]['albums']:
            artists[artist]['albums'][album] = dict()
            artists[artist]['albums'][album]['title'] = album
            artists[artist]['albums'][album]['songs'] = list()
        artists[artist]['albums'][album]['songs'].append(song)
    pass
    d = shelve.open(ipodDB)
    d[mp] = artists
    d.close()
예제 #3
0
import sys
from xml import xpath
from xml.dom import minidom
from xml.parsers.expat import ExpatError
import urllib2, urllib

TRUST_LIMIT = 10
dbname = os.path.join(os.environ['HOME'], ".gtkpod/local_0.itdb")

itdb = gpod.itdb_parse_file(dbname, None)
if not itdb:
    print "Failed to read %s" % dbname
    sys.exit(2)

cache = {}
for track in gpod.sw_get_tracks(itdb):
    if track.artist is None:
        continue

    key = track.artist.upper()
    if not cache.has_key(key):
        url = "http://ws.audioscrobbler.com/1.0/artist/%s/toptags.xml" % urllib.quote(
            track.artist)

        try:
            reply = urllib2.urlopen(url).read()
            xmlreply = minidom.parseString(reply)
            attlist = xpath.Evaluate("//toptags/tag[1]/@name", xmlreply)
            count = xpath.Evaluate("//toptags/tag[1]/@count", xmlreply)
            if attlist and count and int(count[0].value) > TRUST_LIMIT:
                cache[key] = str(
예제 #4
0
import mutagen.mp3

# please specify your iPod mountpoint here..
IPOD_MOUNT = '/mnt/ipod/'

itdb = gpod.itdb_parse( IPOD_MOUNT, None)

if not itdb:
    print 'Cannot open iPod at %s' % ( IPOD_MOUNT )
    sys.exit( 2)

# just for some stats..
counter_upd = 0
counter_left = 0

for track in gpod.sw_get_tracks( itdb):
    if track.artist is None or track.title is None or track.album is None:
        # silently ignore
        continue

    filename = gpod.itdb_filename_on_ipod( track)
    try:
        mp3 = mutagen.mp3.MP3(filename)
        if not mp3.tags:
            print ''
            print '%s has no id3 tags' % ( filename )
            print 'iTDB says: AR = %s, TI = %s, AL = %s' % ( track.artist, track.title, track.album )
            mp3.add_tags() # create header
            mp3.tags.add(mutagen.id3.TPE1(3,track.artist))
            mp3.tags.add(mutagen.id3.TALB(3,track.album))
            mp3.tags.add(mutagen.id3.TIT2(3,track.title))
예제 #5
0
파일: syncipod.py 프로젝트: imclab/syncipod
                        relative_filepath = relative_filepath.replace("#","_")
                    print "Copying: " + full_local_filepath
                    subprocess.call(["gvfs-copy", full_local_filepath, "afc://" + uuid + "/" + ipod_path_prefix + "/" + relative_filepath])
                    new_files.append((full_local_filepath, full_ipod_filepath))
                    deleted_files.append(full_ipod_filepath[len(mp):].replace('/',':'))

### Done syncing the music directory with the ipod. Now let's rebuild the database with
### the new changes.

db = gpod.itdb_parse(mp, None)

### First delete the removed/modified files from ipod database. This is an annoying part because we can only lookup track by id
### but we don't have an id, so we basically need to check every track to see if its been deleted/modified
if deleted_files:   
    print "Removing deleted & outdated tracks from the ipod database"
    tracks = gpod.sw_get_tracks(db)
    for track in tracks:
        if track.ipod_path in deleted_files:
        # Remove it from any playlists it might be on
            for pl in gpod.sw_get_playlists(db):
                if gpod.itdb_playlist_contains_track(pl, track):
                    gpod.itdb_playlist_remove_track(pl, track)
    
            # Remove it from the master playlist
            gpod.itdb_playlist_remove_track(gpod.itdb_playlist_mpl(db), track)
    
            # Remove it from the database
            gpod.itdb_track_remove(track)
    
### Now lets add everything new/modified from our music directory
### We'll use the local files to get the metadata to speed things up....