-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYouTubeDownloadWrapper.py
More file actions
70 lines (59 loc) · 3.66 KB
/
Copy pathYouTubeDownloadWrapper.py
File metadata and controls
70 lines (59 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
import sys, os, glob, subprocess
import music_tag # install with pip install yt-dlp, music-tag
print("E'lo's YouTube Playlist Downloader, Renamer, and Tagger")
if len(sys.argv) >= 1:
folder = sys.argv[1].split("\" ")[0]
#print(sys.argv[1].split("\" ")[0])
else:
folder = input("Enter the folder you would like to use: ")
if len(sys.argv) >= 2:
playlist = sys.argv[1].split("\" ")[1]
else:
playlist = input("Enter the playlist you would like to download: ")
# fix post processor warning
# Seems to do weird folder stuff currently...
subprocess.run(['yt-dlp', '--download-archive', 'downloaded.txt', '--no-post-overwrites', '-ciwx', '--audio-format', 'mp3', '-o', '%(channel)s_%(title)s.%(ext)s', '--ffmpeg-location', 'C:\\Programs\\ffmpeg\\bin', '--postprocessor-args', '-af dynaudnorm', playlist, '--use-postprocessor', 'DeArrow:when=pre_process'], cwd=folder)
files = glob.glob(folder + '/**/*.mp3', recursive=True)
for song in files:
songInfo = music_tag.load_file(song)
title = songInfo['title']
artist = songInfo['artist']
genre = songInfo['genre']
if str(artist) == "" or str(title) == "" or str(genre) == "":
print(song)
done = False
while not done:
inp = input("Would you like to rename this file? (y/n): ")
if inp.lower() in ["y", "n"]:
done = True
if inp.lower() in ["y"]:
defaultTitle = song.split("\\")[-1].split("_")[-1].split(" - ")[-1]
defaultArtist = song.split("\\")[-1].split("_")[-1].split(" - ")[0]
if defaultArtist.split(".")[0] == defaultTitle or defaultArtist == defaultTitle:
defaultArtist = song.split("\\")[-1].split("_")[0]
defaultTitle = defaultTitle.replace("[", "(")
defaultTitle = defaultTitle.replace("]", ")")
defaultTitle = defaultTitle.replace(".mp3", "")
defaultTitle = defaultTitle.replace("feat.", "ft.")
defaultTitle = defaultTitle.replace("Prod.", "prod.")
defaultTitle = defaultTitle.replace("(Lyrics)", "")
defaultTitle = defaultTitle.replace("(Official Video)", "")
defaultTitle = defaultTitle.replace("(Official Music Video)", "")
defaultTitle = defaultTitle.replace("(Official Audio)", "")
defaultTitle = defaultTitle.replace("(Official Visualizer)", "")
defaultTitle = defaultTitle.replace(" ", " ")
if defaultArtist.endswith(" - Topic") == True:
defaultArtist = defaultArtist.replace(" - Topic", "")
defaultGenre = folder.split("\\")[-1]
newTitle = input("What is the title? Default = " + defaultTitle + ": ") or defaultTitle
newArtist = input("What is the artist? Default = " + defaultArtist + ": ") or defaultArtist
newGenre = input("What is the genre? Default = " + defaultGenre + ": ") or defaultGenre
songInfo['title'] = newTitle
songInfo['artist'] = newArtist
songInfo['genre'] = newGenre
songInfo.save()
os.rename(song, os.path.dirname(song) + "//" + newArtist + " - " + newTitle + os.path.splitext(song)[1])
print(os.path.dirname(song) + "//" + newArtist + " - " + newTitle + os.path.splitext(song)[1])
else:
print("Skipping ", artist, " - ", title, " - ", genre)