Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two new command-line options #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions morituri/common/mbngs.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def getIds(self):
joinString=";")


def _getMetadata(releaseShort, release, discid):
def _getMetadata(releaseShort, release, discid, country=None):
"""
@type release: C{dict}
@param release: a release dict as returned in the value for key release
Expand All @@ -160,6 +160,10 @@ def _getMetadata(releaseShort, release, discid):

assert release['id'], 'Release does not have an id'

if 'country' in release and country and release['country'] != country:
log.warning('program', '%r was not released in %r', release, country)
return None

discMD = DiscMetadata()

discMD.releaseType = releaseShort.get('release-group', {}).get('type')
Expand Down Expand Up @@ -251,7 +255,7 @@ def _getMetadata(releaseShort, release, discid):
# ripper.py


def musicbrainz(discid, record=False):
def musicbrainz(discid, country=None, record=False):
"""
Based on a MusicBrainz disc id, get a list of DiscMetadata objects
for the given disc id.
Expand Down Expand Up @@ -305,7 +309,7 @@ def musicbrainz(discid, record=False):
formatted = json.dumps(releaseDetail, sort_keys=False, indent=4)
log.debug('program', 'release %s' % formatted)

md = _getMetadata(release, releaseDetail, discid)
md = _getMetadata(release, releaseDetail, discid, country)
if md:
log.debug('program', 'duration %r', md.duration)
ret.append(md)
Expand Down
28 changes: 22 additions & 6 deletions morituri/common/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ def getCDDB(self, cddbdiscid):

return None

def getMusicBrainz(self, ittoc, mbdiscid, release=None):
def getMusicBrainz(self, ittoc, mbdiscid, release=None, country=None, prompt=False):
"""
@type ittoc: L{morituri.image.table.Table}
"""
Expand All @@ -332,6 +332,7 @@ def getMusicBrainz(self, ittoc, mbdiscid, release=None):
for _ in range(0, 4):
try:
metadatas = mbngs.musicbrainz(mbdiscid,
country=country,
record=self._record)
except mbngs.NotFoundException, e:
break
Expand Down Expand Up @@ -364,12 +365,29 @@ def getMusicBrainz(self, ittoc, mbdiscid, release=None):
self._stdout.write('URL : %s\n' % metadata.url)
self._stdout.write('Release : %s\n' % metadata.mbid)
self._stdout.write('Type : %s\n' % metadata.releaseType)
if metadata.barcode:
self._stdout.write("Barcode : %s\n" % metadata.barcode)
if metadata.catalogNumber:
self._stdout.write("Cat no : %s\n" % metadata.catalogNumber)

delta = abs(metadata.duration - ittoc.duration())
if not delta in deltas:
deltas[delta] = []
deltas[delta].append(metadata)

lowest = None

if not release and len(metadatas) > 1:
# Select the release that most closely matches the duration.
lowest = min(deltas.keys())

if prompt:
guess = (deltas[lowest])[0].mbid
release = raw_input("\nPlease select a release [%s]: " % guess)

if not release:
release = guess

if release:
metadatas = [m for m in metadatas if m.url.endswith(release)]
self.debug('Asked for release %r, only kept %r',
Expand All @@ -388,12 +406,10 @@ def getMusicBrainz(self, ittoc, mbdiscid, release=None):
"but none of the found releases match\n" % release)
return
else:
# Select the release that most closely matches the duration.
lowest = min(deltas.keys())

# If we have multiple, make sure they match
metadatas = deltas[lowest]
if lowest:
metadatas = deltas[lowest]

# If we have multiple, make sure they match
if len(metadatas) > 1:
artist = metadatas[0].artist
releaseTitle = metadatas[0].releaseTitle
Expand Down
10 changes: 9 additions & 1 deletion morituri/rip/cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def addOptions(self):
self.parser.add_option('-R', '--release-id',
action="store", dest="release_id",
help="MusicBrainz release id to match to (if there are multiple)")
self.parser.add_option('-p', '--prompt',
action="store_true", dest="prompt",
help="Prompt if there are multiple matching releases")
self.parser.add_option('-c', '--country',
action="store", dest="country",
help="Filter releases by country")


def do(self, args):
Expand Down Expand Up @@ -89,7 +95,9 @@ def do(self, args):

self.program.metadata = self.program.getMusicBrainz(self.ittoc,
self.mbdiscid,
release=self.options.release_id)
release=self.options.release_id,
country=self.options.country,
prompt=self.options.prompt)

if not self.program.metadata:
# fall back to FreeDB for lookup
Expand Down
10 changes: 9 additions & 1 deletion morituri/rip/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ def addOptions(self):
self.parser.add_option('-R', '--release-id',
action="store", dest="release_id",
help="MusicBrainz release id to match to (if there are multiple)")
self.parser.add_option('-p', '--prompt',
action="store_true", dest="prompt",
help="Prompt if there are multiple matching releases")
self.parser.add_option('-c', '--country',
action="store", dest="country",
help="Filter releases by country")


def do(self, args):
Expand All @@ -128,7 +134,9 @@ def do(self, args):
self.stdout.write("MusicBrainz lookup URL %s\n" %
cueImage.table.getMusicBrainzSubmitURL())
prog.metadata = prog.getMusicBrainz(cueImage.table, mbdiscid,
release=self.options.release_id)
release=self.options.release_id,
country=self.options.country,
prompt=self.options.prompt)

if not prog.metadata:
print 'Not in MusicBrainz database, skipping'
Expand Down