* 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:
@@ -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>
|
2011-10-28 Thomas Vander Stichele <thomas at apestaart dot org>
|
||||||
|
|
||||||
* morituri/common/musicbrainzngs.py:
|
* morituri/common/musicbrainzngs.py:
|
||||||
|
|||||||
@@ -72,6 +72,16 @@ class DiscMetadata(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tracks = []
|
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):
|
def _getMetadata(release, discid):
|
||||||
"""
|
"""
|
||||||
@@ -175,7 +185,7 @@ def _getMetadata(release, discid):
|
|||||||
|
|
||||||
|
|
||||||
# see http://bugs.musicbrainz.org/browser/python-musicbrainz2/trunk/examples/ripper.py
|
# 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
|
Based on a MusicBrainz disc id, get a list of DiscMetadata objects
|
||||||
for the given disc id.
|
for the given disc id.
|
||||||
@@ -189,7 +199,7 @@ def musicbrainz(discid):
|
|||||||
log.debug('musicbrainz', 'looking up results for discid %r', discid)
|
log.debug('musicbrainz', 'looking up results for discid %r', discid)
|
||||||
from morituri.extern.musicbrainzngs import musicbrainz
|
from morituri.extern.musicbrainzngs import musicbrainz
|
||||||
|
|
||||||
results = []
|
ret = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = musicbrainz.get_releases_by_discid(discid,
|
result = musicbrainz.get_releases_by_discid(discid,
|
||||||
@@ -205,12 +215,12 @@ def musicbrainz(discid):
|
|||||||
if len(result) == 0:
|
if len(result) == 0:
|
||||||
return None
|
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']),
|
len(result['disc']['release-list']),
|
||||||
discid)
|
discid)
|
||||||
|
_record(record, 'releases', discid, result)
|
||||||
|
|
||||||
# Display the returned results to the user.
|
# Display the returned results to the user.
|
||||||
ret = []
|
|
||||||
|
|
||||||
for release in result['disc']['release-list']:
|
for release in result['disc']['release-list']:
|
||||||
log.debug('program', 'result %r: artist %r, title %r' % (
|
log.debug('program', 'result %r: artist %r, title %r' % (
|
||||||
@@ -221,6 +231,7 @@ def musicbrainz(discid):
|
|||||||
|
|
||||||
res = musicbrainz.get_release_by_id(release['id'],
|
res = musicbrainz.get_release_by_id(release['id'],
|
||||||
includes=["artists", "artist-credits", "recordings", "discids"])
|
includes=["artists", "artist-credits", "recordings", "discids"])
|
||||||
|
_record(record, 'release', release['id'], res)
|
||||||
release = res['release']
|
release = res['release']
|
||||||
|
|
||||||
md = _getMetadata(release, discid)
|
md = _getMetadata(release, discid)
|
||||||
|
|||||||
@@ -53,6 +53,12 @@ class Program(log.Loggable):
|
|||||||
outdir = None
|
outdir = None
|
||||||
result = 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):
|
def _getTableCachePath(self):
|
||||||
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache',
|
path = os.path.join(os.path.expanduser('~'), '.morituri', 'cache',
|
||||||
'table')
|
'table')
|
||||||
@@ -224,7 +230,8 @@ class Program(log.Loggable):
|
|||||||
|
|
||||||
for _ in range(0, 4):
|
for _ in range(0, 4):
|
||||||
try:
|
try:
|
||||||
metadatas = musicbrainzngs.musicbrainz(mbdiscid)
|
metadatas = musicbrainzngs.musicbrainz(mbdiscid,
|
||||||
|
record=self._record)
|
||||||
except musicbrainzngs.NotFoundException, e:
|
except musicbrainzngs.NotFoundException, e:
|
||||||
break
|
break
|
||||||
except musicbrainzngs.MusicBrainzException, e:
|
except musicbrainzngs.MusicBrainzException, e:
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ filling in the variables and expanding the file extension. Variables are:
|
|||||||
"should be the same.")
|
"should be the same.")
|
||||||
|
|
||||||
def do(self, args):
|
def do(self, args):
|
||||||
prog = program.Program()
|
prog = program.Program(record=self.getRootCommand().record)
|
||||||
runner = task.SyncRunner()
|
runner = task.SyncRunner()
|
||||||
|
|
||||||
def function(r, t):
|
def function(r, t):
|
||||||
|
|||||||
@@ -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)",
|
log.debug("morituri", "This is morituri version %s (%s)",
|
||||||
configure.version, configure.revision)
|
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',
|
self.parser.add_option('-v', '--version',
|
||||||
action="store_true", dest="version",
|
action="store_true", dest="version",
|
||||||
help="show version information")
|
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
|
print "rip %s" % configure.version
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
self.record = options.record
|
||||||
|
|
||||||
def parse(self, argv):
|
def parse(self, argv):
|
||||||
log.debug("morituri", "rip %s" % " ".join(argv))
|
log.debug("morituri", "rip %s" % " ".join(argv))
|
||||||
logcommand.LogCommand.parse(self, argv)
|
logcommand.LogCommand.parse(self, argv)
|
||||||
|
|||||||
Reference in New Issue
Block a user