Vinfall revidoval tento gist . Přejít na revizi
1 file changed, 72 insertions
cue_to_flac.py(vytvořil soubor)
@@ -0,0 +1,72 @@ | |||
1 | + | #!/usr/bin/env python3 | |
2 | + | # -*- coding: utf-8 -*- | |
3 | + | ||
4 | + | # Based on GitHub Gist | |
5 | + | # https://gist.github.com/Theldus/bf7b9fd7370f4ea4c57da5cb596e9da9 | |
6 | + | # Minor changes to make it usable in Python 3.10 | |
7 | + | ||
8 | + | cue_file = 'CDImage.cue' | |
9 | + | ||
10 | + | f = open(cue_file, 'r', encoding='utf-8') | |
11 | + | d = f.read().splitlines() | |
12 | + | ||
13 | + | general = {} | |
14 | + | ||
15 | + | tracks = [] | |
16 | + | ||
17 | + | current_file = None | |
18 | + | ||
19 | + | for line in d: | |
20 | + | if line.startswith('REM GENRE '): | |
21 | + | general['genre'] = ' '.join(line.split(' ')[2:]) | |
22 | + | if line.startswith('REM DATE '): | |
23 | + | general['date'] = ' '.join(line.split(' ')[2:]) | |
24 | + | if line.startswith('PERFORMER '): | |
25 | + | general['artist'] = ' '.join(line.split(' ')[1:]).replace('"', '') | |
26 | + | if line.startswith('TITLE '): | |
27 | + | general['album'] = ' '.join(line.split(' ')[1:]).replace('"', '') | |
28 | + | if line.startswith('FILE '): | |
29 | + | current_file = ' '.join(line.split(' ')[1:-1]).replace('"', '') | |
30 | + | ||
31 | + | if line.startswith(' TRACK '): | |
32 | + | track = general.copy() | |
33 | + | track['track'] = int(line.strip().split(' ')[1], 10) | |
34 | + | ||
35 | + | tracks.append(track) | |
36 | + | ||
37 | + | if line.startswith(' TITLE '): | |
38 | + | tracks[-1]['title'] = ' '.join(line.strip().split(' ')[1:]).replace('"', '') | |
39 | + | if line.startswith(' PERFORMER '): | |
40 | + | tracks[-1]['artist'] = ' '.join(line.strip().split(' ')[1:]).replace('"', '') | |
41 | + | if line.startswith(' INDEX 01 '): | |
42 | + | t = list(map(int, ' '.join(line.strip().split(' ')[2:]).replace('"', '').split(':'))) | |
43 | + | tracks[-1]['start'] = 60 * t[0] + t[1] + t[2] / 100.0 | |
44 | + | ||
45 | + | for i in range(len(tracks)): | |
46 | + | if i != len(tracks) - 1: | |
47 | + | tracks[i]['duration'] = tracks[i + 1]['start'] - tracks[i]['start'] | |
48 | + | ||
49 | + | for track in tracks: | |
50 | + | metadata = { | |
51 | + | 'artist': track['artist'], | |
52 | + | 'title': track['title'], | |
53 | + | 'album': track['album'], | |
54 | + | 'track': str(track['track']) + '/' + str(len(tracks)) | |
55 | + | } | |
56 | + | ||
57 | + | if 'genre' in track: | |
58 | + | metadata['genre'] = track['genre'] | |
59 | + | if 'date' in track: | |
60 | + | metadata['date'] = track['date'] | |
61 | + | ||
62 | + | cmd = 'ffmpeg' | |
63 | + | cmd += ' -i "%s"' % current_file | |
64 | + | cmd += ' -ss %.2d:%.2d:%.2d' % (track['start'] / 60 / 60, track['start'] / 60 % 60, int(track['start'] % 60)) | |
65 | + | ||
66 | + | if 'duration' in track: | |
67 | + | cmd += ' -t %.2d:%.2d:%.2d' % (track['duration'] / 60 / 60, track['duration'] / 60 % 60, int(track['duration'] % 60)) | |
68 | + | ||
69 | + | cmd += ' ' + ' '.join('-metadata %s="%s"' % (k, v) for (k, v) in metadata.items()) | |
70 | + | cmd += ' "%.2d - %s - %s.flac"' % (track['track'], track['artist'], track['title']) | |
71 | + | ||
72 | + | print(cmd) |
Novější
Starší