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

« back to all changes in this revision

Viewing changes to plugins/cd/importer.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:
15
15
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
16
#
17
17
#
18
 
# The developers of the Exaile media player hereby grant permission 
19
 
# for non-GPL compatible GStreamer and Exaile plugins to be used and 
20
 
# distributed together with GStreamer and Exaile. This permission is 
21
 
# above and beyond the permissions granted by the GPL license by which 
22
 
# Exaile is covered. If you modify this code, you may extend this 
23
 
# exception to your version of the code, but you are not obligated to 
24
 
# do so. If you do not wish to do so, delete this exception statement 
 
18
# The developers of the Exaile media player hereby grant permission
 
19
# for non-GPL compatible GStreamer and Exaile plugins to be used and
 
20
# distributed together with GStreamer and Exaile. This permission is
 
21
# above and beyond the permissions granted by the GPL license by which
 
22
# Exaile is covered. If you modify this code, you may extend this
 
23
# exception to your version of the code, but you are not obligated to
 
24
# do so. If you do not wish to do so, delete this exception statement
25
25
# from your version.
26
26
 
27
27
import os, threading, copy
28
 
from xl import transcoder, track, settings, common
 
28
from xl import transcoder, trax, settings, common
29
29
 
30
30
 
31
31
class CDImporter(object):
32
32
    def __init__(self, tracks):
33
 
        self.tracks = [ t for t in tracks if 
 
33
        self.tracks = [ t for t in tracks if
34
34
                t.get_loc_for_io().startswith("cdda") ]
35
 
        self.duration = float(sum( [ t['__length'] for t in self.tracks ] ))
 
35
        self.duration = float(sum( [ t.get_tag_raw('__length') for t in self.tracks ] ))
36
36
        self.transcoder = transcoder.Transcoder()
37
37
        self.current = None
38
38
        self.current_len = None
40
40
 
41
41
        self.running = False
42
42
 
43
 
        self.outpath = settings.get_option("cd_import/outpath", 
 
43
        self.outpath = settings.get_option("cd_import/outpath",
44
44
                "%s/$artist/$album/$tracknumber - $title" % \
45
45
                os.getenv("HOME"))
46
46
 
63
63
        for tr in self.tracks:
64
64
            self.cont.clear()
65
65
            self.current = tr
66
 
            self.current_len = tr['__length']
67
 
            tags = copy.copy(tr.tags)
68
 
            for t in tags.keys():
69
 
                if t.startswith("__"):
70
 
                    del tags[t]
 
66
            self.current_len = tr.get_tag_raw('__length')
71
67
            loc = tr.get_loc_for_io()
72
 
            trackno, device = loc[7:].split("#")
 
68
            trackno, device = loc[7:].split("/#")
73
69
            src = "cdparanoiasrc track=%s device=\"%s\""%(trackno, device)
74
70
            self.transcoder.set_raw_input(src)
75
71
            outloc = self.get_output_location(tr)
78
74
            self.cont.wait()
79
75
            if not self.running:
80
76
                break
81
 
            tr2 = track.Track("file://"+outloc)
82
 
            tr2.tags.update(tags)
 
77
            tr2 = trax.Track("file://"+outloc)
 
78
            for t in tr.list_tags():
 
79
                if not t.startswith("__"):
 
80
                    tr2.set_tag_raw(t, tr.get_tag_raw(t))
83
81
            tr2.write_tags()
84
82
            try:
85
 
                incr = tr['__length'] / self.duration
 
83
                incr = tr.get_tag_raw('__length') / self.duration
86
84
                self.progress += incr
87
85
            except:
88
86
                raise
100
98
            replacedict["$%s"%tag] = tag
101
99
        for part in parts:
102
100
            for k, v in replacedict.iteritems():
103
 
                val = tr[v]
104
 
                if type(val) in (list, tuple):
105
 
                    val = u" & ".join(val) 
 
101
                val = tr.get_tag_display(v, artist_compilations=False)
 
102
                val = val.replace('"', '\\"')
106
103
                part = part.replace(k, str(val))
107
104
            part = part.replace(os.sep, "") # strip os.sep
108
105
            parts2.append(part)
109
 
        dirpath = "/" + os.path.join(*parts2[:-1]) 
 
106
        dirpath = "/" + os.path.join(*parts2[:-1])
110
107
        if not os.path.exists(dirpath):
111
108
            os.makedirs(dirpath)
112
109
        ext = transcoder.FORMATS[self.transcoder.dest_format]['extension']