Updated tags source detection (TinyTags or GStreamer)

This commit is contained in:
Andrey Perminov 2019-07-03 11:34:42 -07:00
parent 22bd607338
commit 3bd6292859
2 changed files with 18 additions and 25 deletions

View File

@ -66,10 +66,12 @@ class Scanner(object):
indicating if a seek would succeed. indicating if a seek would succeed.
""" """
if uri[:4] == 'file': if uri[:4] == 'file':
duration, seekable, mime = None, None, None duration, seekable, mime = 0, None, None
have_audio = False
tags = {} tags = {}
try: try:
tags['tagtype'] = 'TinyTags'
fname = unquote(uri[7:]).encode('raw_unicode_escape').decode('utf-8') fname = unquote(uri[7:]).encode('raw_unicode_escape').decode('utf-8')
supported = False supported = False
extensions = ['.mp3', '.oga', '.ogg', '.opus', '.wav', '.flac', '.wma', '.m4b', '.m4a', '.mp4'] extensions = ['.mp3', '.oga', '.ogg', '.opus', '.wav', '.flac', '.wma', '.m4b', '.m4a', '.mp4']
@ -82,14 +84,11 @@ class Scanner(object):
if tag.album: tags['album'] = tag.album.rstrip('\0') # album as string if tag.album: tags['album'] = tag.album.rstrip('\0') # album as string
if tag.albumartist: tags['albumartist'] = tag.albumartist.rstrip('\0') # album artist as string if tag.albumartist: tags['albumartist'] = tag.albumartist.rstrip('\0') # album artist as string
if tag.artist: tags['artist'] = tag.artist.rstrip('\0') # artist name as string if tag.artist: tags['artist'] = tag.artist.rstrip('\0') # artist name as string
#if tag.audio_offset # number of bytes before audio data begins
if tag.bitrate: tags['bitrate'] = int(tag.bitrate) # bitrate in kBits/s if tag.bitrate: tags['bitrate'] = int(tag.bitrate) # bitrate in kBits/s
if tag.disc: tags['disc'] = int(tag.disc.rstrip('\0')) # disk number in album if tag.disc: tags['disc'] = int(tag.disc.rstrip('\0')) # disk number in album
if tag.disc_total: tags['disc_total'] = int(tag.disc_total.rstrip('\0')) # the total number of discs if tag.disc_total: tags['disc_total'] = int(tag.disc_total.rstrip('\0')) # the total number of discs
duration=int(float(tag.duration) * 1000) # duration of the song in seconds if tag.duration: duration = int(float(tag.duration) * 1000) # duration of the song in seconds
#if tag.filesize # file size in bytes
if tag.genre: tags['genre'] = tag.genre.rstrip('\0') # genre as string if tag.genre: tags['genre'] = tag.genre.rstrip('\0') # genre as string
#if tag.samplerate # samples per second
if tag.title: tags['title'] = tag.title.rstrip('\0') # title of the song if tag.title: tags['title'] = tag.title.rstrip('\0') # title of the song
if tag.track: tags['track'] = int(tag.track.rstrip('\0')) # track number as string if tag.track: tags['track'] = int(tag.track.rstrip('\0')) # track number as string
if tag.track_total: tags['track_total'] = int(tag.track_total.rstrip('\0')) # total number of tracks as string if tag.track_total: tags['track_total'] = int(tag.track_total.rstrip('\0')) # total number of tracks as string

View File

@ -90,7 +90,8 @@ def convert_tags_to_track(tags):
album_kwargs = {} album_kwargs = {}
track_kwargs = {} track_kwargs = {}
try: if not 'tagtype' in tags:
# Using tags from gstreamer
track_kwargs['composers'] = _artists(tags, Gst.TAG_COMPOSER) track_kwargs['composers'] = _artists(tags, Gst.TAG_COMPOSER)
track_kwargs['performers'] = _artists(tags, Gst.TAG_PERFORMER) track_kwargs['performers'] = _artists(tags, Gst.TAG_PERFORMER)
track_kwargs['artists'] = _artists(tags, Gst.TAG_ARTIST, track_kwargs['artists'] = _artists(tags, Gst.TAG_ARTIST,
@ -135,8 +136,8 @@ def convert_tags_to_track(tags):
if album_kwargs.get('name'): if album_kwargs.get('name'):
track_kwargs['album'] = Album(**album_kwargs) track_kwargs['album'] = Album(**album_kwargs)
except: elif tags['tagtype'] == 'TinyTags':
# Using tags from TinyTags
if 'title' in tags: track_kwargs['name'] = tags['title'] if 'title' in tags: track_kwargs['name'] = tags['title']
if 'genre' in tags: track_kwargs['genre'] = tags['genre'] if 'genre' in tags: track_kwargs['genre'] = tags['genre']
if 'track' in tags: track_kwargs['track_no'] = tags['track'] if 'track' in tags: track_kwargs['track_no'] = tags['track']
@ -160,16 +161,9 @@ def convert_tags_to_track(tags):
if album_kwargs.get('name'): if album_kwargs.get('name'):
track_kwargs['album'] = Album(**album_kwargs) track_kwargs['album'] = Album(**album_kwargs)
#if 'album' in tags:
# track_kwargs['album'] = Album(name=tags['album'])
if 'artist' in tags: if 'artist' in tags:
track_kwargs['artists'] = [Artist(name=tags['artist'])] track_kwargs['artists'] = [Artist(name=tags['artist'])]
#for i in track_kwargs:
# if not i == 'image' : print(i, track_kwargs[i])
finally:
return Track(**track_kwargs) return Track(**track_kwargs)
def _artists(tags, artist_name, artist_id=None, artist_sortname=None): def _artists(tags, artist_name, artist_id=None, artist_sortname=None):