Skip to content

Instantly share code, notes, and snippets.

@maxcohn
Created February 6, 2019 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxcohn/77b5333ca879e8beeb6acf56f70d1f6f to your computer and use it in GitHub Desktop.
Save maxcohn/77b5333ca879e8beeb6acf56f70d1f6f to your computer and use it in GitHub Desktop.
Calculates the total amount of time of MP3 files in the current directory. Uses Mutagen library
# get total time of all mp3 files in the current directory (1/21/19)
import os
from mutagen.mp3 import MP3
total = 0
for file in os.listdir("."):
if not file.endswith(".mp3"): continue
audio = MP3(file)
total += audio.info.length
hours = total / 60 / 60
print(f"Total hours = {hours}")
input("Press enter to exit.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment