~ubuntu-branches/ubuntu/lucid/exaile/lucid

« back to all changes in this revision

Viewing changes to plugins/daapserver/spydaap/parser/exaile.py

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Starr-Bochicchio
  • Date: 2010-02-12 19:51:01 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100212195101-8jt3tculxcl92e6v
Tags: 0.3.1~b1-0ubuntu1
* New upstream release.
* Adjust exaile.install for new plugins.
* debian/control:
 - Drop unneeded python-dev Build-Dep.
 - Bump Standards-Version to 3.8.4 
* debian/rules: No empty po files to delete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#Copyright (C) 2008 Erik Hetzner
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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/>.
 
15
 
 
16
import mutagen, re, spydaap, re, os, sys
 
17
from spydaap.daap import do
 
18
import traceback
 
19
 
 
20
class ExaileParser(spydaap.parser.Parser):
 
21
    _string_map = {
 
22
        'title': 'dmap.itemname',
 
23
        'artist': 'daap.songartist',
 
24
        'composer': 'daap.songcomposer',
 
25
        'genre': 'daap.songgenre',
 
26
        'album': 'daap.songalbum'
 
27
        }
 
28
    
 
29
    _int_map = {
 
30
        'bpm': 'daap.songbeatsperminute',
 
31
        'date': 'daap.songyear',
 
32
        'year': 'daap.songyear',
 
33
        'tracknumber': 'daap.songtracknumber',
 
34
        'tracktotal': 'daap.songtrackcount',
 
35
        'discnumber': 'daap.songdiscnumber'
 
36
        }
 
37
 
 
38
    def understands(self, filename):
 
39
        return true
 
40
     #   return self.file_re.match(filename)
 
41
 
 
42
    # returns a list in exaile
 
43
    def handle_int_tags(self, map, md, daap):
 
44
        for k in md.list_tags():
 
45
            if map.has_key(k):
 
46
                try:
 
47
                    tn = str(md.get_tag_raw(k)[0])
 
48
                    if '/' in tn: #
 
49
                        num, tot = tn.split('/')
 
50
                        daap.append(do(map[k], int(num)))
 
51
                        # set total?
 
52
                    else:
 
53
                        daap.append(do(map[k], int(tn)))
 
54
                except: pass
 
55
                # dates cause exceptions todo
 
56
#                    print 'Parse Exception'
 
57
#                    traceback.print_exc(file=sys.stdout)
 
58
 
 
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():
 
63
            if map.has_key(k):
 
64
                try:
 
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)))
 
68
                except: pass
 
69
 
 
70
    def parse(self, trk):
 
71
        try:
 
72
            #trk = mutagen.File(filename)
 
73
            d = []
 
74
            if len(trk.list_tags()) > 0:
 
75
                if 'title' in trk.list_tags():
 
76
                    name = str(trk.get_tag_raw('title')[0])
 
77
                else: name = str(trk)
 
78
                
 
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)
 
82
            else: 
 
83
                name = str(trk)
 
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'),
 
93
                      ])
 
94
            return (d, name)
 
95
        except Exception, e:
 
96
            sys.stderr.write("Caught exception: while processing %s: %s " % (trk, str(e)) )
 
97
            return (None, None)    
 
98
 
 
99