Last active
January 12, 2024 22:23
-
-
Save kolen/765526 to your computer and use it in GitHub Desktop.
Reads EAC log, generates musicbrainz disc TOC listing for use as discid. Opens browser with discid query on musicbrainz.org.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
""" | |
Reads EAC log, generates musicbrainz disc TOC listing for use as discid. | |
Opens browser with discid query on musicbrainz.org. | |
Warning: may work wrong for discs having data tracks. May generate wrong results on other non-standard cases. | |
MIT License | |
Copyright (c) 2018 Konstantin Mochalov | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all | |
copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
SOFTWARE. | |
""" | |
import re | |
import sys | |
import webbrowser | |
class NotSupportedTOCError(Exception): | |
pass | |
def filter_toc_entries(lines): | |
""" | |
Take iterator of lines, return iterator of toc entries | |
""" | |
while True: | |
line = lines.next() | |
# to allow internationalized EAC output where column headings | |
# may differ | |
if re.match(r""" \s* | |
.+\s+ \| (?#track) | |
\s+.+\s+ \| (?#start) | |
\s+.+\s+ \| (?#length) | |
\s+.+\s+ \| (?#start sec) | |
\s+.+\s*$ (?#end sec) | |
""", line, re.X): | |
lines.next() | |
break | |
while True: | |
line = lines.next() | |
m = re.match(r""" | |
^\s* | |
(?P<num>\d+) | |
\s*\|\s* | |
(?P<start_time>[0-9:.]+) | |
\s*\|\s* | |
(?P<length_time>[0-9:.]+) | |
\s*\|\s* | |
(?P<start_sector>\d+) | |
\s*\|\s* | |
(?P<end_sector>\d+) | |
\s*$ | |
""", line, re.X) | |
if not m: | |
break | |
yield m.groupdict() | |
def calculate_mb_toc_numbers(eac_entries): | |
""" | |
Take iterator of toc entries, return list of numbers for musicbrainz disc id | |
""" | |
eac = list(eac_entries) | |
num_tracks = len(eac) | |
tracknums = [int(e['num']) for e in eac] | |
if range(1,num_tracks+1) != tracknums: | |
raise NotSupportedTOCError("Non-standard track number sequence: %s", tracknums) | |
leadout_offset = int(eac[-1]['end_sector']) + 150 + 1 | |
offsets = [(int(x['start_sector']) + 150) for x in eac] | |
return [1, num_tracks, leadout_offset] + offsets | |
f = open(sys.argv[1]) | |
#conv = (line.decode(sys.argv[2]) for line in f) | |
mb_toc_urlpart = "%20".join(str(x) for x in calculate_mb_toc_numbers(filter_toc_entries(f))) | |
webbrowser.open("http://musicbrainz.org/bare/cdlookup.html?toc=%s" % mb_toc_urlpart) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Work as intended even under Windows: install Python 2.7.14 x64 and drag'n'drop EAC *.log file to script, it opens the page with MusicBrainz DiscID submit/merge functions.