| 1 |
from xl.nls import gettext |
| 2 |
|
| 3 |
|
| 4 |
def N_(x): |
| 5 |
return x |
| 6 |
|
| 7 |
|
| 8 |
class _TD: |
| 9 |
__slots__ = [ |
| 10 |
'name', # descriptive name |
| 11 |
'translated_name', # translated name |
| 12 |
'tag_name', # raw tag name |
| 13 |
'type', |
| 14 |
'editable', |
| 15 |
'min', |
| 16 |
'max', |
| 17 |
'use_disk', # set true if should retrieve tag from disk -- which means |
| 18 |
# the tag cannot be stored in the database |
| 19 |
] |
| 20 |
|
| 21 |
def __init__(self, name, type, **kwargs): |
| 22 |
self.name = name |
| 23 |
self.translated_name = gettext(name) |
| 24 |
self.type = type |
| 25 |
|
| 26 |
# these are overridable by keyword arg |
| 27 |
self.editable = True |
| 28 |
self.use_disk = False |
| 29 |
|
| 30 |
for k, v in kwargs.items(): |
| 31 |
setattr(self, k, v) |
| 32 |
|
| 33 |
|
| 34 |
#: List of metadata tags currently supported by exaile, which are |
| 35 |
#: translated into the corresponding tag for each audio format if |
| 36 |
#: it supports it. Prefer to extend this list's features instead |
| 37 |
#: of creating your own list of tag metadata |
| 38 |
#: |
| 39 |
#: @note We use N_ (fake gettext) because for some uses these strings are |
| 40 |
#: translated later, so we store both the translated and untranslated |
| 41 |
#: version |
| 42 |
|
| 43 |
tag_data = { |
| 44 |
# fmt: off |
| 45 |
'album': _TD(N_('Album'), 'text'), |
| 46 |
'arranger': _TD(N_('Arranger'), 'text'), |
| 47 |
'artist': _TD(N_('Artist'), 'text'), |
| 48 |
'albumartist': _TD(N_('Album artist'), 'text'), |
| 49 |
'author': _TD(N_('Author'), 'text'), |
| 50 |
'bpm': _TD(N_('BPM'), 'int', min=0, max=500), |
| 51 |
'copyright': _TD(N_('Copyright'), 'text'), |
| 52 |
'comment': _TD(N_('Comment'), 'multiline'), |
| 53 |
'composer': _TD(N_('Composer'), 'text'), |
| 54 |
'conductor': _TD(N_('Conductor'), 'text'), |
| 55 |
'cover': _TD(N_('Cover'), 'image', use_disk=True), |
| 56 |
'date': _TD(N_('Date'), 'datetime'), |
| 57 |
'discnumber': _TD(N_('Disc'), 'dblnum', min=0, max=50), |
| 58 |
'encodedby': _TD(N_('Encoded by'), 'text'), |
| 59 |
'genre': _TD(N_('Genre'), 'text'), |
| 60 |
'grouping': _TD(N_('Grouping'), 'text'), |
| 61 |
'isrc': _TD(N_('ISRC'), 'text'), |
| 62 |
'language': _TD(N_('Language'), 'text'), |
| 63 |
'lyrics': _TD(N_('Lyrics'), 'multiline', use_disk=True), |
| 64 |
'lyricist': _TD(N_('Lyricist'), 'text'), |
| 65 |
'organization': _TD(N_('Organization'), 'text'), |
| 66 |
'originalalbum': _TD(N_('Original album'), 'text'), |
| 67 |
'originalartist': _TD(N_('Original artist'), 'text'), |
| 68 |
'originaldate': _TD(N_('Original date'), 'text'), |
| 69 |
'part': None, |
| 70 |
'performer': _TD(N_('Performer'), 'text'), |
| 71 |
'title': _TD(N_('Title'), 'text'), |
| 72 |
'tracknumber': _TD(N_('Track'), 'dblnum', min=0, max=500), |
| 73 |
'version': _TD(N_('Version'), 'text'), |
| 74 |
'website': _TD(N_('Website'), 'text'), |
| 75 |
|
| 76 |
# various internal tags |
| 77 |
|
| 78 |
'__bitrate': _TD(N_('Bitrate'), 'bitrate', editable=False), |
| 79 |
'__basedir': None, |
| 80 |
'__date_added': _TD(N_('Date added'), 'timestamp', editable=False), |
| 81 |
'__last_played': _TD(N_('Last played'), 'timestamp', editable=False), |
| 82 |
'__length': _TD(N_('Length'), 'time', editable=False), |
| 83 |
'__loc': _TD(N_('Location'), 'location', editable=False), |
| 84 |
'__modified': _TD(N_('Modified'), 'timestamp', editable=False), |
| 85 |
'__playtime': _TD(N_('Play time'), 'time', editable=False), |
| 86 |
'__playcount': _TD(N_('Times played'), 'int', editable=False), |
| 87 |
'__rating': None, # currently special. |
| 88 |
'__startoffset': _TD(N_('Start offset'), 'time', min=0, max=3600), # TODO: calculate these parameters |
| 89 |
'__stopoffset': _TD(N_('Stop offset'), 'time', min=0, max=3600), |
| 90 |
# fmt: on |
| 91 |
} |
| 92 |
|
| 93 |
disk_tags = set() |
| 94 |
|
| 95 |
for k, v in tag_data.items(): |
| 96 |
if v: |
| 97 |
v.tag_name = k |
| 98 |
if v.use_disk: |
| 99 |
disk_tags.add(k) |
| 100 |
|
| 101 |
|
| 102 |
def get_default_tagdata(tag): |
| 103 |
"""If the tagname is not in tag_data, you can use this function |
| 104 |
to get a _TD object for it""" |
| 105 |
|
| 106 |
return _TD(tag, 'text', editable=(not tag.startswith('__')), tag_name=tag) |