From a87517a0b385f1a68dd80e7dabf7843955c95ab9 Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Sun, 30 Jun 2019 11:12:05 +0100 Subject: Style fixes --- models/album.py | 66 ++++++----- models/artist.py | 63 ++++++----- models/base.py | 1 + models/track.py | 337 ++++++++++++++++++++++++++++++++----------------------- 4 files changed, 272 insertions(+), 195 deletions(-) (limited to 'models') diff --git a/models/album.py b/models/album.py index d55fb88..b7c3548 100644 --- a/models/album.py +++ b/models/album.py @@ -10,7 +10,7 @@ class Album(BaseModel): if id is not None: for row in self._db.execute("SELECT * FROM album WHERE id = ?", - (id,)): + (id, )): setattr(self, "id", id) setattr(self, "name", row[1]) setattr(self, "date", row[2]) @@ -24,13 +24,13 @@ class Album(BaseModel): with self._db.conn: delete_album = "DELETE FROM album WHERE id = ?" - self._db.execute(delete_album, (self.id,)) + self._db.execute(delete_album, (self.id, )) delete_track_rel = "DELETE FROM album_track WHERE album_id = ?" - self._db.execute(delete_track_rel, (self.id,)) + self._db.execute(delete_track_rel, (self.id, )) delete_artist_rel = "DELETE FROM album_artist WHERE album_id = ?" - self._db.execute(delete_artist_rel, (self.id,)) + self._db.execute(delete_artist_rel, (self.id, )) return True @@ -49,13 +49,16 @@ class Album(BaseModel): if not hasattr(self, "_artists"): setattr(self, "_artists", []) - for row in self._db.execute("SELECT artist.* FROM artist INNER " - "JOIN album_artist ON artist.id = " - "album_artist.artist_id WHERE " - "album_id = ? ORDER BY name ASC", - (self.id,)): - artist = Artist(id=row[0], db=self._db, name=row[1], - sortname=row[2], musicbrainz_artistid=row[3]) + for row in self._db.execute( + "SELECT artist.* FROM artist INNER " + "JOIN album_artist ON artist.id = " + "album_artist.artist_id WHERE " + "album_id = ? ORDER BY name ASC", (self.id, )): + artist = Artist(id=row[0], + db=self._db, + name=row[1], + sortname=row[2], + musicbrainz_artistid=row[3]) self._artists.append(artist) return self._artists @@ -67,15 +70,18 @@ class Album(BaseModel): if not hasattr(self, "_tracks"): setattr(self, "_tracks", []) - for row in self._db.execute("SELECT track.* FROM track INNER " - "JOIN album_track ON track.id = " - "album_track.track_id WHERE " - "album_id = ? ORDER BY tracknumber " - "ASC", (self.id,)): + for row in self._db.execute( + "SELECT track.* FROM track INNER " + "JOIN album_track ON track.id = " + "album_track.track_id WHERE " + "album_id = ? ORDER BY tracknumber " + "ASC", (self.id, )): - track = Track(id=row["id"], db=self._db, + track = Track(id=row["id"], + db=self._db, tracknumber=row["tracknumber"], - name=row["name"], grouping=row["grouping"], + name=row["name"], + grouping=row["grouping"], filename=row["filename"]) self._tracks.append(track) @@ -135,14 +141,19 @@ class Album(BaseModel): for row in result: albums.append( - Album(id=row["id"], db=database, name=row["name"], - date=row["date"]) - ) + Album(id=row["id"], + db=database, + name=row["name"], + date=row["date"])) return albums @classmethod - def all(cls, database, order="album.id", direction="ASC", limit=None, + def all(cls, + database, + order="album.id", + direction="ASC", + limit=None, offset=None): albums = [] @@ -153,15 +164,16 @@ class Album(BaseModel): direction) if limit is not None and offset is not None: - select_string = " ".join((select_string, - "LIMIT %s OFFSET %s" % (limit, offset))) + select_string = " ".join( + (select_string, "LIMIT %s OFFSET %s" % (limit, offset))) result = database.execute(select_string) for row in result: albums.append( - Album(id=row["id"], db=database, name=row["name"], - date=row["date"]) - ) + Album(id=row["id"], + db=database, + name=row["name"], + date=row["date"])) return albums diff --git a/models/artist.py b/models/artist.py index dada665..e91e66e 100644 --- a/models/artist.py +++ b/models/artist.py @@ -3,13 +3,12 @@ from models.base import BaseModel class Artist(BaseModel): - def __init__(self, db, id=None, **kwargs): self._db = db if id is not None: for row in self._db.execute("SELECT * FROM artist WHERE id = ?", - (id,)): + (id, )): for key in ["id", "name", "sortname", "musicbrainz_artistid"]: setattr(self, key, row[key]) else: @@ -22,13 +21,13 @@ class Artist(BaseModel): with self._db.conn: delete_artist = "DELETE FROM artist WHERE id = ?" - self._db.execute(delete_artist, (self.id,)) + self._db.execute(delete_artist, (self.id, )) delete_track_rel = "DELETE FROM artist_track WHERE artist_id = ?" - self._db.execute(delete_track_rel, (self.id,)) + self._db.execute(delete_track_rel, (self.id, )) delete_album_rel = "DELETE FROM album_artist WHERE artist_id = ?" - self._db.execute(delete_album_rel, (self.id,)) + self._db.execute(delete_album_rel, (self.id, )) return True @@ -47,14 +46,16 @@ class Artist(BaseModel): if not hasattr(self, "_tracks"): setattr(self, "_tracks", []) - for row in self._db.execute("SELECT track.* FROM track INNER " - "JOIN artist_track ON track.id = " - "artist_track.track_id WHERE " - "artist_id = ? ORDER BY name ASC", - (self.id,)): + for row in self._db.execute( + "SELECT track.* FROM track INNER " + "JOIN artist_track ON track.id = " + "artist_track.track_id WHERE " + "artist_id = ? ORDER BY name ASC", (self.id, )): - track = Track(id=row["id"], db=self._db, - tracknumber=row["tracknumber"], name=row["name"], + track = Track(id=row["id"], + db=self._db, + tracknumber=row["tracknumber"], + name=row["name"], grouping=row["grouping"], filename=row["filename"]) self._tracks.append(track) @@ -68,12 +69,14 @@ class Artist(BaseModel): if not hasattr(self, "_albums"): setattr(self, "_albums", []) - for row in self._db.execute("SELECT album.* FROM album INNER " - "JOIN album_artist ON album.id = " - "album_artist.album_id WHERE " - "artist_id = ? ORDER BY date ASC", - (self.id,)): - album = Album(id=row["id"], db=self._db, name=row["name"], + for row in self._db.execute( + "SELECT album.* FROM album INNER " + "JOIN album_artist ON album.id = " + "album_artist.album_id WHERE " + "artist_id = ? ORDER BY date ASC", (self.id, )): + album = Album(id=row["id"], + db=self._db, + name=row["name"], date=row["date"]) self._albums.append(album) @@ -126,15 +129,20 @@ class Artist(BaseModel): for row in result: artists.append( - Artist(id=row["id"], db=database, name=row["name"], + Artist(id=row["id"], + db=database, + name=row["name"], sortname=row["sortname"], - musicbrainz_artistid=row["musicbrainz_artistid"]) - ) + musicbrainz_artistid=row["musicbrainz_artistid"])) return artists @classmethod - def all(cls, database, order="sortname", direction="ASC", limit=None, + def all(cls, + database, + order="sortname", + direction="ASC", + limit=None, offset=None): artists = [] @@ -143,16 +151,17 @@ class Artist(BaseModel): direction) if limit is not None and offset is not None: - select_string = " ".join((select_string, - "LIMIT %s OFFSET %s" % (limit, offset))) + select_string = " ".join( + (select_string, "LIMIT %s OFFSET %s" % (limit, offset))) result = database.execute(select_string) for row in result: artists.append( - Artist(id=row["id"], db=database, name=row["name"], + Artist(id=row["id"], + db=database, + name=row["name"], sortname=row["sortname"], - musicbrainz_artistid=row["musicbrainz_artistid"]) - ) + musicbrainz_artistid=row["musicbrainz_artistid"])) return artists diff --git a/models/base.py b/models/base.py index 8a6fc47..9ccec08 100644 --- a/models/base.py +++ b/models/base.py @@ -1,6 +1,7 @@ """Implements a base model for other models to inherit.""" from six import iteritems + class BaseModel(object): """BaseModel is meant to be inherited by other models.""" diff --git a/models/track.py b/models/track.py index 2a92558..81c60fc 100644 --- a/models/track.py +++ b/models/track.py @@ -6,12 +6,10 @@ from models.artist import Artist from models.album import Album from models.base import BaseModel - logging.basicConfig(format="%(asctime)s %(message)s", level=logging.DEBUG) class Track(BaseModel): - def __init__(self, db, id=None, **kwargs): self._db = db @@ -19,9 +17,10 @@ class Track(BaseModel): if id is not None: for row in self._db.execute("SELECT * FROM track WHERE id = ?", - (id,)): - for key in ["id", "tracknumber", "name", "grouping", - "filename"]: + (id, )): + for key in [ + "id", "tracknumber", "name", "grouping", "filename" + ]: setattr(self, key, row[key]) self.__data[key] = row[key] else: @@ -33,7 +32,7 @@ class Track(BaseModel): delete_sql = "DELETE FROM track WHERE id = ?" with self._db.conn: - self._db.execute(delete_sql, (self.id,)) + self._db.execute(delete_sql, (self.id, )) # If there is an old album, remove it if it no longer has any # tracks @@ -46,7 +45,7 @@ class Track(BaseModel): if old_album: self._db.execute("DELETE FROM album_track WHERE track_id = ?", - (self.id,)) + (self.id, )) if not old_album.tracks: old_album.delete() @@ -60,8 +59,9 @@ class Track(BaseModel): old_artists = self.artists for old_artist in old_artists: - self._db.execute("DELETE FROM artist_track WHERE track_id = " - "?", (self.id,)) + self._db.execute( + "DELETE FROM artist_track WHERE track_id = " + "?", (self.id, )) if not old_artist.tracks: old_artist.delete() @@ -72,7 +72,6 @@ class Track(BaseModel): def db(self): return self._db - @db.setter def db(self, db): self._db = db @@ -82,13 +81,17 @@ class Track(BaseModel): if not hasattr(self, "_album"): setattr(self, "_album", None) - for row in self._db.execute("SELECT album.* FROM album INNER " - "JOIN album_track ON album.id = " - "album_track.album_id WHERE " - "track_id = ? LIMIT 1", (self.id,)): - setattr(self, "_album", Album(id=row["id"], db=self._db, - name=row["name"], - date=row["date"])) + for row in self._db.execute( + "SELECT album.* FROM album INNER " + "JOIN album_track ON album.id = " + "album_track.album_id WHERE " + "track_id = ? LIMIT 1", (self.id, )): + setattr( + self, "_album", + Album(id=row["id"], + db=self._db, + name=row["name"], + date=row["date"])) return self._album @@ -98,16 +101,17 @@ class Track(BaseModel): cursor = self._db.cursor() setattr(self, "_artists", []) - for row in cursor.execute("SELECT artist.* FROM artist INNER JOIN " - "artist_track ON artist.id = " - "artist_track.artist_id WHERE " - "artist_track.track_id = ?", - (self.id,)): - self._artists.append(Artist(id=row["id"], db=self._db, - name=row["name"], - sortname=row["sortname"], - musicbrainz_artistid=row[ - "musicbrainz_artistid"])) + for row in cursor.execute( + "SELECT artist.* FROM artist INNER JOIN " + "artist_track ON artist.id = " + "artist_track.artist_id WHERE " + "artist_track.track_id = ?", (self.id, )): + self._artists.append( + Artist(id=row["id"], + db=self._db, + name=row["name"], + sortname=row["sortname"], + musicbrainz_artistid=row["musicbrainz_artistid"])) return self._artists @@ -149,20 +153,22 @@ class Track(BaseModel): rows = None if musicbrainz_artistid: - rows = c.execute("SELECT * FROM artist WHERE " - "musicbrainz_artistid = ?", - (musicbrainz_artistid,)) + rows = c.execute( + "SELECT * FROM artist WHERE " + "musicbrainz_artistid = ?", (musicbrainz_artistid, )) else: rows = c.execute("SELECT * FROM artist WHERE name = ?", - (artist_name,)) + (artist_name, )) row = rows.fetchone() if row: - artist = Artist(id=row["id"], db=self._db, name=row["name"], - sortname=row["sortname"], - musicbrainz_artistid=row[ - "musicbrainz_artistid"]) + artist = Artist( + id=row["id"], + db=self._db, + name=row["name"], + sortname=row["sortname"], + musicbrainz_artistid=row["musicbrainz_artistid"]) if artist.name != artist_name: c.execute("UPDATE artist SET name = ? WHERE id = ?", @@ -175,15 +181,16 @@ class Track(BaseModel): artist.sortname = artistsort else: - c.execute("INSERT INTO artist (name, sortname, " - "musicbrainz_artistid) VALUES(?, ?, ?)", - (artist_name, artistsort, musicbrainz_artistid)) + c.execute( + "INSERT INTO artist (name, sortname, " + "musicbrainz_artistid) VALUES(?, ?, ?)", + (artist_name, artistsort, musicbrainz_artistid)) - artist = Artist( - id=c.lastrowid, db=self._db, name=artist_name, - sortname=artistsort, - musicbrainz_artistid=musicbrainz_artistid - ) + artist = Artist(id=c.lastrowid, + db=self._db, + name=artist_name, + sortname=artistsort, + musicbrainz_artistid=musicbrainz_artistid) i += 1 @@ -211,40 +218,48 @@ class Track(BaseModel): if mb_albumid: rows = c.execute( "SELECT * FROM album WHERE musicbrainz_albumid = ?", - (mb_albumid,) - ) + (mb_albumid, )) row = rows.fetchone() if row: - album = Album(id=row["id"], db=self._db, name=row["name"], + album = Album(id=row["id"], + db=self._db, + name=row["name"], date=row["date"], musicbrainz_albumid=row["musicbrainz_albumid"]) else: - c.execute("INSERT INTO album (name, `date`, " - "musicbrainz_albumid) VALUES (?, ?, ?)", - (album_name, album_date, mb_albumid)) + c.execute( + "INSERT INTO album (name, `date`, " + "musicbrainz_albumid) VALUES (?, ?, ?)", + (album_name, album_date, mb_albumid)) - album = Album(id=c.lastrowid, db=self._db, name=album_name, - date=album_date, musicbrainz_albumid=mb_albumid) + album = Album(id=c.lastrowid, + db=self._db, + name=album_name, + date=album_date, + musicbrainz_albumid=mb_albumid) elif album_name: rows = c.execute( "SELECT album.* FROM album INNER JOIN album_artist ON " "album_artist.album_id = album.id WHERE album.name = ? " - "AND artist_id = ?", (album_name, artist.id) - ) + "AND artist_id = ?", (album_name, artist.id)) row = rows.fetchone() if row: - album = Album(id=row["id"], db=self._db, name=row["name"], + album = Album(id=row["id"], + db=self._db, + name=row["name"], date=row["date"], musicbrainz_albumid=row["musicbrainz_albumid"]) else: c.execute("INSERT INTO album (name, `date`) VALUES (?, ?)", (album_name, album_date)) - album = Album(id=c.lastrowid, db=self._db, name=album_name, + album = Album(id=c.lastrowid, + db=self._db, + name=album_name, date=album_date) if album: @@ -277,9 +292,10 @@ class Track(BaseModel): except KeyError: pass - c.execute("UPDATE track SET tracknumber = ?, name = ?, grouping = ? " - "WHERE id = ?", (track_number, track_name, track_grouping, - self.id)) + c.execute( + "UPDATE track SET tracknumber = ?, name = ?, grouping = ? " + "WHERE id = ?", + (track_number, track_name, track_grouping, self.id)) # If there is an old album, remove it if it no longer has any tracks try: @@ -290,7 +306,7 @@ class Track(BaseModel): old_album = self.album if old_album: c.execute("DELETE FROM album_track WHERE track_id = ?", - (self.id,)) + (self.id, )) # If there are old artists, remove them if they no longer have # any tracks @@ -302,12 +318,13 @@ class Track(BaseModel): for old_artist in old_artists: c.execute("DELETE FROM artist_track WHERE track_id = ?", - (self.id,)) + (self.id, )) if album: try: - c.execute("INSERT INTO album_track (album_id, track_id) " - "VALUES(?, ?)", (album.id, self.id)) + c.execute( + "INSERT INTO album_track (album_id, track_id) " + "VALUES(?, ?)", (album.id, self.id)) except sqlite3.IntegrityError: pass @@ -318,8 +335,9 @@ class Track(BaseModel): for artist in artists: try: - c.execute("INSERT INTO artist_track (artist_id, track_id) " - "VALUES(?, ?)", (artist.id, self.id)) + c.execute( + "INSERT INTO artist_track (artist_id, track_id) " + "VALUES(?, ?)", (artist.id, self.id)) except sqlite3.IntegrityError: pass @@ -395,10 +413,12 @@ class Track(BaseModel): for row in result: tracks.append( - Track(id=row["id"], db=database, tracknumber=row["tracknumber"], - name=row["name"], grouping=row["grouping"], - filename=row["filename"]) - ) + Track(id=row["id"], + db=database, + tracknumber=row["tracknumber"], + name=row["name"], + grouping=row["grouping"], + filename=row["filename"])) return tracks @@ -406,11 +426,15 @@ class Track(BaseModel): def find_by_path(cls, path, database): track = None - for row in database.execute("SELECT * FROM track WHERE filename = ? " - "LIMIT 1", (path,)): - track = Track(id=row["id"], db=database, - tracknumber=row["tracknumber"], name=row["name"], - grouping=row["grouping"], filename=row["filename"]) + for row in database.execute( + "SELECT * FROM track WHERE filename = ? " + "LIMIT 1", (path, )): + track = Track(id=row["id"], + db=database, + tracknumber=row["tracknumber"], + name=row["name"], + grouping=row["grouping"], + filename=row["filename"]) return track @@ -451,50 +475,52 @@ class Track(BaseModel): rows = None row = None if musicbrainz_artistid: - rows = c.execute("SELECT * FROM artist WHERE " - "musicbrainz_artistid = ?", - (musicbrainz_artistid,)) + rows = c.execute( + "SELECT * FROM artist WHERE " + "musicbrainz_artistid = ?", (musicbrainz_artistid, )) row = rows.fetchone() if not row: - rows = c.execute("SELECT * FROM artist WHERE name = ? " - "AND musicbrainz_artistid IS NULL", - (artist_name,)) + rows = c.execute( + "SELECT * FROM artist WHERE name = ? " + "AND musicbrainz_artistid IS NULL", (artist_name, )) row = rows.fetchone() if not row: rows = c.execute("SELECT * FROM artist WHERE name = ?", - (artist_name,)) + (artist_name, )) row = rows.fetchone() if row: - artist = Artist(id=row["id"], db=database, name=row["name"], - sortname=row["sortname"], - musicbrainz_artistid=row[ - "musicbrainz_artistid"]) - - if (musicbrainz_artistid and - (not hasattr(artist, "musicbrainz_artistid") or - not artist.musicbrainz_artistid)): - c.execute("UPDATE artist SET musicbrainz_artistid = ? " - "WHERE id = ?", - (musicbrainz_artistid, artist.id)) + artist = Artist( + id=row["id"], + db=database, + name=row["name"], + sortname=row["sortname"], + musicbrainz_artistid=row["musicbrainz_artistid"]) + + if (musicbrainz_artistid + and (not hasattr(artist, "musicbrainz_artistid") + or not artist.musicbrainz_artistid)): + c.execute( + "UPDATE artist SET musicbrainz_artistid = ? " + "WHERE id = ?", (musicbrainz_artistid, artist.id)) if (artistsort and - (not hasattr(artist, "sortname") or - not artist.sortname)): + (not hasattr(artist, "sortname") or not artist.sortname)): c.execute("UPDATE artist SET sortname = ? WHERE id = ?", (artistsort, artist.id)) else: - c.execute("INSERT INTO artist (name, sortname, " - "musicbrainz_artistid) VALUES(?, ?, ?)", - (artist_name, artistsort, musicbrainz_artistid)) + c.execute( + "INSERT INTO artist (name, sortname, " + "musicbrainz_artistid) VALUES(?, ?, ?)", + (artist_name, artistsort, musicbrainz_artistid)) - artist = Artist( - id=c.lastrowid, db=database, name=artist_name, - sortname=artistsort, - musicbrainz_artistid=musicbrainz_artistid - ) + artist = Artist(id=c.lastrowid, + db=database, + name=artist_name, + sortname=artistsort, + musicbrainz_artistid=musicbrainz_artistid) i += 1 @@ -520,46 +546,59 @@ class Track(BaseModel): pass if mb_albumid: - rows = c.execute("SELECT * FROM album WHERE " - "musicbrainz_albumid = ?", (mb_albumid,)) + rows = c.execute( + "SELECT * FROM album WHERE " + "musicbrainz_albumid = ?", (mb_albumid, )) row = rows.fetchone() if row: - album = Album(id=row["id"], db=database, name=row["name"], - date=row["date"], musicbrainz_albumid=row[ - "musicbrainz_albumid"]) + album = Album(id=row["id"], + db=database, + name=row["name"], + date=row["date"], + musicbrainz_albumid=row["musicbrainz_albumid"]) else: - c.execute("INSERT INTO album (name, `date`, " - "musicbrainz_albumid) VALUES (?, ?, ?)", - (album_name, album_date, mb_albumid)) + c.execute( + "INSERT INTO album (name, `date`, " + "musicbrainz_albumid) VALUES (?, ?, ?)", + (album_name, album_date, mb_albumid)) - album = Album(id=c.lastrowid, db=database, name=album_name, - date=album_date, musicbrainz_albumid=mb_albumid) + album = Album(id=c.lastrowid, + db=database, + name=album_name, + date=album_date, + musicbrainz_albumid=mb_albumid) elif album_name: for artist in artists: - rows = c.execute("SELECT album.* FROM album INNER JOIN " - "album_artist ON album_artist.album_id = " - "album.id WHERE album.name = ? AND " - "artist_id = ?", (album_name, artist.id)) + rows = c.execute( + "SELECT album.* FROM album INNER JOIN " + "album_artist ON album_artist.album_id = " + "album.id WHERE album.name = ? AND " + "artist_id = ?", (album_name, artist.id)) row = rows.fetchone() if row: - album = Album(id=row["id"], db=database, name=row["name"], + album = Album(id=row["id"], + db=database, + name=row["name"], date=row["date"]) else: c.execute("INSERT INTO album (name, `date`) VALUES(?, ?)", (album_name, album_date)) - album = Album(id=c.lastrowid, db=database, name=album_name, + album = Album(id=c.lastrowid, + db=database, + name=album_name, date=album_date) for artist in artists: if album: try: - c.execute("INSERT INTO album_artist (artist_id, album_id) " - "VALUES(?, ?)", (artist.id, album.id)) + c.execute( + "INSERT INTO album_artist (artist_id, album_id) " + "VALUES(?, ?)", (artist.id, album.id)) except sqlite3.IntegrityError: pass @@ -580,33 +619,42 @@ class Track(BaseModel): pass track = None - rows = c.execute("SELECT * FROM track WHERE filename = ?", (filename,)) + rows = c.execute("SELECT * FROM track WHERE filename = ?", + (filename, )) row = rows.fetchone() if row: - track = Track(id=row["id"], db=database, - tracknumber=row["tracknumber"], name=row["name"], - grouping=row["grouping"], filename=row["filename"]) + track = Track(id=row["id"], + db=database, + tracknumber=row["tracknumber"], + name=row["name"], + grouping=row["grouping"], + filename=row["filename"]) else: - c.execute("INSERT INTO track (tracknumber, name, grouping, " - "filename) VALUES(?, ?, ?, ?)", - (track_number, track_name, track_grouping, - filename)) - - track = Track(id=c.lastrowid, db=database, tracknumber=track_number, - name=track_name, grouping=track_grouping, + c.execute( + "INSERT INTO track (tracknumber, name, grouping, " + "filename) VALUES(?, ?, ?, ?)", + (track_number, track_name, track_grouping, filename)) + + track = Track(id=c.lastrowid, + db=database, + tracknumber=track_number, + name=track_name, + grouping=track_grouping, filename=filename) if album: try: - c.execute("INSERT INTO album_track (album_id, track_id) " - "VALUES(?,?)", (album.id, track.id)) + c.execute( + "INSERT INTO album_track (album_id, track_id) " + "VALUES(?,?)", (album.id, track.id)) except sqlite3.IntegrityError: pass for artist in artists: try: - c.execute("INSERT INTO artist_track (artist_id, track_id) " - "VALUES(?, ?)", (artist.id, track.id)) + c.execute( + "INSERT INTO artist_track (artist_id, track_id) " + "VALUES(?, ?)", (artist.id, track.id)) except sqlite3.IntegrityError: pass @@ -616,7 +664,11 @@ class Track(BaseModel): return track @classmethod - def all(cls, database, order="track.id", direction="ASC", limit=None, + def all(cls, + database, + order="track.id", + direction="ASC", + limit=None, offset=None): tracks = [] @@ -628,15 +680,18 @@ class Track(BaseModel): direction) if limit and offset: - select_string = " ".join((select_string, - "LIMIT %s OFFSET %s" % (limit, offset))) + select_string = " ".join( + (select_string, "LIMIT %s OFFSET %s" % (limit, offset))) result = database.execute(select_string) for row in result: - tracks.append(Track(id=row["id"], db=database, - tracknumber=row["tracknumber"], - name=row["name"], grouping=row["name"], - filename=row["filename"])) + tracks.append( + Track(id=row["id"], + db=database, + tracknumber=row["tracknumber"], + name=row["name"], + grouping=row["name"], + filename=row["filename"])) return tracks -- cgit v1.2.3