mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-23 01:16:18 +00:00
Whether or not a track has embeded art is tracked just like any other metadata, to reduce disk r/w and mem usage and a lot of other things.
WARNING: This needs migrations before being merged to master
This commit is contained in:
parent
74fba8840e
commit
2c4ec6c0e8
@ -105,7 +105,7 @@ class Folder(PathMixin, db.Entity):
|
|||||||
info['coverArt'] = str(self.id)
|
info['coverArt'] = str(self.id)
|
||||||
else:
|
else:
|
||||||
for track in self.tracks:
|
for track in self.tracks:
|
||||||
if track.extract_cover_art():
|
if track.has_art:
|
||||||
info['coverArt'] = str(track.id)
|
info['coverArt'] = str(track.id)
|
||||||
break
|
break
|
||||||
|
|
||||||
@ -216,6 +216,7 @@ class Track(PathMixin, db.Entity):
|
|||||||
year = Optional(int)
|
year = Optional(int)
|
||||||
genre = Optional(str, nullable = True)
|
genre = Optional(str, nullable = True)
|
||||||
duration = Required(int)
|
duration = Required(int)
|
||||||
|
has_art = Required(bool, default=False)
|
||||||
|
|
||||||
album = Required(Album, column = 'album_id')
|
album = Required(Album, column = 'album_id')
|
||||||
artist = Required(Artist, column = 'artist_id')
|
artist = Required(Artist, column = 'artist_id')
|
||||||
@ -266,7 +267,7 @@ class Track(PathMixin, db.Entity):
|
|||||||
info['year'] = self.year
|
info['year'] = self.year
|
||||||
if self.genre:
|
if self.genre:
|
||||||
info['genre'] = self.genre
|
info['genre'] = self.genre
|
||||||
if self.extract_cover_art():
|
if self.has_art:
|
||||||
info['coverArt'] = str(self.id)
|
info['coverArt'] = str(self.id)
|
||||||
elif self.folder.cover_art:
|
elif self.folder.cover_art:
|
||||||
info['coverArt'] = str(self.folder.id)
|
info['coverArt'] = str(self.folder.id)
|
||||||
@ -304,8 +305,11 @@ class Track(PathMixin, db.Entity):
|
|||||||
return (self.album.artist.name + self.album.name + ("%02i" % self.disc) + ("%02i" % self.number) + self.title).lower()
|
return (self.album.artist.name + self.album.name + ("%02i" % self.disc) + ("%02i" % self.number) + self.title).lower()
|
||||||
|
|
||||||
def extract_cover_art(self):
|
def extract_cover_art(self):
|
||||||
if os.path.exists(self.path):
|
return Track._extract_cover_art(self.path)
|
||||||
metadata = mutagen.File(self.path)
|
|
||||||
|
def _extract_cover_art(path):
|
||||||
|
if os.path.exists(path):
|
||||||
|
metadata = mutagen.File(path)
|
||||||
data = None
|
data = None
|
||||||
if metadata:
|
if metadata:
|
||||||
if isinstance(metadata.tags, mutagen.id3.ID3Tags) and len(metadata.tags.getall('APIC')) > 0:
|
if isinstance(metadata.tags, mutagen.id3.ID3Tags) and len(metadata.tags.getall('APIC')) > 0:
|
||||||
|
@ -140,6 +140,7 @@ class Scanner:
|
|||||||
trdict['year'] = self.__try_read_tag(tag, 'date', None, lambda x: int(x[0].split('-')[0]))
|
trdict['year'] = self.__try_read_tag(tag, 'date', None, lambda x: int(x[0].split('-')[0]))
|
||||||
trdict['genre'] = self.__try_read_tag(tag, 'genre')
|
trdict['genre'] = self.__try_read_tag(tag, 'genre')
|
||||||
trdict['duration'] = int(tag.info.length)
|
trdict['duration'] = int(tag.info.length)
|
||||||
|
trdict['has_art'] = bool(Track._extract_cover_art(path))
|
||||||
|
|
||||||
trdict['bitrate'] = (tag.info.bitrate if hasattr(tag.info, 'bitrate') else int(os.path.getsize(path) * 8 / tag.info.length)) // 1000
|
trdict['bitrate'] = (tag.info.bitrate if hasattr(tag.info, 'bitrate') else int(os.path.getsize(path) * 8 / tag.info.length)) // 1000
|
||||||
trdict['content_type'] = mimetypes.guess_type(path, False)[0] or 'application/octet-stream'
|
trdict['content_type'] = mimetypes.guess_type(path, False)[0] or 'application/octet-stream'
|
||||||
|
@ -29,6 +29,7 @@ CREATE TABLE IF NOT EXISTS track (
|
|||||||
year INTEGER,
|
year INTEGER,
|
||||||
genre VARCHAR(256),
|
genre VARCHAR(256),
|
||||||
duration INTEGER NOT NULL,
|
duration INTEGER NOT NULL,
|
||||||
|
has_art BOOLEAN NOT NULL,
|
||||||
album_id BINARY(16) NOT NULL REFERENCES album,
|
album_id BINARY(16) NOT NULL REFERENCES album,
|
||||||
artist_id BINARY(16) NOT NULL REFERENCES artist,
|
artist_id BINARY(16) NOT NULL REFERENCES artist,
|
||||||
bitrate INTEGER NOT NULL,
|
bitrate INTEGER NOT NULL,
|
||||||
|
@ -29,6 +29,7 @@ CREATE TABLE IF NOT EXISTS track (
|
|||||||
year INTEGER,
|
year INTEGER,
|
||||||
genre VARCHAR(256),
|
genre VARCHAR(256),
|
||||||
duration INTEGER NOT NULL,
|
duration INTEGER NOT NULL,
|
||||||
|
has_art BOOLEAN NOT NULL,
|
||||||
album_id UUID NOT NULL REFERENCES album,
|
album_id UUID NOT NULL REFERENCES album,
|
||||||
artist_id UUID NOT NULL REFERENCES artist,
|
artist_id UUID NOT NULL REFERENCES artist,
|
||||||
bitrate INTEGER NOT NULL,
|
bitrate INTEGER NOT NULL,
|
||||||
|
@ -31,6 +31,7 @@ CREATE TABLE IF NOT EXISTS track (
|
|||||||
year INTEGER,
|
year INTEGER,
|
||||||
genre VARCHAR(256),
|
genre VARCHAR(256),
|
||||||
duration INTEGER NOT NULL,
|
duration INTEGER NOT NULL,
|
||||||
|
has_art BOOLEAN NOT NULL,
|
||||||
album_id CHAR(36) NOT NULL REFERENCES album,
|
album_id CHAR(36) NOT NULL REFERENCES album,
|
||||||
artist_id CHAR(36) NOT NULL REFERENCES artist,
|
artist_id CHAR(36) NOT NULL REFERENCES artist,
|
||||||
bitrate INTEGER NOT NULL,
|
bitrate INTEGER NOT NULL,
|
||||||
|
@ -71,6 +71,7 @@ class DbTestCase(unittest.TestCase):
|
|||||||
disc = 1,
|
disc = 1,
|
||||||
number = 1,
|
number = 1,
|
||||||
duration = 3,
|
duration = 3,
|
||||||
|
has_art = True,
|
||||||
bitrate = 320,
|
bitrate = 320,
|
||||||
path = 'tests/assets/formats/silence.ogg',
|
path = 'tests/assets/formats/silence.ogg',
|
||||||
content_type = 'audio/ogg',
|
content_type = 'audio/ogg',
|
||||||
@ -106,6 +107,7 @@ class DbTestCase(unittest.TestCase):
|
|||||||
disc = 1,
|
disc = 1,
|
||||||
number = 1,
|
number = 1,
|
||||||
duration = 5,
|
duration = 5,
|
||||||
|
has_art = True,
|
||||||
bitrate = 96,
|
bitrate = 96,
|
||||||
path = 'tests/assets/formats/silence.flac',
|
path = 'tests/assets/formats/silence.flac',
|
||||||
content_type = 'audio/flac',
|
content_type = 'audio/flac',
|
||||||
|
Loading…
Reference in New Issue
Block a user