1
#Copyright (C) 2008 Erik Hetzner
3
#This file is part of Spydaap. Spydaap is free software: you can
4
#redistribute it and/or modify it under the terms of the GNU General
5
#Public License as published by the Free Software Foundation, either
6
#version 3 of the License, or (at your option) any later version.
8
#Spydaap is distributed in the hope that it will be useful, but
9
#WITHOUT ANY WARRANTY; without even the implied warranty of
10
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
#General Public License for more details.
13
#You should have received a copy of the GNU General Public License
14
#along with Spydaap. If not, see <http://www.gnu.org/licenses/>.
16
import mutagen, re, spydaap, re, os, sys
17
from spydaap.daap import do
20
class ExaileParser(spydaap.parser.Parser):
22
'title': 'dmap.itemname',
23
'artist': 'daap.songartist',
24
'composer': 'daap.songcomposer',
25
'genre': 'daap.songgenre',
26
'album': 'daap.songalbum'
30
'bpm': 'daap.songbeatsperminute',
31
'date': 'daap.songyear',
32
'year': 'daap.songyear',
33
'tracknumber': 'daap.songtracknumber',
34
'tracktotal': 'daap.songtrackcount',
35
'discnumber': 'daap.songdiscnumber'
38
def understands(self, filename):
40
# return self.file_re.match(filename)
42
# returns a list in exaile
43
def handle_int_tags(self, map, md, daap):
44
for k in md.list_tags():
47
tn = str(md.get_tag_raw(k)[0])
49
num, tot = tn.split('/')
50
daap.append(do(map[k], int(num)))
53
daap.append(do(map[k], int(tn)))
55
# dates cause exceptions todo
56
# print 'Parse Exception'
57
# traceback.print_exc(file=sys.stdout)
59
# We can't use functions in __init__ because exaile tracks no longer
60
# give us access to .tags
61
def handle_string_tags(self, map, md, daap):
62
for k in md.list_tags():
65
tag = [ str(t) for t in md.get_tag_raw(k)]
66
tag = [ t for t in tag if t != ""]
67
daap.append(do(map[k], "/".join(tag)))
72
#trk = mutagen.File(filename)
74
if len(trk.list_tags()) > 0:
75
if 'title' in trk.list_tags():
76
name = str(trk.get_tag_raw('title')[0])
79
self.handle_string_tags(self._string_map, trk, d)
80
self.handle_int_tags(self._int_map, trk, d)
81
# self.handle_rating(trk, d)
84
#statinfo = os.stat(filename)
85
d.extend([#do('daap.songsize', trk.get_size()),
86
#do('daap.songdateadded', statinfo.st_ctime),
87
#do('daap.songdatemodified', statinfo.st_ctime),
88
do('daap.songtime', trk.get_tag_raw('__length') * 1000),
89
# do('daap.songbitrate', trk.get_tag_raw('__bitrate') / 1000),
90
# do('daap.songsamplerate', ogg.info.sample_rate), # todo ??
91
do('daap.songformat', trk.local_file_name().split('.')[-1]), # todo ??
92
do('daap.songdescription', 'Exaile Streaming Audio'),
96
sys.stderr.write("Caught exception: while processing %s: %s " % (trk, str(e)) )