def get_all_tracks(self): tracks = [] for track in gpod.sw_get_playlist_tracks(self.podcasts_playlist): filename = gpod.itdb_filename_on_ipod(track) if filename is None: # This can happen if the episode is deleted on the device logger.info('Episode has no file: %s', track.title) self.remove_track_gpod(track) continue length = util.calculate_size(filename) timestamp = util.file_modification_timestamp(filename) modified = util.format_date(timestamp) try: released = gpod.itdb_time_mac_to_host(track.time_released) released = util.format_date(released) except ValueError, ve: # timestamp out of range for platform time_t (bug 418) logger.info('Cannot convert track time: %s', ve) released = 0 t = SyncTrack(track.title, length, modified, modified_sort=timestamp, libgpodtrack=track, playcount=track.playcount, released=released, podcast=track.artist) tracks.append(t)
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()
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()
def purge(self): for track in gpod.sw_get_playlist_tracks(self.podcasts_playlist): if gpod.itdb_filename_on_ipod(track) is None: logger.info('Episode has no file: %s', track.title) # self.remove_track_gpod(track) elif track.playcount > 0 and not track.rating: logger.info('Purging episode: %s', track.title) self.remove_track_gpod(track)
def remove_track_gpod(self, track): filename = gpod.itdb_filename_on_ipod(track) try: gpod.itdb_playlist_remove_track(self.podcasts_playlist, track) except: logger.info('Track %s not in playlist', track.title) gpod.itdb_track_unlink(track) util.delete_file(filename)
def ipod_filename(self): """Get the full path to the track on the iPod. Note (from the libgpod documentation): This code works around a problem on some systems and might return a filename with different case than the original filename. Don't copy it back to track unless you must. """ return gpod.itdb_filename_on_ipod(self._track)
def remove_track(self, track): self.notify('status', _('Removing %s') % track.title) track=track.libgpodtrack filename=gpod.itdb_filename_on_ipod(track) try: gpod.itdb_playlist_remove_track(self.podcasts_playlist, track) except: log('Track %s not in playlist', track.title, sender=self) gpod.itdb_track_unlink(track) util.delete_file(filename)
def get_all_tracks(self): tracks = [] for track in gpod.sw_get_playlist_tracks(self.podcasts_playlist): filename = gpod.itdb_filename_on_ipod(track) length = util.calculate_size(filename) timestamp = util.file_modification_timestamp(filename) modified = util.format_date(timestamp) released = gpod.itdb_time_mac_to_host(track.time_released) released = util.format_date(released) t = SyncTrack(track.title, length, modified, modified_sort=timestamp, libgpodtrack=track, playcount=track.playcount, released=released, podcast=track.artist) tracks.append(t) return tracks
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)) mp3.tags.add(mutagen.id3.TXXX(3,"Taggger","tagged from itdb with libgpod")) mp3.save() counter_upd += 1 print 'wrote tags to: %s' % ( filename ) else:
print track.title for track in gpod.sw_get_tracks(itdb): lists = [] for playlist in gpod.sw_get_playlists(itdb): if gpod.itdb_playlist_contains_track(playlist, track): lists.append(playlist) print track.artist print track.tracklen print track.size if track.artist == "Placebo": print u"%-25s %-20s %-20s %-30s %s" % (track.title, track.album, track.artist, gpod.itdb_filename_on_ipod(track), repr(u",".join([l.name for l in lists]))) if gpod.itdb_track_set_thumbnail(track,"/tmp/placebo.jpg") != 0: print "Failed to save image thumbnail" print track.orig_image_filename if track.title == remove_track: print "Removing track.." print "..disk" os.unlink(gpod.itdb_filename_on_ipod(track)) for l in lists: print u"..playlist %s" % l.name gpod.itdb_playlist_remove_track(l, track) print "..db" gpod.itdb_track_unlink(track)
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)) mp3.tags.add( mutagen.id3.TXXX(3, "Taggger", "tagged from itdb with libgpod")) mp3.save()