1+ from __future__ import unicode_literals
2+ from lxml .cssselect import CSSSelector
3+ from lxml .html import fromstring
4+ import questionary
5+ from rich import print , pretty
6+ from rich .traceback import install
7+ install ()
8+ pretty .install ()
9+ from rich .progress import track
10+ from rich .console import Console
11+ from rich .prompt import Prompt
12+ console = Console ()
13+
14+
15+ def asker ():
16+ try :
17+ single_songs = questionary .select (
18+ "How many songs do you want to download?" ,
19+ choices = [
20+ "One song" ,
21+ "Multiple Songs"
22+ ]
23+ ).ask ()
24+
25+ if single_songs == "One song" :
26+ return [questionary .text ("What is the song name" ).ask ()]
27+ else :
28+ input_method = questionary .select (
29+ "Which songs do you want to download?" ,
30+ choices = [
31+ "Songs, comma seperated" ,
32+ 'List in textfile (1 Song per line)' ,
33+ 'From YTMusic (beta)' ,
34+ ]).ask () # returns value of selection
35+
36+ if input_method == "From YTMusic" :
37+ console .print ("""[bold red]YT-Music[/bold red].
38+ - Go to your YTMusic liked songs playlist (https://music.youtube.com/playlist?list=LM)
39+ - Make sure you are logged in
40+ - Press Ctrl/Cmd + Shift + i and open the dev tools
41+ - Keep scrolling down until you reach the end of your playlist (Songs will stop loading)
42+ - Copy the all the html markup
43+ - Create a text file and paste the html into it.
44+ """ )
45+ if not questionary .confirm ("Only continue if you have done the task." ).ask ():
46+ quit ()
47+ file = questionary .path ("Where is that file located?" ).ask ()
48+ with open (file , "r" , encoding = "utf-8" ) as f :
49+ data = f .read ()
50+ h = fromstring (data )
51+ sel = CSSSelector ("yt-formatted-string.title.style-scope.ytmusic-responsive-list-item-renderer.complex-string > a.yt-simple-endpoint.style-scope.yt-formatted-string" )
52+ songs_list = [e .text for e in sel (h )]
53+ return songs_list
54+
55+ elif input_method == "List in textfile (1 Song per line)" :
56+ file = questionary .path ("Where is that file located?" ).ask ()
57+ text_file = open (file ,encoding = 'utf-8' )
58+ songs_list = text_file .read ().splitlines ()
59+ return songs_list
60+ elif input_method == "Songs, comma seperated" :
61+ songs_list = questionary .text ("Write all songs (comma seperated)" ).ask ().split ("," )
62+ return songs_list
63+ except Exception as e :
64+ ## eventually change :/
65+ pass
0 commit comments