diff --git a/mymusic_dl/main.py b/mymusic_dl/main.py index be6f4bc..a5f2ac8 100644 --- a/mymusic_dl/main.py +++ b/mymusic_dl/main.py @@ -4,12 +4,15 @@ from mymusic_dl.functions import get_youtube_url from mymusic_dl.functions import download_audio -"""This module verifies the user input before proceeding further. +"""This block of code verifies the user input before proceeding further. """ guide = """ To download a playlist, try $ mymusic_dl https://open.spitify.com/playlist/18EuC3nWTRg10DD35jfZkk + +To search a song and download the first result from youtube, try + $ mymusic_dl -s "ncs top 10" """ error = """ @@ -35,21 +38,21 @@ def input_validator(cliArgs): prGreen(guide) return 0 - if not "open.spotify.com" in cliArgs[1] or not "https://" in cliArgs[1]: - prRed(error) - prGreen(guide) - return 0 +# if not "open.spotify.com" in cliArgs[1] or not "https://" in cliArgs[1]: +# prRed(error) +# prGreen(guide) +# return 0 if "playlist" in cliArgs[1]: prGreen("^_^ playlist link detected...\n continuing to web scraping...") return 1 - + elif cliArgs[1] == "-s": + prGreen("^_^ proceeding to search youtube...\n") + return 2 elif "track" in cliArgs[1] or "album" in cliArgs[1]: prGreen("\n^_^ Support for tracks and albums Coming Soon! Your " + chr(127775) -+ "'s on GitHub will motivate me complete it faster :)\n") - ++ "'s on GitHub will motivate me to ship updates faster :)\n") return 0 - else: prRed(error) prGreen(guide) @@ -57,38 +60,63 @@ def input_validator(cliArgs): +"""This block is the entrypoint of the program +""" def mymusic_dl(): - """Entrypoint of the scripts""" - - if(input_validator(cliArgs)): - url = cliArgs[1] - # remove the excessive parts from the link - if "?si=" in url: - url = url[:url.index("?si=")] - - song_count, pl_name, track_artists_album = scrape_spotify(url) - - # might replace all this with log later - prGreen("Info") - prGreen("Playlist name: {0}\nSong Count: {1}\n" .format(pl_name, song_count)) - prGreen("Getting video id from youtube...") - - # search the strings on yotube and store the videoID - videoID_list = [ get_youtube_url(query) for query in track_artists_album ] - - if None in videoID_list: - prRed("Something went wrong") - else: - prGreen("Here is the list of videoIDs") - for i in videoID_list: - print(i) + return_val = input_validator(cliArgs) + + if(return_val): + if(return_val == 1): + url = cliArgs[1] + # remove the excessive parts from the link + if "?si=" in url: + url = url[:url.index("?si=")] + + song_count, pl_name, track_artists_album = scrape_spotify(url) + + # might replace all this with log later + prGreen("Info") + prGreen("Playlist name: {0}\nSong Count: {1}\n" .format(pl_name, song_count)) + prGreen("Getting video id from youtube...") + + # search the strings on yotube and store the videoID + videoID_list = [ get_youtube_url(query) for query in track_artists_album ] + + if None in videoID_list: + prRed("Something went wrong") + else: + prGreen("Here is the list of videoIDs") + for i in videoID_list: + print(i) + + prRed("Starting Downloads . . .") + + for videoID in videoID_list: + + # trying error handling here + try: + download_audio(videoID) + prGreen("Download +1 done") + except Exception: # ya ik it's bad and stuff + pass + + elif(return_val == 2): + query = cliArgs[2] + # get url + vid_id = get_youtube_url(query) + # start download retry 3 times if failed + c = 3 + while c: + try: + download_audio(vid_id) + prGreen("Done :)") + except Exception as e: + print(e, "\n Due to error will try", c-1, "times more") + c -= 1 + break - prRed("Starting Downloads . . .") - for videoID in videoID_list: - download_audio(videoID) - prGreen("Download +1 done") if __name__ == '__main__': mymusic_dl() diff --git a/setup.py b/setup.py index 4a3b18c..62b8e16 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ setuptools.setup( name='mymusic_dl', - version='0.0.1a7', + version='0.0.1b0', python_requires='>=3', install_requires=requirements, author='Prateek Mishra', diff --git a/tests/test_all.py b/tests/test_all.py index aa128d0..4c91480 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -1,5 +1,3 @@ """One for all test file, as of now """ -import spoti_yt -