def main(argv): array = sys.argv for i in range(len(array)): if array[i] in ('-p', '--path'): CLI.path = array[i + 1] print(CLI.path) #same old for loop for i in range(len(array)): if array[i] in ('-h', '--help'): CLI.help() elif array[i] in ('-ss', '--spotify-song'): try: md = MusicDownloader() state = md.downloadBySpotifyUri(array[i + 1], CLI.path) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-sa', '--spotify-album'): try: md = MusicDownloader() md.downloadBySpotifyUriAlbumMode(array[i + 1], CLI.path) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-sp', '--spotify-playlist'): #playlist uri try: md = MusicDownloader() md.downloadBySpotifyUriPlaylistMode(array[i + 1], CLI.path) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-ds', '--deezer-song'): try: md = MusicDownloader() state = md.downloadByDeezerUrl(array[i + 1], CLI.path) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-da', '--deezer-album'): try: md = MusicDownloader() md.downloadByDeezerUrlAlbumMode(array[i + 1], CLI.path) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-dp', '--deezer-playlist'): #playlist uri try: md = MusicDownloader() md.downloadByDeezerUrlPlaylistMode(array[i + 1], CLI.path) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-ym', '--youtube-music'): #YouTube Music try: link = ''.join(str(array[i + 1]).split('music.')).split('&')[0] md = MusicDownloader() name = md.getYoutubeMusicInfo(link) tags = md.getLastFMTags(name) try: state = md.downloadFromYoutubeMusic(url=link, info=tags, path=CLI.path) except: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-yv', '--youtube-video'): try: md = MusicDownloader() name = md.getNameFromYoutube(array[i + 1]) uri = random.randint(1000000000, 10000000000) uri = 's' + str(uri) + 't' info = { 'uri': uri, 'name': str(name).split('-')[-1], 'artist': str(name).split('-')[0], 'album': 'YouTube', 'image': '', 'duration_ms': 0 } state = md.downloadFromYoutubeMusic(url=array[i + 1], info=info, path=CLI.path) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-a', '--apple'): #Apple Music try: md = MusicDownloader() apple = AppleMusic() name = apple.getName(array[i + 1]) state = md.downloadBySearchQuery(query=name, path=CLI.path) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif array[i] in ('-q', '--query'): try: md = MusicDownloader() state, data = md.downloadBySearchQuery(query=array[i + 1], path=CLI.path) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) CLI.help()
def main(argv): try: opts, args = getopt.getopt(argv, "hs:p:q:y:v:a:f:", [ "help=", "song=", "playlist=", "query=", "youtube=", "video=", "apple=", "file=" ]) except getopt.GetoptError: CLI.help() exit(0) for parameter, argument in opts: if parameter in ("-h", "--help"): CLI.help() sys.exit(0) elif parameter in ("-s", "--song"): #song uri try: md = MusicDownloader() state = md.downloadBySpotifyUri(argument) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif parameter in ("-p", "--playlist"): #playlist uri try: md = MusicDownloader() md.downloadBySpotifyUriPlaylistMode(argument) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif parameter in ("-q", "--query"): #query try: md = MusicDownloader() state, data = md.downloadBySearchQuery(argument) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif parameter in ("-y", "--youtube"): #YouTube Music try: link = ''.join(str(argument).split('music.')).split('&')[0] md = MusicDownloader() name = md.getYoutubeMusicInfo(link) tags = md.getLastFMTags(name) state = md.downloadFromYoutubeMusic(url=link, info=tags) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif parameter in ("-v", "--video"): #YouTube Music try: md = MusicDownloader() name = md.getNameFromYoutube(argument) uri = random.randint(1000000000, 10000000000) uri = 's' + str(uri) + 't' info = { 'uri': uri, 'name': str(name).split('-')[-1], 'artist': str(name).split('-')[0], 'album': 'YouTube', 'image': '', 'duration_ms': 0 } state = md.downloadFromYoutubeMusic(url=argument, info=info) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif parameter in ("-a", "--apple"): #Apple Music try: md = MusicDownloader() apple = AppleMusic() name = apple.getName(argument) state = md.downloadBySearchQuery(query=name) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0) sys.exit(0) elif parameter in ("-f", "--file"): #from file try: md = MusicDownloader() md.downloadBySpotifyUriFromFile(argument) except KeyboardInterrupt: exit(0) sys.exit() else: #normal startup try: while True: md = MusicDownloader() state = md.downloadBySpotifyUri( input('[smd]>SONG URI:')) if not state: notify.send(f'Failed to download', True) except KeyboardInterrupt: sys.exit(0)