def init(self): """ Init main application """ self.__is_fs = False if Gtk.get_minor_version() > 18: cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/Lollypop/application.css') else: cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/Lollypop/application-legacy.css') cssProvider = Gtk.CssProvider() cssProvider.load_from_file(cssProviderFile) screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) self.settings = Settings.new() self.db = Database() self.playlists = Playlists() # We store cursors for main thread SqlCursor.add(self.db) SqlCursor.add(self.playlists) self.albums = AlbumsDatabase() self.artists = ArtistsDatabase() self.genres = GenresDatabase() self.tracks = TracksDatabase() self.player = Player() self.scanner = CollectionScanner() self.art = Art() self.art.update_art_size() if self.settings.get_value('artist-artwork'): GLib.timeout_add(5000, self.art.cache_artists_info) if LastFM is not None: self.lastfm = LastFM() if not self.settings.get_value('disable-mpris'): # Ubuntu > 16.04 if Gtk.get_minor_version() > 18: from lollypop.mpris import MPRIS # Ubuntu <= 16.04, Debian Jessie, ElementaryOS else: from lollypop.mpris_legacy import MPRIS MPRIS(self) if not self.settings.get_value('disable-notifications'): from lollypop.notification import NotificationManager self.notify = NotificationManager() settings = Gtk.Settings.get_default() dark = self.settings.get_value('dark-ui') settings.set_property('gtk-application-prefer-dark-theme', dark) self.add_action(self.settings.create_action('playback')) self.add_action(self.settings.create_action('shuffle')) self.db.upgrade()
def init(self): """ Init main application """ if Gtk.get_minor_version() > 18: cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/Lollypop/application.css') else: cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/Lollypop/application-legacy.css') cssProvider = Gtk.CssProvider() cssProvider.load_from_file(cssProviderFile) screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) self.settings = Settings.new() ArtSize.BIG = self.settings.get_value('cover-size').get_int32() # For a 200 album artwork, we want a 60 artist artwork ArtSize.ARTIST_SMALL = ArtSize.BIG * 60 / 200 self.db = Database() self.playlists = Playlists() # We store cursors for main thread SqlCursor.add(self.db) SqlCursor.add(self.playlists) self.albums = AlbumsDatabase() self.artists = ArtistsDatabase() self.genres = GenresDatabase() self.tracks = TracksDatabase() self.player = Player() self.scanner = CollectionScanner() self.art = Art() if self.settings.get_value('artist-artwork'): GLib.timeout_add(5000, self.art.cache_artists_art) if LastFM is not None: self.lastfm = LastFM() if not self.settings.get_value('disable-mpris'): MPRIS(self) if not self.settings.get_value('disable-notifications'): self.notify = NotificationManager() settings = Gtk.Settings.get_default() dark = self.settings.get_value('dark-ui') settings.set_property('gtk-application-prefer-dark-theme', dark) self._parser = TotemPlParser.Parser.new() self._parser.connect('entry-parsed', self._on_entry_parsed) self.add_action(self.settings.create_action('shuffle')) self._is_fs = False
def init(self): """ Init main application """ cssProviderFile = Gio.File.new_for_uri( 'resource:///org/gnome/Lollypop/application.css') cssProvider = Gtk.CssProvider() cssProvider.load_from_file(cssProviderFile) screen = Gdk.Screen.get_default() styleContext = Gtk.StyleContext() styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER) self.settings = Settings.new() ArtSize.BIG = self.settings.get_value('cover-size').get_int32() if LastFM is not None: self.lastfm = LastFM() self.db = Database() self.playlists = Playlists() # We store cursors for main thread SqlCursor.add(self.db) SqlCursor.add(self.playlists) self.albums = AlbumsDatabase() self.artists = ArtistsDatabase() self.genres = GenresDatabase() self.tracks = TracksDatabase() self.player = Player() self.scanner = CollectionScanner() self.art = Art() if not self.settings.get_value('disable-mpris'): MPRIS(self) if not self.settings.get_value('disable-mpd'): self.mpd = MpdServerDaemon( self.settings.get_value('mpd-eth').get_string(), self.settings.get_value('mpd-port').get_int32()) if not self.settings.get_value('disable-notifications'): self.notify = NotificationManager() settings = Gtk.Settings.get_default() dark = self.settings.get_value('dark-ui') settings.set_property('gtk-application-prefer-dark-theme', dark) self._parser = TotemPlParser.Parser.new() self._parser.connect('entry-parsed', self._on_entry_parsed) self.add_action(self.settings.create_action('shuffle')) self._is_fs = False
def get_disc_tracks(self, album_id, genre_ids, artist_ids, disc): """ Get tracks ids for album id disc @param album id as int @param genre ids as [int] @param artist ids as [int] @param disc as int @return [int] """ genre_ids = remove_static_genres(genre_ids) # Reset filters if not needed if not self.__has_genres(album_id): genre_ids = [] if not self.__has_artists(album_id): artist_ids = [] with SqlCursor(Lp().db) as sql: filters = (album_id, disc) request = "SELECT DISTINCT tracks.rowid\ FROM tracks" if genre_ids: request += ", track_genres" filters += tuple(genre_ids) if artist_ids: request += ", track_artists" filters += tuple(artist_ids) request += " WHERE album_id=?\ AND discnumber=?" if genre_ids: request += " AND track_genres.track_id = tracks.rowid AND (" for genre_id in genre_ids: request += "track_genres.genre_id=? OR " request += "1=0)" if artist_ids: request += " AND track_artists.track_id=tracks.rowid AND (" for artist_id in artist_ids: request += "track_artists.artist_id=? OR " request += "1=0)" request += " ORDER BY discnumber, tracknumber, tracks.name" result = sql.execute(request, filters) return list(itertools.chain(*result))
def clean(self, album_id): """ Clean database for album id @param album id as int @param return True if album deleted or genre modified @warning commit needed """ with SqlCursor(Lp().db) as sql: ret = False # Check album really have tracks from its genres for genre_id in self.get_genre_ids(album_id): result = sql.execute( "SELECT track_id\ FROM tracks, track_genres\ WHERE track_genres.track_id ==\ tracks.rowid\ AND tracks.album_id=?\ AND track_genres.genre_id=?", (album_id, genre_id)) v = result.fetchone() if not v: ret = True sql.execute( "DELETE from album_genres\ WHERE album_id=?\ AND genre_id=?", (album_id, genre_id)) # Remove album if orphaned result = sql.execute( "SELECT rowid from tracks\ WHERE album_id=?\ LIMIT 1", (album_id, )) v = result.fetchone() # Album empty, remove it if not v: ret = True sql.execute( "DELETE FROM album_artists\ WHERE album_id=?", (album_id, )) sql.execute("DELETE FROM albums WHERE rowid=?", (album_id, )) return ret
def get_track_uris(self, album_id, genre_ids, artist_ids): """ Get track uris for album id/disc Will search track from albums from same artist with same name and different genre @param album id as int @param genre ids as [int] @param artist_ids as [int] @return Arrays of tracks id as int """ genre_ids = remove_static_genres(genre_ids) # Reset filters if not needed if not self.__has_genres(album_id): genre_ids = [] if not self.__has_artists(album_id): artist_ids = [] with SqlCursor(Lp().db) as sql: filters = (album_id, ) request = "SELECT DISTINCT tracks.uri\ FROM tracks" if genre_ids: request += ", track_genres" filters += tuple(genre_ids) if artist_ids: request += ", track_artists" filters += tuple(artist_ids) request += " WHERE album_id=? " if genre_ids: request += "AND track_genres.track_id = tracks.rowid AND (" for genre_id in genre_ids: request += "track_genres.genre_id=? OR " request += "1=0)" if artist_ids: request += "AND track_artists.track_id=tracks.rowid AND (" for artist_id in artist_ids: request += "track_artists.artist_id=? OR " request += "1=0)" request += " ORDER BY discnumber, tracknumber" result = sql.execute(request, filters) return list(itertools.chain(*result))
def get_name(self, artist_id): """ Get artist name @param artist_id as int @return str """ with SqlCursor(self.__db) as sql: if artist_id == Type.COMPILATIONS: return _("Many artists") if App().settings.get_value("show-artist-sort"): result = sql.execute( "SELECT sortname from artists WHERE rowid=?", (artist_id, )) else: result = sql.execute("SELECT name from artists WHERE rowid=?", (artist_id, )) v = result.fetchone() if v is not None: return v[0] return ""
def get_id_by_name_artists(self, album_name, artist_ids): """ Get non compilation album id @param album_name as str @param artist_ids as [int] @return int """ with SqlCursor(App().db) as sql: filters = (album_name,) request = "SELECT albums.rowid FROM albums, album_artists\ WHERE name=? COLLATE NOCASE AND\ album_artists.album_id=albums.rowid AND (1=0 " filters += tuple(artist_ids) for artist_id in artist_ids: request += "OR artist_id=? " request += ")" result = sql.execute(request, filters) v = result.fetchone() if v is not None: return v[0] return None
def search_performed(self, searched, storage_type): """ Search tracks looking like searched with performers @param searched as str without accents @param storage_type as StorageType @return [(int, name)] """ with SqlCursor(self.__db) as sql: filters = ("%" + searched + "%", storage_type) request = "SELECT DISTINCT tracks.rowid, artists.name\ FROM track_artists, tracks, artists\ WHERE track_artists.artist_id=artists.rowid AND\ track_artists.track_id=tracks.rowid AND\ noaccents(artists.name) LIKE ? AND\ tracks.storage_type & ? AND NOT EXISTS (\ SELECT album_artists.artist_id\ FROM album_artists\ WHERE album_artists.artist_id=artists.rowid)\ LIMIT 25" result = sql.execute(request, filters) return list(result)
def get_id(self, name): """ Get artist id @param Artist name as string @return Artist id as int """ # Special case, id name is fully uppercase, do not use NOCASE # We want to have a different artist with SqlCursor(App().db) as sql: if name.isupper(): result = sql.execute( "SELECT rowid from artists\ WHERE name=?", (name, )) else: result = sql.execute( "SELECT rowid from artists\ WHERE name=? COLLATE NOCASE", (name, )) v = result.fetchone() if v is not None: return v[0] return None
def get(self, name, duration): """ Get stats for track with filename and duration @param path as str @param duration as int @return (popularity, ltime, mtime, loved album, album_popularity) as (int, int, int, int, int, int) """ with SqlCursor(self) as sql: result = sql.execute( "SELECT popularity, rate, ltime, mtime,\ loved, loved_album, album_popularity,\ album_rate\ FROM history\ WHERE name=?\ AND duration=?", (name, duration)) v = result.fetchone() if v is not None: return v return (0, 0, 0, 0, 0, 0, 0, 0)
def del_tracks(self, track_ids): """ Delete tracks from db @param track_ids as [int] """ with SqlCursor(self) as sql: for track_id in track_ids: album_id = Lp().tracks.get_album_id(track_id) art_file = Lp().art.get_album_cache_name(Album(album_id)) genre_ids = Lp().tracks.get_genre_ids(track_id) album_artist_ids = Lp().albums.get_artist_ids(album_id) artist_ids = Lp().tracks.get_artist_ids(track_id) Lp().tracks.remove(track_id) Lp().tracks.clean(track_id) if Lp().albums.clean(album_id): Lp().art.clean_store(art_file) for artist_id in album_artist_ids + artist_ids: Lp().artists.clean(artist_id) for genre_id in genre_ids: Lp().genres.clean(genre_id) sql.commit()
def get_id(self, name, mb_artist_id=None): """ Get artist id @param name as string @param mb_artist_id as str @return (artist_id as int, name as str) """ with SqlCursor(self.__db) as sql: request = "SELECT rowid, name from artists\ WHERE name=?" params = [name] if mb_artist_id: request += " AND (mb_artist_id=? OR mb_artist_id IS NULL)" params.append(mb_artist_id) request += " COLLATE NOCASE" result = sql.execute(request, params) v = result.fetchone() if v is not None: return (v[0], v[1]) return (None, None)
def get_loves(self): """ Get albums ids with popularity @return array of album ids as int """ with SqlCursor(Lp().db) as sql: filters = (Type.CHARTS, ) request = "SELECT DISTINCT albums.rowid\ FROM albums, album_genres as AG\ WHERE ? NOT IN (\ SELECT album_genres.genre_id\ FROM album_genres\ WHERE AG.album_id=album_genres.album_id)\ AND loved=1\ AND AG.album_id=albums.rowid" if not get_network_available(): request += " AND albums.synced!=%s" % Type.NONE request += " ORDER BY popularity DESC" result = sql.execute(request, filters) return list(itertools.chain(*result))
def get_rated(self, limit=100): """ Get albums with user rating >= 4 @param limit as int @return array of album ids as int """ with SqlCursor(Lp().db) as sql: filters = (Type.CHARTS, ) request = "SELECT DISTINCT albums.rowid\ FROM albums, album_genres as AG\ WHERE ? NOT IN (\ SELECT album_genres.genre_id\ FROM album_genres\ WHERE AG.album_id=album_genres.album_id)\ AND rate>=4\ AND AG.album_id=albums.rowid" if not get_network_available(): request += " AND albums.synced!=%s" % Type.NONE request += " ORDER BY popularity DESC LIMIT %s" % limit result = sql.execute(request, filters) return list(itertools.chain(*result))
def set_mtime(self, track_id, genre_ids, mtime): """ Get modification time @param track id as int @param mtime as int """ with SqlCursor(Lp().db) as sql: filters = ( mtime, track_id, ) + tuple(genre_ids) request = "UPDATE track_genres\ SET mtime=?\ WHERE track_id=?\ AND (" for genre_id in genre_ids: request += "genre_id=? OR " request += "1=0)" sql.execute(request, filters) sql.commit()
def clean(self, artist_id): """ Clean database for artist id @param artist id as int @warning commit needed """ with SqlCursor(Lp().db) as sql: result = sql.execute("SELECT album_id from album_artists\ WHERE artist_id=?\ LIMIT 1", (artist_id,)) v = result.fetchone() # Check tracks if not v: result = sql.execute("SELECT track_id from track_artists\ WHERE artist_id=?\ LIMIT 1", (artist_id,)) v = result.fetchone() # Artist with no relation, remove if not v: sql.execute("DELETE FROM artists WHERE rowid=?", (artist_id,))
def search(self, string, limit=25): """ Search for albums looking like string @param search as str @param limit as int/None @return album ids as [int] """ with SqlCursor(Lp().db) as sql: if limit is None: filters = ('%' + noaccents(string) + '%', Type.CHARTS) else: filters = ('%' + noaccents(string) + '%', Type.CHARTS, limit) request = ("SELECT albums.rowid\ FROM albums, album_genres\ WHERE noaccents(name) LIKE ?\ AND album_genres.genre_id!=?\ AND album_genres.album_id=albums.rowid") if limit is not None: request += " LIMIT ?" result = sql.execute(request, filters) return list(itertools.chain(*result))
def execute(self, request): """ Execute SQL request (only smart one) @param request as str @return list """ try: with SqlCursor(App().db) as sql: result = sql.execute(request) # Special case for OR request if request.find("ORDER BY random()") == -1 and\ request.find("UNION") != -1: ids = [] for (id, other) in list(result): ids.append(id) return ids else: return list(itertools.chain(*result)) except Exception as e: Logger.error("Database::execute(): %s -> %s", e, request) return []
def get_synced_ids(self): """ Get synced album ids """ with SqlCursor(Lp().db) as sql: request = "SELECT DISTINCT albums.rowid\ FROM albums, artists, album_artists\ WHERE album_artists.album_id = albums.rowid\ AND (album_artists.artist_id = artists.rowid\ OR album_artists.artist_id=?)\ AND synced=1" order = " ORDER BY artists.sortname\ COLLATE NOCASE COLLATE LOCALIZED,\ albums.year,\ albums.name\ COLLATE NOCASE COLLATE LOCALIZED" filters = (Type.COMPILATIONS, ) result = sql.execute(request + order, filters) return list(itertools.chain(*result))
def add(self, name, uri, duration, tracknumber, discnumber, discname, album_id, year, popularity, rate, ltime, persistent=DbPersistent.INTERNAL): """ Add a new track to database @param name as string @param uri as string, @param duration as int @param tracknumber as int @param discnumber as int @param discname as str @param album_id as int @param genre_id as int @param year as int @param popularity as int @param rate as int @param ltime as int @param persistent as int @return inserted rowid as int @warning: commit needed """ with SqlCursor(Lp().db) as sql: result = sql.execute( "INSERT INTO tracks (name, uri, duration, tracknumber,\ discnumber, discname, album_id,\ year, popularity, rate, ltime, persistent) VALUES\ (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (name, uri, duration, tracknumber, discnumber, discname, album_id, year, popularity, rate, ltime, persistent)) return result.lastrowid
def __del_from_db(self, uri): """ Delete track from db @param uri as str """ try: f = Lio.File.new_for_uri(uri) name = f.get_basename() track_id = Lp().tracks.get_id_by_uri(uri) album_id = Lp().tracks.get_album_id(track_id) genre_ids = Lp().tracks.get_genre_ids(track_id) album_artist_ids = Lp().albums.get_artist_ids(album_id) artist_ids = Lp().tracks.get_artist_ids(track_id) popularity = Lp().tracks.get_popularity(track_id) rate = Lp().tracks.get_rate(track_id) ltime = Lp().tracks.get_ltime(track_id) mtime = Lp().albums.get_mtime(album_id) duration = Lp().tracks.get_duration(track_id) album_popularity = Lp().albums.get_popularity(album_id) album_rate = Lp().albums.get_rate(album_id) loved = Lp().albums.get_loved(album_id) uri = Lp().tracks.get_uri(track_id) self.__history.add(name, duration, popularity, rate, ltime, mtime, loved, album_popularity, album_rate) Lp().tracks.remove(track_id) Lp().tracks.clean(track_id) deleted = Lp().albums.clean(album_id) if deleted: with SqlCursor(Lp().db) as sql: sql.commit() GLib.idle_add(self.emit, "album-updated", album_id, True) for artist_id in album_artist_ids + artist_ids: Lp().artists.clean(artist_id) GLib.idle_add(self.emit, "artist-updated", artist_id, False) for genre_id in genre_ids: Lp().genres.clean(genre_id) GLib.idle_add(self.emit, "genre-updated", genre_id, False) except Exception as e: print("CollectionScanner::__del_from_db:", e)
def get_albums_for_year(self, year, limit=-1): """ Return albums for year @return album ids as [int] @param limit as int """ with SqlCursor(App().db) as sql: if limit != -1: result = sql.execute( "SELECT albums.rowid\ FROM albums\ WHERE albums.year=?\ ORDER BY random() LIMIT ?", (year, limit)) else: order = " ORDER BY artists.sortname\ COLLATE NOCASE COLLATE LOCALIZED,\ albums.timestamp,\ albums.name\ COLLATE NOCASE COLLATE LOCALIZED" if year == Type.NONE: request = "SELECT DISTINCT albums.rowid\ FROM albums, album_artists, artists\ WHERE albums.rowid=album_artists.album_id AND\ artists.rowid=album_artists.artist_id AND\ albums.year is null" filter = () else: request = "SELECT DISTINCT albums.rowid\ FROM albums, album_artists, artists\ WHERE albums.rowid=album_artists.album_id AND\ artists.rowid=album_artists.artist_id AND\ albums.year=?" filter = (year, ) request += order result = sql.execute(request, filter) return list(itertools.chain(*result))
def add(self, name, artist_id, no_album_artist, year, path, popularity, mtime): """ Add a new album to database @param Album name as string @param artist id as int, @param no_album_artist as bool, @param year as int @param path as string @param mtime as int @return inserted rowid as int @warning: commit needed """ with SqlCursor(Lp().db) as sql: result = sql.execute( "INSERT INTO albums\ (name, artist_id, no_album_artist, year,\ path, popularity, mtime)\ VALUES (?, ?, ?, ?, ?, ?, ?)", (name, artist_id, no_album_artist, year, path, popularity, mtime)) return result.lastrowid
def get_compilation_id(self, album_name, year): """ Get compilation id @param Album name as string, @param year as int @return Album id as int """ with SqlCursor(Lp().db) as sql: if year is None: result = sql.execute( "SELECT rowid FROM albums where name=?\ AND no_album_artist=1\ AND year is null", (album_name, )) else: result = sql.execute( "SELECT rowid FROM albums where name=?\ AND no_album_artist=1\ AND year=?", (album_name, year)) v = result.fetchone() if v is not None: return v[0] return None
def get_id(self, album_name, artist_id, year): """ Get non compilation album id @param Album name as string, @param artist id as int @param year as int @return Album id as int """ with SqlCursor(Lp().db) as sql: filters = (album_name, artist_id) request = "SELECT rowid FROM albums where name=?\ AND artist_id=? " if year is None: request += "AND year is null" else: request += "AND year =?" filters += (year,) result = sql.execute(request, filters) v = result.fetchone() if v is not None: return v[0] return None
def get_name(self, playlist_id): """ Get playlist name @param playlist id as int @return playlist name as str """ if playlist_id == Type.LOVED: return self.LOVED elif playlist_id < 0: for (id, name, sortname) in ShownPlaylists.get(True): if id == playlist_id: return name with SqlCursor(self) as sql: result = sql.execute( "SELECT name\ FROM playlists\ WHERE rowid=?", (playlist_id, )) v = result.fetchone() if v is not None: return v[0] return ""
def get_name(self, playlist_id): """ Get playlist name @param playlist id as int @return playlist name as str """ if playlist_id == Type.LOVED: return self.LOVED elif playlist_id == Type.SPOTIFY: return _("Spotify charts") elif playlist_id == Type.LASTFM: return _("Last.fm charts") with SqlCursor(self) as sql: result = sql.execute( "SELECT name\ FROM playlists\ WHERE rowid=?", (playlist_id, )) v = result.fetchone() if v is not None: return v[0] return ''
def add(self, name, artist_ids, path, popularity, mtime): """ Add a new album to database @param Album name as string @param artist ids as int @param path as string @param mtime as int @return inserted rowid as int @warning: commit needed """ with SqlCursor(Lp().db) as sql: result = sql.execute("INSERT INTO albums\ (name, no_album_artist,\ path, popularity, mtime, synced)\ VALUES (?, ?, ?, ?, ?, ?)", (name, artist_ids == [], path, popularity, mtime, 0)) for artist_id in artist_ids: sql.execute("INSERT INTO album_artists\ (album_id, artist_id)\ VALUES (?, ?)", (result.lastrowid, artist_id)) return result.lastrowid
def get_non_compilation_id(self, album_name, artist_ids): """ Get non compilation album id @param Album name as string, @param artist ids as [int] @return Album id as int """ with SqlCursor(Lp().db) as sql: filters = (album_name,) filters += tuple(artist_ids) request = "SELECT albums.rowid FROM albums, album_artists\ WHERE name=? AND\ no_album_artist=0 AND\ album_artists.album_id=albums.rowid AND (1=0 " for artist_id in artist_ids: request += "OR artist_id=? " request += ")" result = sql.execute(request, filters) v = result.fetchone() if v is not None: return v[0] return None
def get_track_ids_sorted(self, playlist_id): """ Return availables track ids for playlist sorted by artist/album @param playlist_id as int @return array of track id as int """ with SqlCursor(self) as sql: result = sql.execute( "SELECT music.tracks.rowid\ FROM tracks, music.tracks,\ music.track_artists, music.artists\ WHERE tracks.playlist_id=?\ AND music.track_artists.track_id=\ music.tracks.rowid\ AND music.artists.id=\ music.track_artists.artist_id\ AND music.tracks.uri=\ main.tracks.uri\ ORDER BY\ music.artists.sortname, album_id", (playlist_id, )) return list(itertools.chain(*result))
def __init__(self): """ Init playlists manager """ GObject.GObject.__init__(self) self._LOVED = _("Loved tracks") self._MPD = _("Network control") try_import = not os.path.exists(self.DB_PATH) # Create db schema try: with SqlCursor(self) as sql: sql.execute(self.create_playlists) sql.execute(self.create_tracks) sql.commit() except: pass # We import playlists from lollypop < 0.9.60 if try_import: try: d = Gio.File.new_for_path(self.LOCAL_PATH + "/playlists") infos = d.enumerate_children( 'standard::name', Gio.FileQueryInfoFlags.NOFOLLOW_SYMLINKS, None) for info in infos: f = info.get_name() if f.endswith(".m3u"): if f[:-4] != self._LOVED: self.add(f[:-4]) playlist_id = self.get_id(f[:-4]) parser = TotemPlParser.Parser.new() parser.connect('entry-parsed', self._on_entry_parsed, playlist_id) parser.parse_async(d.get_uri() + "/%s" % f, True, None, None) except: pass
def add_tracks(self, playlist_id, tracks, notify=True): """ Add tracks to playlist if not already present @param playlist id as int @param tracks as [Track] @param notify as bool """ with SqlCursor(self) as sql: changed = False for track in tracks: if not self.exists_track(playlist_id, track.id): changed = True sql.execute("INSERT INTO tracks" " VALUES (?, ?)", (playlist_id, track.path)) if changed: sql.execute("UPDATE playlists SET mtime=?\ WHERE rowid=?", (datetime.now().strftime('%s'), playlist_id)) sql.commit() if notify: GLib.idle_add(self.emit, 'playlist-changed', playlist_id)