Skip to content

Instantly share code, notes, and snippets.

@LoneRabbit
Last active May 8, 2022 17:05
Show Gist options
  • Save LoneRabbit/2914aa1d0e4df91d7065ecb3ced8d38d to your computer and use it in GitHub Desktop.
Save LoneRabbit/2914aa1d0e4df91d7065ecb3ced8d38d to your computer and use it in GitHub Desktop.
Tracklisting script for timestamps on YouTube playlist videos. Only works with .mp3 files with title metadata.
import eyed3
import os
cumlength = 0
ntrack = 0
path = input("Path to tracks: ")
path.strip('"') #Remove quotes
title = []
trackno = []
length = []
#PARSING
for root, dirs, files in os.walk(os.path.abspath(path)):
for file in files:
if file.endswith(".mp3"):
#print(os.path.join(root, file))
#Mutagen:
##audio = MP3(os.path.join(root, file))
##title = TIT2(os.path.join(root, file))
##length = audio.info.length
#EyeD3:
title.append(eyed3.load(os.path.join(root, file)).tag.title)
trackno.append((eyed3.load(os.path.join(root, file)).tag.track_num)[0])
length.append(eyed3.load(os.path.join(root, file)).info.time_secs)
ntrack = ntrack + 1
for i in range(ntrack):
for x in range(ntrack):
if trackno[x] == (i+1):
minute = int(cumlength//60)
remainder = str(int(cumlength % 60))
remainder = remainder.zfill(2)
if minute >=60:
hour = minute//60
minute = minute-(60*hour)
print(hour, ":", minute, ":", remainder, " ", title[x], sep='')
else:
print(minute, ":", remainder, " ", title[x], sep='')
cumlength = cumlength + length[x] #CUMulative length
#Conclusion: This probably took me way more time than to just actually do it manually. Did this from around 3 or 4pm now it's 5pm.
#And I took another day to make it list in the correct order... OMG I finally did it. My god.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment