-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
60 lines (45 loc) · 1.78 KB
/
app.py
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
from pytube import YouTube as youtube # type: ignore
import tkinter as tk
import subprocess
from tkinter import filedialog
from pytube import Search
from downloader import downloadMp3, open_file_dialog
from spotify import get_token, search_for_artist, get_songs_of_artist
import os
# search = Search('Night Changes')
# # for i in search.results:
# # print(i.watch_url)
# # print('-------------------')
# # keys = "\n".join([k for k in search.results[0].__dict__])
# # print(keys)
# print(search.results[0].watch_url)
# yt = youtube(search.results[0].watch_url)
if __name__ == "__main__":
#tkinter code
root = tk.Tk()
root.title("YouTube Video Downloader")
root.withdraw()
# url = input("Enter the URL of the video: ")
token_spotify = get_token() # Spotify token
singer = str(input("Enter the name of the singer: ")) # Singer name
result = search_for_artist(token_spotify, singer) # Search for the singer
artist_id = result["id"] # Get the artist ID
songs = get_songs_of_artist(token_spotify, artist_id)
directory = open_file_dialog() # Open file dialog to select directory
path = os.path.join(directory, singer)
if not os.path.exists(path):
os.makedirs(path)
path = os.path.join(directory, singer)
if directory:
print("Downloading video to %s" % directory)
for idx, song in enumerate(songs):
# print(f"{idx+1}. {song['name']}")
search = Search(song['name'])
url = search.results[0].watch_url
print("Downloading song %s" % song['name'])
# print(url)
downloadMp3(url, path)
# print("Download complete.")
else:
print("No directory selected. Exiting...")
# subprocess.run(["pkill", "-f", "python"])