def _sort_items(self, model, itera, iterb, data): if not self._updating: return False a_index = model.get_value(itera, 0) a = format_artist_name(model.get_value(itera, 1)) b = format_artist_name(model.get_value(iterb, 1)) # Do not order static entries if a_index < 0: return False else: return a.lower() > b.lower()
def add_artists(self, artists, album_artists, sortnames): """ Add artists to db @param artists as [string] @param album artists as [string] @param sortnames as [string] @commit needed @param return ([artist ids as int], [new artist ids as int]) """ new_artist_ids = [] artist_ids = [] sortsplit = sortnames.split(';') sortlen = len(sortsplit) i = 0 for artist in artists.split(';'): # Get artist id, add it if missing artist_id = Lp().artists.get_id(artist) if i >= sortlen or sortsplit[i] == "": sortname = format_artist_name(artist) else: sortname = sortsplit[i] if artist_id is None: artist_id = Lp().artists.add(artist, sortname) if artist in album_artists: new_artist_ids.append(artist_id) else: Lp().artists.set_sortname(artist_id, sortname) i += 1 artist_ids.append(artist_id) return (artist_ids, new_artist_ids)
def add_album_artists(self, artists, sortnames): """ Add album artist to db @param artists as [string] @param sortnames as [string] @param artist ids as int @commit needed """ artist_ids = [] sortsplit = sortnames.split(';') sortlen = len(sortsplit) i = 0 for artist in artists.split(';'): artist = artist.strip() if artist != '': # Get album artist id, add it if missing artist_id = Lp().artists.get_id(artist) if i >= sortlen or sortsplit[i] == "": sortname = None else: sortname = sortsplit[i].strip() if artist_id is None: if sortname is None: sortname = format_artist_name(artist) artist_id = Lp().artists.add(artist, sortname) elif sortname is not None: Lp().artists.set_sortname(artist_id, sortname) i += 1 artist_ids.append(artist_id) return artist_ids
def add_artists(self, artists, album_artist, sortname): """ Add artists to db @param artists as [string] @param album artist as string @param sortname as string @commit needed @param return ([artist ids as int], [new artist ids as int]) """ new_artist_ids = [] # Get all artist ids artist_ids = [] for artist in artists.split(';'): # Get artist id, add it if missing artist_id = Lp().artists.get_id(artist) if artist_id is None: if sortname == "": sortname = format_artist_name(artist) artist_id = Lp().artists.add(artist, sortname) if artist == album_artist: new_artist_ids.append(artist_id) elif sortname != "": Lp().artists.set_sortname(artist_id, sortname) artist_ids.append(artist_id) return (artist_ids, new_artist_ids)
def add_artists(self, artists, album_artists, sortnames): """ Add artists to db @param artists as [string] @param album artists as [string] @param sortnames as [string] @commit needed @param return ([artist ids as int], [new artist ids as int]) """ new_artist_ids = [] artist_ids = [] sortsplit = sortnames.split(';') sortlen = len(sortsplit) i = 0 for artist in artists.split(';'): artist = artist.strip() if artist != '': # Get artist id, add it if missing artist_id = Lp().artists.get_id(artist) if i >= sortlen or sortsplit[i] == "": sortname = format_artist_name(artist) else: sortname = sortsplit[i].strip() if artist_id is None: artist_id = Lp().artists.add(artist, sortname) if artist in album_artists: new_artist_ids.append(artist_id) else: Lp().artists.set_sortname(artist_id, sortname) i += 1 artist_ids.append(artist_id) return (artist_ids, new_artist_ids)
def _sort_items(self, model, itera, iterb, data): if not self._updating: return False a_index = model.get_value(itera, 0) b_index = model.get_value(iterb, 0) a = format_artist_name(model.get_value(itera, 1)) b = format_artist_name(model.get_value(iterb, 1)) # Static vs static if a_index < 0 and b_index < 0: return a_index < b_index # Static entries always on top elif b_index < 0: return True # Static entries always on top if a_index < 0: return False # String comparaison for non static else: return a.lower() > b.lower()
def search(self, string): """ Search for artists looking like string @param string @return Array of id as int """ with SqlCursor(Lp().db) as sql: result = sql.execute("SELECT rowid FROM artists\ WHERE name LIKE ?\ LIMIT 25", ('%' + format_artist_name(string) + '%',)) return list(itertools.chain(*result))
def search(self, string, sql=None): """ Search for artists looking like string @param string @return Array of id as int """ if not sql: sql = Lp.sql result = sql.execute("SELECT rowid FROM artists\ WHERE name LIKE ?\ LIMIT 25", ('%' + format_artist_name(string) + '%',)) return list(itertools.chain(*result))
def _find_tracks(self, cmd_args): """ find tracks @syntax find filter value @param args as str """ tracks = [] args = self._get_args(cmd_args) # Search for filters i = 0 track_position = None artist = artist_id = None album = None genre = genre_id = None date = '' while i < len(args) - 1: if args[i].lower() == 'album': album = args[i+1] elif args[i].lower() == 'artist' or\ args[i].lower() == 'albumartist': artist = format_artist_name(args[i+1]) elif args[i].lower() == 'genre': genre = args[i+1] elif args[i].lower() == 'date': date = args[i+1] elif args[i].lower() == 'track': track_position = args[i+1] i += 2 try: year = int(date) except: year = Type.NONE if genre is not None: genre_id = Lp().genres.get_id(genre) if artist is not None: artist_id = Lp().artists.get_id(artist) # We search for tracks and filter on position for track_id in self.server.mpddb.get_tracks_ids(album, artist_id, genre_id, year): track_id_position = None if track_position is not None: track_id_position = Lp().tracks.get_position(track_id) if track_id_position == track_position: tracks.append(track_id) return tracks
def add_artists(self, artists, sortnames, mb_artist_id=""): """ Add artists to db @param artists as str @param sortnames as str @param mb_artist_id as str @return ([int], [int]): (added artist ids, artist ids) """ artist_ids = [] added_artist_ids = [] artistsplit = artists.split(";") sortsplit = sortnames.split(";") sortlen = len(sortsplit) mbidsplit = mb_artist_id.split(";") mbidlen = len(mbidsplit) if len(artistsplit) != mbidlen: mbidsplit = [] mbidlen = 0 i = 0 for artist in artistsplit: artist = artist.strip() if artist != "": if i >= mbidlen or mbidsplit[i] == "": mbid = None else: mbid = mbidsplit[i].strip() # Get artist id, add it if missing (artist_id, db_name) = App().artists.get_id(artist, mbid) if i >= sortlen or sortsplit[i] == "": sortname = None else: sortname = sortsplit[i].strip() if artist_id is None: if sortname is None: sortname = format_artist_name(artist) artist_id = App().artists.add(artist, sortname, mbid) added_artist_ids.append(artist_id) else: # artists.get_id() is NOCASE, check if we need to update # artist name if db_name != artist: App().artists.set_name(artist_id, artist) if sortname is not None: App().artists.set_sortname(artist_id, sortname) if mbid is not None: App().artists.set_mb_artist_id(artist_id, mbid) i += 1 artist_ids.append(artist_id) return (added_artist_ids, artist_ids)
def _sort_items(self, model, itera, iterb, data): """ Sort model """ if not self._updating: return False a_index = model.get_value(itera, 0) b_index = model.get_value(iterb, 0) a = format_artist_name(model.get_value(itera, 1)) b = format_artist_name(model.get_value(iterb, 1)) # Static vs static if a_index < 0 and b_index < 0: return a_index < b_index # Static entries always on top elif b_index < 0: return True # Static entries always on top if a_index < 0: return False # String comparaison for non static else: return a.lower() > b.lower()
def add(self, name, sortname): """ Add a new artist to database @param artist name as string @param sortname as string @return inserted rowid as int @warning: commit needed """ if sortname == "": sortname = format_artist_name(name) with SqlCursor(Lp().db) as sql: result = sql.execute("INSERT INTO artists (name, sortname)\ VALUES (?, ?)", (name, sortname)) return result.lastrowid
def add(self, name, sortname): """ Add a new artist to database @param artist name as string @param sortname as string @return inserted rowid as int @warning: commit needed """ if sortname == "": sortname = format_artist_name(name) with SqlCursor(Lp().db) as sql: result = sql.execute( "INSERT INTO artists (name, sortname)\ VALUES (?, ?)", (name, sortname)) return result.lastrowid
def add_album_artist(self, album_artist): """ Add album artist to db @param album_artist as string @param return ([album artist ids as int], [new as bool]) @commit needed """ album_artist_id = None new = False if album_artist: album_artist = format_artist_name(album_artist) # Get album artist id, add it if missing album_artist_id = Lp().artists.get_id(album_artist) if album_artist_id is None: album_artist_id = Lp().artists.add(album_artist) new = True return (album_artist_id, new)
def add_album_artist(self, album_artist): """ Add album artist to db @param album_artist as string @param return ([album artist ids as int], [new as bool]) @commit needed """ album_artist_id = None new = False if album_artist: # Get album artist id, add it if missing album_artist_id = Lp().artists.get_id(album_artist) if album_artist_id is None: album_artist_id = Lp().artists.add(album_artist, format_artist_name( album_artist)) new = True return (album_artist_id, new)
def add_artists(self, artists, sortnames, mb_artist_ids=""): """ Add artists to db @param artists as [string] @param sortnames as [string] @param mb_artist_ids as [string] @return [int] @commit needed """ artist_ids = [] artistsplit = artists.split(";") sortsplit = sortnames.split(";") sortlen = len(sortsplit) mbidsplit = mb_artist_ids.split(";") mbidlen = len(mbidsplit) if len(artistsplit) != mbidlen: mbidsplit = [] mbidlen = 0 i = 0 for artist in artistsplit: artist = artist.strip() if artist != "": if i >= mbidlen or mbidsplit[i] == "": mbid = None else: mbid = mbidsplit[i].strip() # Get artist id, add it if missing artist_id = App().artists.get_id(artist, mbid) if i >= sortlen or sortsplit[i] == "": sortname = None else: sortname = sortsplit[i].strip() if artist_id is None: if sortname is None: sortname = format_artist_name(artist) artist_id = App().artists.add(artist, sortname, mbid) else: if sortname is not None: App().artists.set_sortname(artist_id, sortname) if mbid is not None: App().artists.set_mb_artist_id(artist_id, mbid) i += 1 artist_ids.append(artist_id) return artist_ids
def _on_scroll(self, adj): """ Show a popover with current letter @param adj as Gtk.Adjustement """ # Only show if scrolled window is huge if adj.get_upper() < adj.get_page_size() * 3: return if self._last_motion_event is None: return if self._timeout is not None: GLib.source_remove(self._timeout) self._timeout = None dest_row = self._view.get_dest_row_at_pos(self._last_motion_event.x, self._last_motion_event.y) if dest_row is None: return row = dest_row[0] if row is None: return row_iter = self._model.get_iter(row) if row_iter is None or self._model.get_value(row_iter, 0) < 0: return text = self._model.get_value(row_iter, 1) if text: if self._is_artists: text = format_artist_name(text) self._popover.set_text(" %s " % text[0].upper()) self._popover.set_relative_to(self) r = Gdk.Rectangle() r.x = self.get_allocated_width() r.y = self._last_motion_event.y r.width = 1 r.height = 1 self._popover.set_pointing_to(r) self._popover.set_position(Gtk.PositionType.RIGHT) self._popover.show()
def _search(self, cmd_args): """ Send stats about db @syntax search what value @param args as str @return msg as str """ msg = "" args = self._get_args(cmd_args) # Search for filters i = 0 artist = artist_id = None album = None genre = genre_id = None date = '' while i < len(args) - 1: if args[i].lower() == 'album': album = args[i+1] elif args[i].lower() == 'artist' or\ args[i].lower() == 'albumartist': artist = format_artist_name(args[i+1]) elif args[i].lower() == 'genre': genre = args[i+1] elif args[i].lower() == 'date': date = args[i+1] i += 2 try: year = int(date) except: year = Type.NONE if genre is not None: genre_id = Lp().genres.get_id(genre) if artist is not None: artist_id = Lp().artists.get_id(artist) for track_id in self.server.mpddb.get_tracks_ids(album, artist_id, genre_id, year): msg += self._string_for_track_id(track_id) return msg
def _count(self, cmd_args): """ Send lollypop current song @syntax count tag @param args as str @return msg as str """ args = self._get_args(cmd_args) # Search for filters i = 0 artist = artist_id = year = album = genre = genre_id = None while i < len(args) - 1: if args[i].lower() == 'album': album = args[i+1] elif args[i].lower() == 'artist': artist = format_artist_name(args[i+1]) elif args[i].lower() == 'genre': genre = args[i+1] elif args[i].lower() == 'date': date = args[i+1] i += 2 # Artist have albums with different dates so # we do not want None in year if artist_id is not None or album is not None: try: year = int(date) except: year = None else: year = Type.NONE if genre is not None: genre_id = Lp().genres.get_id(genre) if artist is not None: artist_id = Lp().artists.get_id(artist) (songs, playtime) = self.server.mpddb.count(album, artist_id, genre_id, year) msg = "songs: %s\nplaytime: %s\n" % (songs, playtime) return msg
def add_album_artists(self, artists): """ Add album artist to db @param artists as [string] @param return ([album artist ids as int], [new as bool]) @commit needed """ artist_ids = [] new_artist_ids = [] for artist in artists.split(';'): if artist != '': # Get album artist id, add it if missing artist_id = Lp().artists.get_id(artist) if artist_id is None: album_artist_id = Lp().artists.add( artist, format_artist_name(artist)) artist_ids.append(album_artist_id) new_artist_ids.append(album_artist_id) else: artist_ids.append(artist_id) return (artist_ids, new_artist_ids)
def add_artists(self, artists, album_artist): """ Add artists to db @param artists as [string] @param album artist as string @commit needed @param return ([artist ids as int], [new artist ids as int]) """ new_artist_ids = [] # Get all artist ids artist_ids = [] for word in artists.split(';'): artist = format_artist_name(word) # Get artist id, add it if missing artist_id = Lp().artists.get_id(artist) if artist_id is None: artist_id = Lp().artists.add(artist) if artist == album_artist: new_artist_ids.append(artist_id) artist_ids.append(artist_id) return (artist_ids, new_artist_ids)
def add_album_artists(self, artists): """ Add album artist to db @param artists as [string] @param return ([album artist ids as int], [new as bool]) @commit needed """ artist_ids = [] new_artist_ids = [] for artist in artists.split(';'): if artist != '': # Get album artist id, add it if missing artist_id = Lp().artists.get_id(artist) if artist_id is None: album_artist_id = Lp().artists.add(artist, format_artist_name( artist)) artist_ids.append(album_artist_id) new_artist_ids.append(album_artist_id) else: artist_ids.append(artist_id) return (artist_ids, new_artist_ids)
def add_artists(self, artists, album_artist, sql): """ Add artists to db @param artists as [string] @param album artist as string @param sql as sqlite cursor @commit needed @param return ([artist ids as int], [new artist ids as int]) """ new_artist_ids = [] # Get all artist ids artist_ids = [] for word in artists.split(';'): artist = format_artist_name(word) # Get artist id, add it if missing artist_id = Lp.artists.get_id(artist, sql) if artist_id is None: Lp.artists.add(artist, sql) artist_id = Lp.artists.get_id(artist, sql) if artist == album_artist: new_artist_ids.append(artist_id) artist_ids.append(artist_id) return (artist_ids, new_artist_ids)
def _add2db(self, filepath, mtime, infos, sql): self._new_artist = False self._new_genre = False path = os.path.dirname(filepath) tags = infos.get_tags() (exist, title) = tags.get_string_index('title', 0) if not exist: title = os.path.basename(filepath) (exist, artists) = tags.get_string_index('artist', 0) if not exist: artists = _("Unknown") artists = "" size = tags.get_tag_size('artist') if size == 0: artists = _("Unknown") else: for i in range(0, size): (exist, artist) = tags.get_string_index('artist', i) artists += artist if i < size-1: artists += ";" (exist, aartist) = tags.get_string_index('album-artist', 0) if not exist: aartist = None (exist, album) = tags.get_string_index('album', 0) if not exist: album = _("Unknown") genres = "" size = tags.get_tag_size('genre') if size == 0: genres = _("Unknown") else: for i in range(0, size): (exist, genre) = tags.get_string_index('genre', i) genres += genre if i < size-1: genres += ";" (exist, discnumber) = tags.get_uint_index('disc-number', 0) if not exist: discnumber = 0 (exist, tracknumber) = tags.get_uint_index('track-number', 0) if not exist: tracknumber = 0 (exist, datetime) = tags.get_date_time('datetime') if exist: year = datetime.get_year() else: year = None length = infos.get_duration()/1000000000 # Get all artist ids artist_ids = [] for word in artists.split(';'): artist = format_artist_name(word) # Get artist id, add it if missing artist_id = Objects.artists.get_id(artist, sql) if artist_id is None: Objects.artists.add(artist, sql) artist_id = Objects.artists.get_id(artist, sql) if artist == aartist: self._new_artist = True artist_ids.append(artist_id) if aartist: aartist = format_artist_name(aartist) # Get aartist id, add it if missing aartist_id = Objects.artists.get_id(aartist, sql) if aartist_id is None: Objects.artists.add(aartist, sql) aartist_id = Objects.artists.get_id(aartist, sql) self._new_artist = True else: aartist_id = Navigation.COMPILATIONS # Get all genre ids genre_ids = [] for genre in genres.split(';'): # Get genre id, add genre if missing genre_id = Objects.genres.get_id(genre, sql) if genre_id is None: Objects.genres.add(genre, sql) genre_id = Objects.genres.get_id(genre, sql) self._new_genre = True genre_ids.append(genre_id) album_id = Objects.albums.get_id(album, aartist_id, sql) if album_id is None: Objects.albums.add(album, aartist_id, path, 0, sql) album_id = Objects.albums.get_id(album, aartist_id, sql) for genre_id in genre_ids: Objects.albums.add_genre(album_id, genre_id, sql) # Now we have our album id, check if path doesn't change if Objects.albums.get_path(album_id, sql) != path: Objects.albums.set_path(album_id, path, sql) # Add track to db Objects.tracks.add(title, filepath, length, tracknumber, discnumber, album_id, year, mtime, sql) # Update year for album year = Objects.albums.get_year_from_tracks(album_id, sql) Objects.albums.set_year(album_id, year, sql) # Set artists/genres for track track_id = Objects.tracks.get_id_by_path(filepath, sql) for artist_id in artist_ids: Objects.tracks.add_artist(track_id, artist_id, sql) for genre_id in genre_ids: Objects.tracks.add_genre(track_id, genre_id, sql) if self._new_genre or self._new_artist: sql.commit() if self._new_genre: GLib.idle_add(self.emit, "genre-update", genre_id) if self._new_artist: GLib.idle_add(self.emit, "artist-update", aartist_id, album_id) return track_id
def _add2db(self, filepath, mtime, tag, sql): compilation = False path = os.path.dirname(filepath) keys = tag.keys() if "title" in keys: title = tag["title"][0] else: title = os.path.basename(filepath) if "artist" in keys: artist = format_artist_name(tag["artist"][0]) else: artist = "Unknown" if "performer" in keys: performer = format_artist_name(tag["performer"][0]) else: performer = None if "album" in keys: album = tag["album"][0] else: album = "Unknown" if "genre" in keys: genre = tag["genre"][0] else: genre = "Unknown" length = int(tag.info.length) if "discnumber" in keys: string = tag["discnumber"][0] if "/" in string: index = string.find("/") discnumber = int(string[0:index]) else: try: discnumber = int(string) except: discnumber = 0 else: discnumber = 0 if "tracknumber" in keys: string = tag["tracknumber"][0] if "/" in string: index = string.find("/") tracknumber = int(string[0:index]) else: try: tracknumber = int(string) except: tracknumber = 0 else: tracknumber = 0 if "date" in keys: try: string = tag["date"][0] if "-" in string: index = string.find("-") year = int(string[0:index]) else: year = int(string) except: year = 0 else: year = 0 # Get artist id, add it if missing artist_id = Objects["artists"].get_id(artist, sql) if artist_id == COMPILATIONS: Objects["artists"].add(artist, sql) artist_id = Objects["artists"].get_id(artist, sql) if performer: # Get performer id, add it if missing performer_id = Objects["artists"].get_id(performer, sql) if performer_id == COMPILATIONS: Objects["artists"].add(performer, sql) performer_id = Objects["artists"].get_id(performer, sql) else: performer_id = COMPILATIONS # Get genre id, add genre if missing genre_id = Objects["genres"].get_id(genre, sql) if genre_id == -1: Objects["genres"].add(genre, sql) genre_id = Objects["genres"].get_id(genre, sql) # # Here we search an existing album for this track # # Get albums with this name from this artist/performer if performer_id != COMPILATIONS: album_id = Objects["albums"].get_id(album, performer_id, genre_id, sql) else: album_id = Objects["albums"].get_id(album, artist_id, genre_id, sql) # Track can go in a compilation if performer_id == COMPILATIONS and album_id == -1: # Look if we find a compilation for this name: album_id = Objects["albums"].get_id(album, COMPILATIONS, genre_id, sql) if album_id == -1: # Search for others album with same name for album_id_ in Objects["albums"].get_id(album, None, genre_id, sql): # there is no performer tag, so use it if len(Objects["albums"].get_performers_id(album_id_, sql)) == 0: album_id = album_id_ # We need to check if it's an album without performers or # a compilation ie different artists without performers for track_id_ in Objects["albums"].get_tracks(album_id, sql): artist_id_ = Objects["tracks"].get_artist_id(track_id_, sql) if artist_id_ != artist_id: # Mark it as a compilation Objects["albums"].set_artist_id(album_id, COMPILATIONS, sql) break popularity = 0 if path in self._popularities: popularity = self._popularities[path] # Get a new album if none found if album_id == -1: if performer_id != COMPILATIONS: Objects["albums"].add(album, performer_id, genre_id, year, path, popularity, sql) album_id = Objects["albums"].get_id(album, performer_id, genre_id, sql) else: Objects["albums"].add(album, artist_id, genre_id, year, path, popularity, sql) album_id = Objects["albums"].get_id(album, artist_id, genre_id, sql) # Now we have our album id, check if path doesn't change if Objects["albums"].get_path(album_id, sql) != path: Objects["albums"].set_path(album_id, path, sql) # Add track to db Objects["tracks"].add(title, filepath, length, tracknumber, discnumber, artist_id, performer_id, album_id, mtime, sql)
def _add2db(self, filepath, mtime, infos, outside, sql): self._new_artists = [] self._new_genres = [] path = os.path.dirname(filepath) tags = infos.get_tags() (exist, title) = tags.get_string_index('title', 0) if not exist: title = os.path.basename(filepath) (exist, artists) = tags.get_string_index('artist', 0) if not exist: artists = _("Unknown") artists = "" size = tags.get_tag_size('artist') if size == 0: artists = _("Unknown") else: for i in range(0, size): (exist, artist) = tags.get_string_index('artist', i) artists += artist if i < size-1: artists += ";" (exist, aartist) = tags.get_string_index('album-artist', 0) if not exist: aartist = None (exist, album) = tags.get_string_index('album', 0) if not exist: album = _("Unknown") genres = "" size = tags.get_tag_size('genre') if size == 0: genres = _("Unknown") else: for i in range(0, size): (exist, genre) = tags.get_string_index('genre', i) genres += genre if i < size-1: genres += ";" (exist, discnumber) = tags.get_uint_index('album-disc-number', 0) if not exist: discnumber = 0 (exist, tracknumber) = tags.get_uint_index('track-number', 0) if not exist: tracknumber = 0 (exist, datetime) = tags.get_date_time('datetime') if exist: year = datetime.get_year() else: year = None length = infos.get_duration()/1000000000 # Get all artist ids artist_ids = [] for word in artists.split(';'): artist = format_artist_name(word) # Get artist id, add it if missing artist_id = Objects.artists.get_id(artist, sql) if artist_id is None: Objects.artists.add(artist, outside, sql) artist_id = Objects.artists.get_id(artist, sql) if artist == aartist: self._new_artists.append(artist_id) artist_ids.append(artist_id) if aartist: aartist = format_artist_name(aartist) # Get aartist id, add it if missing aartist_id = Objects.artists.get_id(aartist, sql) if aartist_id is None: Objects.artists.add(aartist, outside, sql) aartist_id = Objects.artists.get_id(aartist, sql) self._new_artists.append(aartist_id) else: aartist_id = Navigation.COMPILATIONS # Get all genre ids genre_ids = [] for genre in genres.split(';'): # Get genre id, add genre if missing genre_id = Objects.genres.get_id(genre, sql) if genre_id is None: Objects.genres.add(genre, outside, sql) genre_id = Objects.genres.get_id(genre, sql) self._new_genres.append(genre_id) genre_ids.append(genre_id) album_id = Objects.albums.get_id(album, aartist_id, sql) if album_id is None: # If db was empty on scan, # use file modification time to get recents if self._is_empty: mtime = int(os.path.getmtime(filepath)) # Use current time else: mtime = int(time()) Objects.albums.add(album, aartist_id, path, 0, outside, mtime, sql) album_id = Objects.albums.get_id(album, aartist_id, sql) for genre_id in genre_ids: Objects.albums.add_genre(album_id, genre_id, outside, sql) # Now we have our album id, check if path doesn't change if Objects.albums.get_path(album_id, sql) != path and not outside: Objects.albums.set_path(album_id, path, sql) # Add track to db Objects.tracks.add(title, filepath, length, tracknumber, discnumber, album_id, year, mtime, outside, sql) # Update year for album year = Objects.albums.get_year_from_tracks(album_id, sql) Objects.albums.set_year(album_id, year, sql) # Set artists/genres for track track_id = Objects.tracks.get_id_by_path(filepath, sql) for artist_id in artist_ids: Objects.tracks.add_artist(track_id, artist_id, outside, sql) for genre_id in genre_ids: Objects.tracks.add_genre(track_id, genre_id, outside, sql) # Notify about new artists/genres if self._new_genres or self._new_artists: sql.commit() for genre_id in self._new_genres: GLib.idle_add(self.emit, "genre-update", genre_id) for artist_id in self._new_artists: GLib.idle_add(self.emit, "artist-update", artist_id, album_id) return track_id
def _list(self, cmd_args): """ List objects @syntax list what [filter value...] or list album artist_name @param args as str @return msg as str """ msg = "" args = self._get_args(cmd_args) # Search for filters if len(args) == 2: i = 0 else: i = 1 artist = artist_id = None album = None genre = genre_id = None date = '' while i < len(args) - 1: print(args[i], i) if args[i].lower() == 'album': if i % 2: album = args[i+1] else: artist = format_artist_name(args[i+1]) elif args[i].lower() == 'artist' or\ args[i].lower() == 'albumartist': artist = format_artist_name(args[i+1]) elif args[i].lower() == 'genre': genre = args[i+1] elif args[i].lower() == 'date': date = args[i+1] i += 2 try: year = int(date) except: year = Type.NONE if genre is not None: genre_id = Lp().genres.get_id(genre) if artist is not None: artist_id = Lp().artists.get_id(artist) if args[0].lower() == 'file': for path in self.server.mpddb.get_tracks_paths(album, artist_id, genre_id, year): msg += "File: "+path+"\n" if args[0].lower() == 'album': print(artist_id) for album in self.server.mpddb.get_albums_names(artist_id, genre_id, year): msg += "Album: "+album+"\n" elif args[0].lower() == 'artist': for artist in self.server.mpddb.get_artists_names(genre_id): msg += "Artist: "+translate_artist_name(artist)+"\n" elif args[0].lower() == 'genre': results = Lp().genres.get_names() for name in results: msg += "Genre: "+name+"\n" elif args[0].lower() == 'date': for year in self.server.mpddb.get_albums_years(album, artist_id, genre_id): msg += "Date: "+str(year)+"\n" return msg