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

« back to all changes in this revision

Viewing changes to plugins/cd/__init__.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
 
36
36
 
37
37
import dbus, threading, os, struct
38
38
from fcntl import ioctl
39
 
from xl import playlist, track, common
 
39
from xl import playlist, trax, common
40
40
from xl import settings
41
41
import os.path
42
42
 
47
47
    CDDB_AVAIL=False
48
48
 
49
49
import cdprefs
50
 
    
 
50
 
51
51
def get_prefs_pane():
52
52
    return cdprefs
53
53
 
97
97
            entry = ioctl(fd, CDROMREADTOCENTRY, entry)
98
98
            track, adrctrl, format, addr = struct.unpack(TOC_ENTRY_FMT, entry)
99
99
            m, s, f = struct.unpack(ADDR_FMT, struct.pack('i', addr))
100
 
                
 
100
 
101
101
            adr = adrctrl & 0xf
102
102
            ctrl = (adrctrl & 0xf0) >> 4
103
103
 
105
105
            if ctrl & CDROM_DATA_TRACK:
106
106
                data = 1
107
107
 
108
 
            self.raw_tracks.append( (track, m, s, f, (m*60+s) * 75 + f, data) ) 
 
108
            self.raw_tracks.append( (track, m, s, f, (m*60+s) * 75 + f, data) )
109
109
 
110
110
    def get_raw_info(self):
111
111
        return self.raw_tracks[:]
126
126
            self.device = "/dev/cdrom"
127
127
        else:
128
128
            self.device = device
129
 
        
 
129
 
130
130
        self.open_disc()
131
131
 
132
132
    def open_disc(self):
135
135
        lengths = toc.get_track_lengths()
136
136
 
137
137
        songs = {}
138
 
        
 
138
 
139
139
        for count, length in enumerate(lengths):
140
140
            count += 1
141
 
            song = track.Track()
142
 
            song.set_loc("cdda://%d#%s" % (count, self.device))
143
 
            song['title'] = "Track %d" % count
144
 
            song['tracknumber'] = count
145
 
            song['__length'] = length
146
 
            songs[song.get_loc()] = song
 
141
            song = trax.Track("cdda://%d#%s" % (count, self.device))
 
142
            song.set_tag_raw('title', "Track %d" % count)
 
143
            song.set_tag_raw('tracknumber', count)
 
144
            song.set_tag_raw('__length', length)
 
145
            songs[song.get_loc_for_io()] = song
147
146
 
148
 
        sort_tups = [ (int(s['tracknumber'][0]),s) for s in songs.values() ]
 
147
        # FIXME: this can probably be cleaner
 
148
        sort_tups = [ (int(s.get_tag_raw('tracknumber')[0]),s) \
 
149
                for s in songs.values() ]
149
150
        sort_tups.sort()
150
 
 
151
151
        sorted = [ s[1] for s in sort_tups ]
152
152
 
153
153
        self.add_tracks(sorted)
154
154
 
155
155
        if CDDB_AVAIL:
156
156
            self.get_cddb_info()
157
 
    
 
157
 
158
158
    @common.threaded
159
159
    def get_cddb_info(self):
160
160
        try:
161
161
            disc = DiscID.open(self.device)
162
 
            self.info = DiscID.disc_id(disc) 
 
162
            self.info = DiscID.disc_id(disc)
163
163
            status, info = CDDB.query(self.info)
164
164
        except IOError:
165
165
            return
169
169
            status = 200
170
170
        if status != 200:
171
171
            return
172
 
        
 
172
 
173
173
        (status, info) = CDDB.read(info['category'], info['disc_id'])
174
 
        
 
174
 
175
175
        title = info['DTITLE'].split(" / ")
176
176
        for i in range(self.info[1]):
177
 
            self.ordered_tracks[i]['title'] = \
178
 
                    info['TTITLE' + `i`].decode('iso-8859-15', 'replace')
179
 
            self.ordered_tracks[i]['album'] = \
180
 
                    title[1].decode('iso-8859-15', 'replace')
181
 
            self.ordered_tracks[i]['artist'] = \
182
 
                    title[0].decode('iso-8859-15', 'replace')
183
 
            self.ordered_tracks[i]['year'] = \
184
 
                    info['EXTD'].replace("YEAR: ", "")
185
 
            self.ordered_tracks[i]['genre'] = \
186
 
                    info['DGENRE']
 
177
            tr = self.ordered_tracks[i]
 
178
            tr.set_tag_raw('title',
 
179
                    info['TTITLE' + `i`].decode('iso-8859-15', 'replace'))
 
180
            tr.set_tag_raw('album',
 
181
                    title[1].decode('iso-8859-15', 'replace'))
 
182
            tr.set_tag_raw('artist',
 
183
                    title[0].decode('iso-8859-15', 'replace'))
 
184
            tr.set_tag_raw('year',
 
185
                    info['EXTD'].replace("YEAR: ", ""))
 
186
            tr.set_tag_raw('genre',
 
187
                    info['DGENRE'])
187
188
 
188
189
        self.set_name(title[1].decode('iso-8859-15', 'replace'))
189
190
        event.log_event('cddb_info_retrieved', self, True)
208
209
        except:
209
210
            common.log_exception(log=logger, message="Could not import cd gui panel")
210
211
            return 'flatplaylist'
211
 
      
 
212
 
212
213
    panel_type = property(_get_panel_type)
213
214
 
214
215
    def connect(self):