| 1 |
# Matroska tagger for Exaile |
| 2 |
# Copyright (C) 2010 Johannes Sasongko <[email protected]> |
| 3 |
# |
| 4 |
# This program is free software; you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation; either version 2, or (at your option) |
| 7 |
# any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 |
# |
| 18 |
# |
| 19 |
# The developers of the Exaile media player hereby grant permission |
| 20 |
# for non-GPL compatible GStreamer and Exaile plugins to be used and |
| 21 |
# distributed together with GStreamer and Exaile. This permission is |
| 22 |
# above and beyond the permissions granted by the GPL license by which |
| 23 |
# Exaile is covered. If you modify this code, you may extend this |
| 24 |
# exception to your version of the code, but you are not obligated to |
| 25 |
# do so. If you do not wish to do so, delete this exception statement |
| 26 |
# from your version. |
| 27 |
|
| 28 |
|
| 29 |
from xl.metadata import _base, _matroska |
| 30 |
|
| 31 |
|
| 32 |
class MkaFormat(_base.BaseFormat): |
| 33 |
others = False # For now, stick with defined tags only. |
| 34 |
writable = False |
| 35 |
|
| 36 |
tag_mapping = { |
| 37 |
'album': ('TITLE', 50), |
| 38 |
'album artist': ('ARTIST', 50), |
| 39 |
'artist': ('ARTIST', 30), |
| 40 |
'comment': ('COMMENT', 30), |
| 41 |
'composer': ('COMPOSER', 30), |
| 42 |
'date': ('DATE_RECORDED', 50), |
| 43 |
'discnumber': ('PART_NUMBER', 50), |
| 44 |
'genre': ('GENRE', 30), |
| 45 |
'performer': ('PERFORMER', 30), |
| 46 |
'title': ('TITLE', 30), |
| 47 |
'tracknumber': ('PART_NUMBER', 30), |
| 48 |
} |
| 49 |
|
| 50 |
def _get_raw(self): |
| 51 |
return self.tags |
| 52 |
|
| 53 |
def load(self): |
| 54 |
mka = _matroska.parse(self.loc) |
| 55 |
segment = mka['Segment'][0] |
| 56 |
info = segment['Info'][0] |
| 57 |
try: |
| 58 |
timecodescale = info['TimecodeScale'][0] |
| 59 |
except KeyError: |
| 60 |
timecodescale = 1000000 |
| 61 |
length = info['Duration'][0] * timecodescale / 1e9 |
| 62 |
self.tags = tags = {'__length': length} |
| 63 |
for mkatags in segment['Tags']: |
| 64 |
for mkatag in mkatags['Tag']: |
| 65 |
target = int(mkatag['Targets'][0]['TargetTypevalue'][0]) |
| 66 |
for simpletag in mkatag['SimpleTag']: |
| 67 |
key = (simpletag['TagName'][0], target) |
| 68 |
try: |
| 69 |
values = tags[key] |
| 70 |
except KeyError: |
| 71 |
values = tags[key] = [] |
| 72 |
values.append(simpletag['TagString'][0]) |
| 73 |
|
| 74 |
|
| 75 |
# vi: et sts=4 sw=4 ts=4 |