Пример #1
0
def ident(exit_on_fail = True):
    album = None
    if len(config.args) >= 1:
        album = os.path.join(config.catalog_path, config.args[0])
    num_discs = 1
    if len(config.args) >= 2:
        num_discs = int(config.args[1])

    if album and os.path.exists(album):
        raise Exception('Already exists: ' + album)

    djplatform.wait_for_disc()

    for disc in range(num_discs):
        if disc > 0:
            djplatform.eject_disc()
            print()
            print()
            print('--- Insert disc %d of %d ---' % (disc + 1, num_discs))
            djplatform.wait_for_disc()

        lines = get_tracks_from_gracenote(exit_on_fail)

        if album:
            if not os.path.exists(os.path.dirname(album)):
                os.makedirs(os.path.dirname(album))
            with open(album, 'a', encoding='utf-8') as f:
                if disc > 0:
                    f.write('~~~\n')
                for line in lines:
                    f.write(line)
                    f.write('\n')

    if num_discs > 1:
        djplatform.eject_disc()
Пример #2
0
def rip_and_encode(tracks, album_path):
    disc_tracksets = divide_tracks_by_disc(tracks)

    num_discs = len(disc_tracksets)
    disc_num = config.first_disc
    linear_num = 1

    for disc_tracks in disc_tracksets[disc_num - 1:]:
        if disc_num > config.first_disc:
            print(("--- Insert disc %d of %d ---" % (disc_num, num_discs)))
            platform.wait_for_disc()
        disc_num += 1

        assert_disc_length(len(disc_tracks))

        for (track_num, track) in enumerate(disc_tracks, start=1):
            if track == SKIPPED_TRACK:
                continue

            print(('Ripping ' + track['title']))
            if track['set']:
                print(('from ' + track['set']))
            print()

            output_file = os.path.join(
                    platform.music_path, album_path,
                    track['filename'])
            rip_proc = None
            encode_proc = None
            try:
                rip_proc = subprocess.Popen(
                        [platform.bin_cdparanoia(), '%d' % track_num, '-'],
                        stdout=subprocess.PIPE)
                encode_proc = subprocess.Popen(
                        [platform.bin_flac(), '-s', '-', '-o', output_file,
                         '-T', 'TITLE=%s' % (track['title']),
                         '-T', 'ALBUM=%s' % (track['album']),
                         '-T', 'ARTIST=%s' % (track['artist']),
                         '-T', 'GENRE=%s' % (track['genre']),
                         '-T', 'TRACKNUMBER=%d' % linear_num],
                        stdin=rip_proc.stdout, stdout=subprocess.PIPE)
                rip_proc.stdout.close()
                encode_proc.communicate()
                if rip_proc.wait() != 0:
                    raise Exception('Abnormal cdparanoia termination')
                if encode_proc.returncode != 0:
                    raise Exception('Abnormal flac termination')
            except:
                if encode_proc is not None:
                    encode_proc.terminate()
                if rip_proc is not None:
                    rip_proc.terminate()
                os.remove(output_file)
                raise
            linear_num += 1

        platform.eject_disc()
Пример #3
0
def fit():
    album = os.path.join(config.catalog_path, config.args[0])
    num_discs = 1
    if len(config.args) > 1:
        num_discs = int(config.args[1])

    print('--- Insert first disc ---')
    platform.wait_for_disc()

    if not os.path.exists(album):
        ident.ident(exit_on_fail = False)

        if config.editor:
            os.system(config.editor + ' ' + platform.shell_escape(album))
        else:
            raise Exception('Default editor not implemented')

        if num_discs > 1:
            print()
            print()
            print('--- Re-insert first disc ---')
            platform.wait_for_disc()

    rip.rip()
Пример #4
0
def fit():
    album = config.args[0]
    num_discs = 1
    if len(config.args) > 1:
        num_discs = int(config.args[1])

    print("--- Insert first disc ---")
    platform.wait_for_disc()

    if not os.path.exists(album):
        ident.ident()

        if config.editor:
            os.system(config.editor + " " + shlex.quote(album))
        else:
            raise Exception("Default editor not implemented")

        if num_discs > 1:
            print()
            print()
            print("--- Re-insert first disc ---")
            platform.wait_for_disc()

    rip.rip()