def search_by_cue(name): """ search by .cue :param name: :return: """ with open(name, "rb") as f: d = f.read() # c = cuelib.cue_parse(d) s = ' '.join((c.performer, c.title)).strip() if not s: return name # return s
def cue_tagger(releases, name, skip=0): """ .cue tagger :param releases: :param name: :param skip: skip tracks before tagging (<0 for old, >0 for new) :return: return Cue() and save new cue as "name.<DISCOGS_ID>.ext" """ if skip < 0: cue_skip = abs(skip) else: cue_skip = 0 # cue_rems = [] r = releases[0] if len(releases) > 1: logger("warning: too many releases (%r), using first only {%r}" % (len(releases), r)) # r_dump = dump_release(r) if not r_dump: return None # r_info = r_dump[0] r_id, r_artists, r_title, r_year, r_formats, r_labels, r_genres = r_info if not os.path.isfile(name): logger("warning: can't find {%r}" % name) r_tracks = get_tracks(r, duration=False) tracks = [(get_track_title(r_track, "")[0], "00:00:00") for r_track in r_tracks] data = cuelib.cue_maker(tracks=tracks) else: with open(name, "rb") as f: data = f.read() # # cue = cuelib.cue_parse(data) # head cue.performer = r_artists or cue.performer cue.title = r_title or cue.title # REMs cue_rems.append(("DISCOGS", str(r_id))) cue_rems.append(("LABEL", r_labels)) cue_rems.append(("DATE", r_year)) cue_rems.append(("GENRE", r_genres)) [cue.rems(*v) for v in cue_rems if v[-1]] # tracks c_tracks = cue.tracks r_tracks = get_tracks(r, duration=False) if len(r_tracks) - skip < len(c_tracks): logger("warning: release tracks(%d) < cue tracks (%d) (skip %d)" % (len(r_tracks), len(c_tracks), skip)) # for n_track in range(len(r_tracks)): try: c_track = c_tracks[n_track + cue_skip] r_track = r_tracks[n_track + skip] title, extra = get_track_title(r_track, c_track.title) c_track.performer = get_track_artist( r_track, r_artists or c_track.performer) c_track.title = title if extra: c_track.rems("CREDITS", extra) # except IndexError: break # # # save new .cue if cue: _name, _ext = os.path.splitext(name) _name = "%s.%010d" % (_name, r_id) cue_name = _name + _ext with open(cue_name, "wb") as f: s = cue.dumps() f.write(s) # else: cue_name = '' # return cue, cue_name
def cue_tagger(releases, name, skip=0): """ .cue tagger :param releases: :param name: :param skip: skip tracks before tagging (<0 for old, >0 for new) :return: return Cue() and save new cue as "name.<DISCOGS_ID>.ext" """ if skip < 0: cue_skip = abs(skip) else: cue_skip = 0 # cue_rems = [] r = releases[0] if len(releases) > 1: logger("warning: too many releases (%r), using first only {%r}" % (len(releases), r)) # r_dump = dump_release(r) if not r_dump: return None # r_info = r_dump[0] r_id, r_artists, r_title, r_year, r_formats, r_labels, r_genres = r_info if not os.path.isfile(name): logger("warning: can't find {%r}" % name) r_tracks = get_tracks(r, duration=False) tracks = [(get_track_title(r_track, "")[0], "00:00:00") for r_track in r_tracks] data = cuelib.cue_maker(tracks=tracks) else: with open(name, "rb") as f: data = f.read() # # cue = cuelib.cue_parse(data) # head cue.performer = r_artists or cue.performer cue.title = r_title or cue.title # REMs cue_rems.append(("DISCOGS", str(r_id))) cue_rems.append(("LABEL", r_labels)) cue_rems.append(("DATE", r_year)) cue_rems.append(("GENRE", r_genres)) [cue.rems(*v) for v in cue_rems if v[-1]] # tracks c_tracks = cue.tracks r_tracks = get_tracks(r, duration=False) if len(r_tracks)-skip < len(c_tracks): logger("warning: release tracks(%d) < cue tracks (%d) (skip %d)" % (len(r_tracks), len(c_tracks), skip)) # for n_track in range(len(r_tracks)): try: c_track = c_tracks[n_track + cue_skip] r_track = r_tracks[n_track + skip] title, extra = get_track_title(r_track, c_track.title) c_track.performer = get_track_artist(r_track, r_artists or c_track.performer) c_track.title = title if extra: c_track.rems("CREDITS", extra) # except IndexError: break # # # save new .cue if cue: _name, _ext = os.path.splitext(name) _name = "%s.%010d" % (_name, r_id) cue_name = _name + _ext with open(cue_name, "wb") as f: s = cue.dumps() f.write(s) # else: cue_name = '' # return cue, cue_name