Skip to content

Instantly share code, notes, and snippets.

@rahul1906
Created April 15, 2020 21:07
Show Gist options
  • Select an option

  • Save rahul1906/082fd3e39274117f551e8395a161ca7c to your computer and use it in GitHub Desktop.

Select an option

Save rahul1906/082fd3e39274117f551e8395a161ca7c to your computer and use it in GitHub Desktop.
Playlist length calculator from subtitle files
from glob import glob
files = glob('*lang_en*') # change the regex condition here
playlist_seconds = 0
for file in files :
with open(file, 'r') as f:
sub_title = f.read()
h, m, s = sub_title.strip().split('-->')[-1].split(',')[0].strip().split(':')
h, m, s = int(h), int(m), int(s)
total_seconds = (h*60*60) + (m*60) + s
playlist_seconds += total_seconds
print("""
Total time {}h {}m
""".format(playlist_seconds//3600, int(playlist_seconds%60)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment