-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
54 lines (43 loc) · 2.18 KB
/
main.py
File metadata and controls
54 lines (43 loc) · 2.18 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
import os
import shutil
from ytToMp3 import YouTubeAPI
from mp3ToWav import Mp3ToWavConverter
from wavToStars import SongClassifier
dirs = [
"./Downloads",
"./0_tmp_spectrograms",
"./1_Star",
"./2_Stars",
"./3_Stars",
"./4_Stars",
"./5_Stars"
]
def clear_directories():
for dir_path in dirs:
if os.path.exists(dir_path):
for filename in os.listdir(dir_path):
file_path = os.path.join(dir_path, filename)
try:
if os.path.isfile(file_path) or os.path.islink(file_path):
os.unlink(file_path)
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
print(f"Failed to delete {file_path}. Reason: {e}")
if __name__ == "__main__":
#url = "https://music.youtube.com/watch?v=YcxBgFBKixk&si=IIlo3JhvKDzofjTY"
# "official music video" OR "official audio" OR "official lyrics" OR "lyric video" -playlist -compilation -top -mix
# ("Beach Avenue" OR "Birds of Bellwoods" OR "Avicii" OR "Patent Pending") ("official music video" OR "official audio" OR "lyric video") -playlist -compilation -top -mix
# ("official music video" OR "official audio" OR "lyric video" OR "visualizer" OR "album version" OR "single version") (pop OR hip hop OR OR folk OR country) -playlist -compilation -mix -top
youTubeAPI = YouTubeAPI()
urls = youTubeAPI.search_youtube_official('("official music video" OR "official audio" OR "lyric video" OR "visualizer" OR "album version" OR "single version") (taylor swift) -playlist -compilation -mix -top', max_results=200)
clear_directories()
for url in urls:
youTubeAPI.download_youtube_as_mp3(url, "./Downloads")
Mp3ToWavConverter(output_dir="./Downloads").convert_all()
classifier = SongClassifier(model_path="./Models/Sonai_05-29-25_12:13:21.h5")
classifier.classify_and_move()
print("Predictions completed.")
for i, dir_path in enumerate(dirs[2:7], start=2):
num_files = len([f for f in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, f))])
print(f"{dirs[i]}: {num_files}")