def __init__(self, parent_db, title="New Playlist", smart=False, pos=-1, proxied_playlist=None): """Create a playlist object. parent_db is the database object to which the playlist belongs. title is a string that provides a name for the playlist. If smart is true the playlist will be a smart playlist. If pos is set the track will be inserted at that position. By default the playlist will be added at the end of the database. If proxied_playlist is set it is expected to be an Itdb_Playlist object (as returned by gpod.sw_get_playlist() or similar functions). """ self._db = parent_db if proxied_playlist: self._pl = proxied_playlist else: if smart: smart = 1 else: smart = 0 self._pl = gpod.itdb_playlist_new(title, smart) gpod.itdb_playlist_add(self._db._itdb, self._pl, pos)
def rebuild(mountpoint, ipod_name, dry_run=True): db = gpod.itdb_new() gpod.itdb_set_mountpoint(db, mountpoint) master = gpod.itdb_playlist_new(ipod_name, False) gpod.itdb_playlist_set_mpl(master) gpod.itdb_playlist_add(db, master, -1) mb_albumid_to_artwork = dict() def store_artwork(artwork_data, mb_albumid): import gio from gtk import gdk artwork_in = gio.memory_input_stream_new_from_data(artwork_data) pixbuf = gdk.pixbuf_new_from_stream(artwork_in, None) artwork = gpod.itdb_artwork_new() gpod.itdb_artwork_set_thumbnail_from_pixbuf(artwork, pixbuf, 0, None) mb_albumid_to_artwork[mb_albumid] = artwork return artwork def get_artwork(mb_albumid): return mb_albumid_to_artwork.get(mb_albumid) def action(path): from os import sep, stat from os.path import relpath from mutagen.m4a import M4AInfo relative_path = relpath(path, mountpoint) ipod_path = ":" + relative_path.replace(sep, ":") md_hard, md_easy = get_metadata(path) info = md_easy.info c = is_compilation(md_easy) track = gpod.itdb_track_new() track.title = get_first_utf8(md_easy, "title") track.artist = get_first_utf8(md_easy, "artist") track.album = get_first_utf8(md_easy, "album") track.compilation = c track.tracklen = int(info.length * 1000) track.bitrate = int(info.bitrate) track.samplerate = int(info.sample_rate) track.ipod_path = ipod_path track.size = stat(path).st_size if isinstance(info, M4AInfo): track.filetype = "M4A-file" else: track.filetype = "MP3-file" mb_albumid = get_first_utf8(md_easy, "musicbrainz_albumid", None) if mb_albumid is not None: existing_artwork = get_artwork(mb_albumid) if existing_artwork is not None: _log.debug( "found existing artwork for track %r (%r-%r)", path, get_first(md_easy, "artist"), get_first(md_easy, "album"), ) artwork = existing_artwork else: artwork_data = get_any_artwork(md_hard) if artwork_data is not None: _log.debug("storing artwork for track %r", path) artwork = store_artwork(artwork_data, mb_albumid) else: artwork = None else: artwork = None if artwork is not None: track.artwork = gpod.itdb_artwork_duplicate(artwork) try: track_number = get_first(md_easy, "tracknumber") disc_number = get_first(md_easy, "discnumber", "1") track_n = track_number.split("/") disc_n = disc_number.split("/") track.track_nr = int(track_n[0]) track.cd_nr = int(disc_n[0]) if len(track_n) > 1: track.tracks = int(track_n[1]) if len(disc_n) > 1: track.cds = int(disc_n[1]) except Exception, e: _log.error("%r %r", e, md_easy) gpod.itdb_track_add(db, track, -1) gpod.itdb_playlist_add_track(master, track, -1)
get_playlists(playlists) for playlist in playlists: if (listPlaylists or verbose): print "Playlist Name: " , playlist.name # , "Type: ", type(playlist.name) #import pdb; pdb.set_trace() if playlistSelected != playlist.name: continue if playlistSelected: print "test check for new playlist construction" #Create our temp playlist and start putting tracks in it that meet our clean threshold tmpPlaylistName = "Clean."+playlist.name tmpPlaylist = gpod.itdb_playlist_new(tmpPlaylistName, 0) gpod.itdb_playlist_add(itdb,tmpPlaylist,-1) if listPlaylists == False: #iterating over tracks on ipod (didn't pass the object representing tracks) for track in gpod.sw_get_playlist_tracks(playlist): print track.artist, "-" ,track.title explicitCount = explicit_count(track) print 'Explicit Count is: ' , explicitCount if explicitCount <= explicitThreshold and \ explicitCount >= 0: #if this track is a keeper #Add our track to our already constructed playlist gpod.itdb_playlist_add_track(tmpPlaylist,track, -1) # TODO REMOVE THIS - this is JUST FOR TESTING #if track.title == "Some Song Title To Break On": # print "***********BREAKING FOR TEST PURPOSES************"