@@ -39,6 +39,31 @@ async def update_downloads_playlist(playlists):
3939 playlists ["all" ] = sum (playlists .values (), [])
4040 print ("Updated downloads playlist:" , [os .path .basename (file ) for file in playlists ["downloads" ]])
4141
42+ # Function to choose a playlist or download music
43+ async def initial_choice (playlists ):
44+ while True :
45+ user_choice = input ("Do you want to choose a playlist or download music? (playlist/download): " ).strip ().lower ()
46+ if user_choice == "playlist" :
47+ return choice (playlists )
48+ elif user_choice == "download" :
49+ use = input ("Download from URL (Y or N): " ).strip ().lower ()
50+ if use in ["y" , "yes" ]:
51+ url = input ("Enter the URL of the video (n to break): " )
52+ if url .lower () not in ["n" , "no" ]:
53+ try :
54+ await url_download (url )
55+ except Exception as e :
56+ print (f"Error downloading from URL: { e } " )
57+ else :
58+ try :
59+ await search_and_download ()
60+ except Exception as e :
61+ print (f"Error searching and downloading: { e } " )
62+ await update_downloads_playlist (playlists )
63+ return playlists ["downloads" ]
64+ else :
65+ print ("Invalid choice. Please choose 'playlist' or 'download'." )
66+
4267# Function to choose a playlist
4368def choice (playlists ):
4469 while True :
@@ -134,7 +159,7 @@ async def music_play(playlist, playlists):
134159# Main function to start the music player
135160async def main ():
136161 playlists = await get_playlists (directories )
137- playlist = choice (playlists )
162+ playlist = await initial_choice (playlists )
138163 await music_play (playlist , playlists )
139164
140165if __name__ == "__main__" :
0 commit comments