* 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.
This commit is contained in:
Thomas Vander Stichele
2011-10-28 17:49:36 +00:00
parent 919076e720
commit c2838ad05c
5 changed files with 37 additions and 6 deletions

View File

@@ -1,3 +1,11 @@
2011-10-28 Thomas Vander Stichele <thomas at apestaart dot org>
* 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.
2011-10-28 Thomas Vander Stichele <thomas at apestaart dot org>
* morituri/common/musicbrainzngs.py:

View File

@@ -72,6 +72,16 @@ class DiscMetadata(object):
def __init__(self):
self.tracks = []
def _record(record, which, name, what):
# optionally record to disc as a JSON serialization
if record:
import json
filename = 'morituri.%s.%s.json' % (which, name)
handle = open(filename, 'w')
handle.write(json.dumps(what))
handle.close()
log.info('musicbrainzngs', 'Wrote %s %s to %s', which, name, filename)
def _getMetadata(release, discid):
"""
@@ -175,7 +185,7 @@ def _getMetadata(release, discid):
# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/ripper.py
def musicbrainz(discid):
def musicbrainz(discid, record=False):
"""
Based on a MusicBrainz disc id, get a list of DiscMetadata objects
for the given disc id.
@@ -189,7 +199,7 @@ def musicbrainz(discid):
log.debug('musicbrainz', 'looking up results for discid %r', discid)
from morituri.extern.musicbrainzngs import musicbrainz
results = []
ret = []
try:
result = musicbrainz.get_releases_by_discid(discid,
@@ -205,12 +215,12 @@ def musicbrainz(discid):
if len(result) == 0:
return None
log.debug('musicbrainz', 'found %d releases for discid %r',
log.debug('musicbrainzngs', 'found %d releases for discid %r',
len(result['disc']['release-list']),
discid)
_record(record, 'releases', discid, result)
# Display the returned results to the user.
ret = []
for release in result['disc']['release-list']:
log.debug('program', 'result %r: artist %r, title %r' % (
@@ -221,6 +231,7 @@ def musicbrainz(discid):
res = musicbrainz.get_release_by_id(release['id'],
includes=["artists", "artist-credits", "recordings", "discids"])
_record(record, 'release', release['id'], res)
release = res['release']
md = _getMetadata(release, discid)

View File

@@ -53,6 +53,12 @@ class Program(log.Loggable):
outdir = None
result = None
def __init__(self, record=False):
"""
@param record: whether to record results of API calls for playback.
"""
self._record = record
def _getTableCachePath(self):
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache',
'table')
@@ -224,7 +230,8 @@ class Program(log.Loggable):
for _ in range(0, 4):
try:
metadatas = musicbrainzngs.musicbrainz(mbdiscid)
metadatas = musicbrainzngs.musicbrainz(mbdiscid,
record=self._record)
except musicbrainzngs.NotFoundException, e:
break
except musicbrainzngs.MusicBrainzException, e:

View File

@@ -110,7 +110,7 @@ filling in the variables and expanding the file extension. Variables are:
"should be the same.")
def do(self, args):
prog = program.Program()
prog = program.Program(record=self.getRootCommand().record)
runner = task.SyncRunner()
def function(r, t):

View File

@@ -69,6 +69,9 @@ You can get help on subcommands by using the -h option to the subcommand.
log.debug("morituri", "This is morituri version %s (%s)",
configure.version, configure.revision)
self.parser.add_option('-R', '--record',
action="store_true", dest="record",
help="record API requests for playback")
self.parser.add_option('-v', '--version',
action="store_true", dest="version",
help="show version information")
@@ -79,6 +82,8 @@ You can get help on subcommands by using the -h option to the subcommand.
print "rip %s" % configure.version
sys.exit(0)
self.record = options.record
def parse(self, argv):
log.debug("morituri", "rip %s" % " ".join(argv))
logcommand.LogCommand.parse(self, argv)