Updated tags source detection (TinyTags or GStreamer)
This commit is contained in:
parent
22bd607338
commit
79748e17a3
@ -67,9 +67,11 @@ class Scanner(object):
|
|||||||
"""
|
"""
|
||||||
if uri[:4] == 'file':
|
if uri[:4] == 'file':
|
||||||
duration, seekable, mime = None, None, None
|
duration, seekable, mime = None, None, None
|
||||||
|
have_audio = False
|
||||||
tags = {}
|
tags = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
tags['tinytag'] = True
|
||||||
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']
|
||||||
@ -79,19 +81,16 @@ class Scanner(object):
|
|||||||
break
|
break
|
||||||
if supported:
|
if supported:
|
||||||
tag = TinyTag.get(fname, image=False)
|
tag = TinyTag.get(fname, image=False)
|
||||||
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
|
||||||
duration=int(float(tag.duration) * 1000) # duration of the song in seconds
|
if tag.genre: tags['genre'] = tag.genre.rstrip('\0') # genre as string
|
||||||
#if tag.filesize # file size in bytes
|
if tag.title: tags['title'] = tag.title.rstrip('\0') # title of the song
|
||||||
if tag.genre: tags['genre'] = tag.genre.rstrip('\0') # genre as string
|
if tag.track: tags['track'] = int(tag.track.rstrip('\0')) # track number as string
|
||||||
#if tag.samplerate # samples per second
|
|
||||||
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_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
|
||||||
if tag.composer: tags['composer'] = tag.composer.rstrip('\0')
|
if tag.composer: tags['composer'] = tag.composer.rstrip('\0')
|
||||||
#try:
|
#try:
|
||||||
|
|||||||
@ -90,7 +90,8 @@ def convert_tags_to_track(tags):
|
|||||||
album_kwargs = {}
|
album_kwargs = {}
|
||||||
track_kwargs = {}
|
track_kwargs = {}
|
||||||
|
|
||||||
try:
|
if not 'tinytag' 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:
|
else:
|
||||||
|
# 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,17 +161,10 @@ 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:
|
return Track(**track_kwargs)
|
||||||
# if not i == 'image' : print(i, track_kwargs[i])
|
|
||||||
|
|
||||||
finally:
|
|
||||||
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):
|
||||||
# Name missing, don't set artist
|
# Name missing, don't set artist
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user