Created
July 15, 2018 09:40
-
-
Save oneamitj/0790c6d484058a9afb28c3a2ac9a4695 to your computer and use it in GitHub Desktop.
Correctly rename youtube downloaded official songs with Artist and Title.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import stagger | |
from stagger.id3 import * | |
import os | |
dir_name = "/path/to/dir/with/songs" | |
file_list = os.listdir(dir_name) | |
# Filename in format = "Ariana Grande - No Tears Left To Cry.mp3" | |
for filename in file_list: | |
full_filename = dir_name + "/" + filename | |
print(full_filename) | |
tag = stagger.read_tag(full_filename) | |
splited_name = tag.title.split(" - ") | |
if len(splited_name) < 2: splited_name.append(splited_name[0]) | |
artist = splited_name[0].strip() | |
title = splited_name[1].replace("[", "").replace("]", "").replace("(", "").replace(")", "").replace("|", "").replace("'", "").replace('"', "").replace("video", "").replace("Video", "").replace("Offical", "").replace("Music", "").strip() | |
tag.title = title # Alternative, friendlier API | |
tag.album_artist = artist | |
tag.artist = artist | |
tag.write() | |
os.rename(full_filename, dir_name + "/" + title + ".mp3") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment