Created
June 12, 2017 02:50
-
-
Save yuradmt/e6af74e15597f2550f3485a2306752b5 to your computer and use it in GitHub Desktop.
tracklisting with running times (for youtube)
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
""" | |
create running time for tracks in an album | |
1. song A 02:20 | |
2. song B 01:30 | |
3. song C 04:00 | |
=> | |
1. song A 00:00 | |
2. song B 02:20 | |
3. song C 03:50 | |
""" | |
import sys | |
import re | |
if __name__ == '__main__': | |
with open(sys.argv[1], mode='r') as f: | |
running_time = 0 # seconds | |
for l in f.readlines(): | |
# track number follwed by . or ), track title and track duration with or | |
# without parenthesis | |
match = re.search(r'^(\d+[\.\)]+)(.+ )[\(\[]*(\d+):(\d+)[\)\]]*', l) | |
track_number = match.group(1) | |
track_title = match.group(2) | |
track_min = match.group(3) | |
track_sec = match.group(4) | |
output = '' | |
running_hrs = 0 | |
running_mins = running_time // 60 | |
running_sec = running_time % 60 | |
if running_mins > 60: | |
running_hrs = running_mins // 60 | |
running_mins = running_mins % 60 | |
output = '{}{}{:02d}:{:02d}:{:02d}'.format(track_number, | |
track_title, | |
running_hrs, | |
running_mins, | |
running_sec) | |
else: | |
output = '{}{}{:02d}:{:02d}'.format(track_number, | |
track_title, | |
running_mins, | |
running_sec) | |
print(output) | |
running_time += int(track_min) * 60 + int(track_sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment