Changeset 420


Ignore:
Timestamp:
02-01-11 18:14:26 (2 years ago)
Author:
thomas
Message:
  • morituri/common/program.py:
  • morituri/image/table.py:
  • morituri/rip/cd.py: Get CDDB disc id. Use it to print info when not found on MusicBrainz?.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r417 r420  
     12011-01-02  Thomas Vander Stichele  <thomas at apestaart dot org> 
     2 
     3        * morituri/common/program.py: 
     4        * morituri/image/table.py: 
     5        * morituri/rip/cd.py: 
     6          Get CDDB disc id.  Use it to print info when not found on 
     7          MusicBrainz. 
     8 
    192011-01-01  Thomas Vander Stichele  <thomas at apestaart dot org> 
    210 
  • trunk/morituri/common/program.py

    r416 r420  
    301301 
    302302        return os.path.join(outdir, template % v) 
     303 
     304    def getCDDB(self, cddbdiscid): 
     305        """ 
     306        @param cddbdiscid: list of id, tracks, offsets, seconds 
     307 
     308        @rtype: str 
     309        """ 
     310        # FIXME: convert to nonblocking? 
     311        import CDDB 
     312        code, md = CDDB.query(cddbdiscid)  
     313        self.debug('CDDB query result: %r, %r', code, md) 
     314        if code == 200: 
     315            return md['title'] 
     316 
     317        return None 
     318 
    303319 
    304320    def getMusicBrainz(self, ittoc, mbdiscid): 
  • trunk/morituri/image/table.py

    r369 r420  
    240240        return ret 
    241241 
    242     def getCDDBDiscId(self): 
    243         """ 
    244         Calculate the CDDB disc ID. 
    245  
    246         @rtype:   str 
    247         @returns: the 8-character hexadecimal disc ID 
    248         """ 
     242    def _getCDDBValues(self): 
     243        """ 
     244        Get all CDDB values needed to calculate disc id and lookup URL. 
     245 
     246        This includes: 
     247         - CDDB disc id 
     248         - number of audio tracks 
     249         - offset of index 1 of each track 
     250         - length of disc in seconds 
     251 
     252        @rtype:   list of int 
     253        """ 
     254        result = [] 
     255 
     256        # number of first track 
     257        result.append(1) 
     258 
     259        # number of last audio track 
     260        result.append(self.getAudioTracks()) 
     261 
     262        leadout = self.leadout 
     263        # if the disc is multi-session, last track is the data track, 
     264        # and we should subtract 11250 + 150 from the last track's offset 
     265        # for the leadout 
     266        if self.hasDataTracks(): 
     267            assert not self.tracks[-1].audio 
     268            leadout = self.tracks[-1].getIndex(1).absolute - 11250 - 150 
     269 
     270        # treat leadout offset as track 0 offset 
     271        result.append(150 + leadout) 
     272 
     273        # offsets of tracks 
     274        for i in range(1, 100): 
     275            try: 
     276                track = self.tracks[i - 1] 
     277                if not track.audio: 
     278                    continue 
     279                offset = track.getIndex(1).absolute + 150 
     280                result.append(offset) 
     281            except IndexError: 
     282                pass 
     283 
     284 
     285        self.debug('CDDB values: %r', result) 
     286        return result 
     287 
     288 
     289 
     290    def getCDDBValues(self): 
     291        """ 
     292        Get all CDDB values needed to calculate disc id and lookup URL. 
     293 
     294        This includes: 
     295         - CDDB disc id 
     296         - number of audio tracks 
     297         - offset of index 1 of each track 
     298         - length of disc in seconds 
     299 
     300        @rtype:   list of int 
     301        """ 
     302        result = [] 
     303 
     304        result.append(self.getAudioTracks()) 
     305 
    249306        # cddb disc id takes into account data tracks 
    250307        # last byte is the number of tracks on the CD 
     
    260317        for track in self.tracks: 
    261318            offset = self.getTrackStart(track.number) + delta 
     319            result.append(offset) 
    262320            debug.append(str(offset)) 
    263321            seconds = offset / common.FRAMES_PER_SECOND 
     
    273331        t = leadoutSeconds - startSeconds 
    274332        debug.append(str(leadoutSeconds + 2)) # 2 is the 150 frame cddb offset 
     333        result.append(leadoutSeconds) 
    275334 
    276335        value = (n % 0xff) << 24 | t << 8 | len(self.tracks) 
     336        result.insert(0, value) 
    277337 
    278338        # compare this debug line to cd-discid output 
     339        self.debug('cddb values: %r', result) 
     340 
    279341        self.debug('cddb disc id debug: %s', 
    280342            " ".join(["%08x" % value, ] + debug)) 
    281343         
    282         return "%08x" % value 
     344        return result 
     345 
     346 
     347    def getCDDBDiscId(self): 
     348        """ 
     349        Calculate the CDDB disc ID. 
     350 
     351        @rtype:   str 
     352        @returns: the 8-character hexadecimal disc ID 
     353        """ 
     354        values = self.getCDDBValues() 
     355        return "%08x" % values[0] 
     356 
    283357 
    284358    def getMusicBrainzDiscId(self): 
  • trunk/morituri/rip/cd.py

    r419 r420  
    138138        prog.metadata = prog.getMusicBrainz(ittoc, mbdiscid) 
    139139 
    140         # stop if the cd is unknown and we don't want to continue 
    141         if not prog.metadata and not self.options.unknown: 
    142             prog.ejectDevice(device) 
    143             return -1 
     140        if not prog.metadata: 
     141            # fall back to FreeDB for lookup 
     142            cddbid = ittoc.getCDDBValues() 
     143            cddbmd = prog.getCDDB(cddbid) 
     144            if cddbmd: 
     145                print 'FreeDB identifies disc as %s' % cddbmd 
     146 
     147            if not self.options.unknown: 
     148                prog.ejectDevice(device) 
     149                return -1 
    144150 
    145151        # now, read the complete index table, which is slower 
Note: See TracChangeset for help on using the changeset viewer.