Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save thwaller/b74a0abf051c9504d986b57d78bbf01a to your computer and use it in GitHub Desktop.

Select an option

Save thwaller/b74a0abf051c9504d986b57d78bbf01a to your computer and use it in GitHub Desktop.

Revisions

  1. @kolen kolen revised this gist Jun 2, 2018. 1 changed file with 22 additions and 0 deletions.
    22 changes: 22 additions & 0 deletions eac_log_to_musicbrainz_discid.py
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,28 @@
    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
  2. @kolen kolen revised this gist Jan 4, 2011. 1 changed file with 18 additions and 3 deletions.
    21 changes: 18 additions & 3 deletions eac_log_to_musicbrainz_discid.py
    Original file line number Diff line number Diff line change
    @@ -10,13 +10,24 @@
    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()
    if re.match(r"\s*Track.*Start.*Length.*Start sector.*End sector", line):
    # 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

    @@ -45,7 +56,11 @@ def calculate_mb_toc_numbers(eac_entries):
    """
    eac = list(eac_entries)
    num_tracks = len(eac)
    print "Num tracks: %d" % num_tracks

    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
    @@ -54,4 +69,4 @@ def calculate_mb_toc_numbers(eac_entries):
    #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)
    webbrowser.open("http://musicbrainz.org/bare/cdlookup.html?toc=%s" % mb_toc_urlpart)
  3. @kolen kolen revised this gist Jan 4, 2011. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions eac_log_to_musicbrainz_discid.py
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,8 @@
    """
    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.
    """

    import re
  4. @kolen kolen created this gist Jan 4, 2011.
    55 changes: 55 additions & 0 deletions eac_log_to_musicbrainz_discid.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    #!/usr/bin/python
    """
    Reads EAC log, generates musicbrainz disc TOC listing for use as discid.
    Opens browser with discid query on musicbrainz.org.
    """

    import re
    import sys
    import webbrowser

    def filter_toc_entries(lines):
    """
    Take iterator of lines, return iterator of toc entries
    """
    while True:
    line = lines.next()
    if re.match(r"\s*Track.*Start.*Length.*Start sector.*End sector", line):
    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)
    print "Num tracks: %d" % num_tracks
    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)