Skip to content

Instantly share code, notes, and snippets.

@shuantsu
Created September 5, 2023 01:36
Show Gist options
  • Save shuantsu/f71526630b37c334534895e67cfa0c98 to your computer and use it in GitHub Desktop.
Save shuantsu/f71526630b37c334534895e67cfa0c98 to your computer and use it in GitHub Desktop.
total audio length
import tinytag
import glob
import sys
def get_mp3_duration(filename):
"""Function to get the duration of an MP3 file using TinyTag"""
tag = tinytag.TinyTag.get(filename)
return tag.duration
def format_duration_in_minutes_seconds(seconds):
"""Function to format duration in minutes and seconds"""
minutes = int(seconds // 60)
seconds = int(seconds % 60)
return f"{minutes:02}:{seconds:02}"
# Get all files in the current directory with the .mp3 extension
if __name__ == "__main__":
mp3_files = sys.argv[1:]
total_duration = 0
# Iterate through the files and print their formatted durations
for filename in mp3_files:
duration = get_mp3_duration(filename)
total_duration += duration
formatted_duration = format_duration_in_minutes_seconds(duration)
print(f"{filename};{str(duration).replace('.', ',')}")
print('-'*30)
input(format_duration_in_minutes_seconds(total_duration))
call venv\Scripts\activate
main.py %*
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment