[SCM] morituri/master: * 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.
js at users.alioth.debian.org
js at users.alioth.debian.org
Sun Oct 19 20:09:37 UTC 2014
The following commit has been merged in the master branch:
commit c2838ad05ca02c663bdde2b17bb2ccf69e483810
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date: Fri Oct 28 17:49:36 2011 +0000
* 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.
diff --git a/ChangeLog b/ChangeLog
index 314a23f..77c5e6b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
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:
Fix case of metadata not having length.
Fix case of release not having a date.
diff --git a/morituri/common/musicbrainzngs.py b/morituri/common/musicbrainzngs.py
index fc759f6..e596548 100644
--- a/morituri/common/musicbrainzngs.py
+++ b/morituri/common/musicbrainzngs.py
@@ -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)
diff --git a/morituri/common/program.py b/morituri/common/program.py
index 00f6f76..9f71bff 100644
--- a/morituri/common/program.py
+++ b/morituri/common/program.py
@@ -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:
diff --git a/morituri/rip/cd.py b/morituri/rip/cd.py
index 2a1a622..a6dc57e 100644
--- a/morituri/rip/cd.py
+++ b/morituri/rip/cd.py
@@ -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):
diff --git a/morituri/rip/main.py b/morituri/rip/main.py
index a6a6dca..afd749b 100644
--- a/morituri/rip/main.py
+++ b/morituri/rip/main.py
@@ -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)
--
morituri packaging
More information about the pkg-multimedia-commits
mailing list