Skip to content

Instantly share code, notes, and snippets.

@musale
Last active February 7, 2017 10:23
Show Gist options
  • Save musale/265ef54ec95adfe8f3bb30fb158b9384 to your computer and use it in GitHub Desktop.
Save musale/265ef54ec95adfe8f3bb30fb158b9384 to your computer and use it in GitHub Desktop.
This is a script that I use to rename my youtube-dl downloaded files. I just remove the extra ids at the end and rename with appropriate extension
# /usr/bin/env python
# ensure that you run the script in the folder containing
# the files to be renamed
import os
for filename in os.listdir("."):
# split the file name into 3 parts
# normal filename looks like this for mp3
# 'Born Again - Third Day-4m_dP2n-5W8.mp3'
split_val = filename.split('-')
print split_val
# concatenate the new name
# my extension is .mp3 so I append that
new_name = "%s-%s.mp3" % (split_val[0], split_val[1])
print new_name
# rename the file
os.rename(filename, new_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment