Changeset 561


Ignore:
Timestamp:
28-10-11 19:49:36 (20 months ago)
Author:
thomas
Message:
  • morituri/rip/main.py:
  • morituri/common/musicbrainzngs.py:
  • morituri/common/program.py:
  • morituri/rip/cd.py: Add -R option to rip to record API results for debugging.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r559 r561  
     12011-10-28  Thomas Vander Stichele  <thomas at apestaart dot org> 
     2 
     3        * morituri/rip/main.py: 
     4        * morituri/common/musicbrainzngs.py: 
     5        * morituri/common/program.py: 
     6        * morituri/rip/cd.py: 
     7          Add -R option to rip to record API results for debugging. 
     8 
    192011-10-28  Thomas Vander Stichele  <thomas at apestaart dot org> 
    210 
  • trunk/morituri/common/musicbrainzngs.py

    r560 r561  
    7272    def __init__(self): 
    7373        self.tracks = [] 
     74 
     75def _record(record, which, name, what): 
     76    # optionally record to disc as a JSON serialization 
     77    if record: 
     78        import json 
     79        filename = 'morituri.%s.%s.json' % (which, name) 
     80        handle = open(filename, 'w') 
     81        handle.write(json.dumps(what)) 
     82        handle.close() 
     83        log.info('musicbrainzngs', 'Wrote %s %s to %s', which, name, filename) 
    7484 
    7585 
     
    176186 
    177187# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/ripper.py 
    178 def musicbrainz(discid): 
     188def musicbrainz(discid, record=False): 
    179189    """ 
    180190    Based on a MusicBrainz disc id, get a list of DiscMetadata objects 
     
    190200    from morituri.extern.musicbrainzngs import musicbrainz 
    191201 
    192     results = [] 
     202    ret = [] 
    193203 
    194204    try: 
     
    206216        return None 
    207217 
    208     log.debug('musicbrainz', 'found %d releases for discid %r', 
     218    log.debug('musicbrainzngs', 'found %d releases for discid %r', 
    209219        len(result['disc']['release-list']), 
    210220        discid) 
     221    _record(record, 'releases', discid, result) 
    211222 
    212223    # Display the returned results to the user. 
    213     ret = [] 
    214224 
    215225    for release in result['disc']['release-list']: 
     
    222232        res = musicbrainz.get_release_by_id(release['id'], 
    223233            includes=["artists", "artist-credits", "recordings", "discids"]) 
     234        _record(record, 'release', release['id'], res) 
    224235        release = res['release'] 
    225236 
  • trunk/morituri/common/program.py

    r558 r561  
    5353    outdir = None 
    5454    result = None 
     55 
     56    def __init__(self, record=False): 
     57        """ 
     58        @param record: whether to record results of API calls for playback. 
     59        """ 
     60        self._record = record 
    5561 
    5662    def _getTableCachePath(self): 
     
    225231        for _ in range(0, 4): 
    226232            try: 
    227                 metadatas = musicbrainzngs.musicbrainz(mbdiscid) 
     233                metadatas = musicbrainzngs.musicbrainz(mbdiscid, 
     234                    record=self._record) 
    228235            except musicbrainzngs.NotFoundException, e: 
    229236                break 
  • trunk/morituri/rip/cd.py

    r549 r561  
    111111 
    112112    def do(self, args): 
    113         prog = program.Program() 
     113        prog = program.Program(record=self.getRootCommand().record) 
    114114        runner = task.SyncRunner() 
    115115 
  • trunk/morituri/rip/main.py

    r508 r561  
    7070            configure.version, configure.revision) 
    7171 
     72        self.parser.add_option('-R', '--record', 
     73                          action="store_true", dest="record", 
     74                          help="record API requests for playback") 
    7275        self.parser.add_option('-v', '--version', 
    7376                          action="store_true", dest="version", 
     
    8083            sys.exit(0) 
    8184 
     85        self.record = options.record 
     86 
    8287    def parse(self, argv): 
    8388        log.debug("morituri", "rip %s" % " ".join(argv)) 
Note: See TracChangeset for help on using the changeset viewer.