Skip to content

Commit

Permalink
remove "lesser" backends, re #48
Browse files Browse the repository at this point in the history
Some backends have features that libdiscid doesn't have.
That is raw reads and CD-TEXT isrcs.

Having discisrc as a backend is redundant, but this might come in handy
for testing purposes. Having different versions of libdiscid and
discisrc.
  • Loading branch information
JonnyJD committed Apr 26, 2013
1 parent 795b198 commit 2995573
Showing 1 changed file with 6 additions and 78 deletions.
84 changes: 6 additions & 78 deletions isrcsubmit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
agent_name = "isrcsubmit.py"
musicbrainz_server = "musicbrainz.org"
# starting with highest priority
backends = ["mediatools", "media_info", "libdiscid", "discisrc", "cdrdao",
"cd-info", "cdda2wav", "icedax", "drutil"]
packages = {"cd-info": "libcdio", "cdda2wav": "cdrtools", "icedax": "cdrkit"}
backends = ["mediatools", "media_info", "libdiscid", "discisrc", "cdrdao"]

import os
import re
Expand Down Expand Up @@ -596,6 +594,8 @@ def gather_isrcs(disc, backend, device):
print("no valid ISRC: %s" % track.isrc)
else:
backend_output.append((track.number, track.isrc))

# redundant to "libdiscid", but this might be handy for prerelease testing
elif backend == "discisrc":
pattern = \
br'Track\s+([0-9]+)\s+:\s+([A-Z]{2})-?([A-Z0-9]{3})-?(\d{2})-?(\d{5})'
Expand All @@ -619,54 +619,8 @@ def gather_isrcs(disc, backend, device):
isrc = decode(isrc)
backend_output.append((track_number, isrc))

# icedax is a fork of the cdda2wav tool
elif backend in ["cdda2wav", "icedax"]:
pattern = \
br'T:\s+([0-9]+)\sISRC:\s+([A-Z]{2})-?([A-Z0-9]{3})-?(\d{2})-?(\d{5})'
try:
p1 = Popen([backend, '-J', '-H', '-D', device], stderr=PIPE)
p2 = Popen(['grep', 'ISRC'], stdin=p1.stderr, stdout=PIPE)
isrcout = p2.stdout
except OSError as err:
backend_error(backend, err)
for line in isrcout:
# there are \n and \r in different places
if debug:
printf(line) # already includes a newline
for text in line.splitlines():
if text.startswith(b"T:"):
m = re.search(pattern, text)
if m is None:
print("can't find ISRC in: %s" % text)
continue
track_number = int(m.group(1))
isrc = m.group(2) + m.group(3) + m.group(4) + m.group(5)
isrc = decode(isrc)
backend_output.append((track_number, isrc))

elif backend == "cd-info":
pattern = \
br'TRACK\s+([0-9]+)\sISRC:\s+([A-Z]{2})-?([A-Z0-9]{3})-?(\d{2})-?(\d{5})'
try:
p = Popen([backend, '-T', '-A', '--no-device-info', '--no-cddb',
'-C', device], stdout=PIPE)
isrcout = p.stdout
except OSError as err:
backend_error(backend, err)
for line in isrcout:
if debug:
printf(line) # already includes a newline
if line.startswith(b"TRACK"):
m = re.search(pattern, line)
if m is None:
print("can't find ISRC in: %s" % line)
continue
track_number = int(m.group(1))
isrc = m.group(2) + m.group(3) + m.group(4) + m.group(5)
isrc = decode(isrc)
backend_output.append((track_number, isrc))

# media_info is a preview version of mediatools, both are for Windows
# this does some kind of raw read
elif backend in ["mediatools", "media_info"]:
pattern = \
br'ISRC\s+([0-9]+)\s+([A-Z]{2})-?([A-Z0-9]{3})-?(\d{2})-?(\d{5})'
Expand Down Expand Up @@ -694,6 +648,7 @@ def gather_isrcs(disc, backend, device):

# cdrdao will create a temp file and we delete it afterwards
# cdrdao is also available for windows
# this will also fetch ISRCs from CD-TEXT
elif backend == "cdrdao":
# no byte pattern, file is opened as unicode
pattern = r'[A-Z]{2}[A-Z0-9]{3}\d{2}\d{5}'
Expand Down Expand Up @@ -742,30 +697,6 @@ def gather_isrcs(disc, backend, device):
except OSError:
pass

# this is the backend included in Mac OS X
# it will take a lot of time because it scans the whole disc
elif backend == "drutil":
pattern = \
br'Track\s+([0-9]+)\sISRC:\s+([A-Z]{2})-?([A-Z0-9]{3})-?(\d{2})-?(\d{5})'
try:
p1 = Popen([backend, 'subchannel', '-drive', device], stdout=PIPE)
p2 = Popen(['grep', 'ISRC'], stdin=p1.stdout, stdout=PIPE)
isrcout = p2.stdout
except OSError as err:
backend_error(backend, err)
for line in isrcout:
if debug:
printf(line) # already includes a newline
if line.startswith(b"Track") and line.find(b"block") > 0:
m = re.search(pattern, line)
if m is None:
print("can't find ISRC in: %s" % line)
continue
track_number = int(m.group(1))
isrc = m.group(2) + m.group(3) + m.group(4) + m.group(5)
isrc = decode(isrc)
backend_output.append((track_number, isrc))

return backend_output


Expand Down Expand Up @@ -837,10 +768,7 @@ def cleanup_isrcs(isrcs):
if backend is None:
verbose_backends = []
for program in backends:
if program in packages:
verbose_backends.append(program + " (" + packages[program] + ")")
else:
verbose_backends.append(program)
verbose_backends.append(program)
print_error("Cannot find a backend to extract the ISRCS!")
print_error2("Isrcsubmit can work with one of the following:")
print_error2(" " + ", ".join(verbose_backends))
Expand Down

0 comments on commit 2995573

Please sign in to comment.