def download_songs(song_list): spk = SongsPK() total_songs = len(song_list) songs_download_count = 0 songs_not_downloaded = [] for song in song_list: try: parsed_song = parse(song) if len(parsed_song) == 0: songs_not_downloaded.append(song) continue getVars = {'q': parsed_song} url = search_url + urllib.parse.urlencode(getVars) page = get_content(url) download_url = base_url + URLParserHref.get_songs_page_url( page, song) page = get_content(download_url) song_download_url = URLParserHref.get_songs_url(page) print("Downloading %s ..." % song) spk.download(song_download_url, song) songs_download_count += 1 except Exception as e: print(e) songs_not_downloaded.append(song) print("%s out of %s songs downloaded" % (songs_download_count, total_songs)), if len(songs_not_downloaded) > 0: print("Following songs were not downloaded") for song in songs_not_downloaded: print(song),
def urlbased(self, url_datas=None): """ Prepares the url and then download the mp3 file. To write the file in Disk it depends on write_mp3 function """ visited_url = [] if not url_datas: url_datas = raw_input("Enter comma separated url strings\n") os.system("clear && echo PLEASE WAIT ...") url_datas = url_datas.split(",") for url_data in url_datas: movie_name = url_data.rstrip(".html").split("/")[-1] if url_data.startswith("www"): url_data = url_data.replace("www", "http://www") try: s_data = requests.get(url_data).content song_urls = URLParserHref.get_songs_url(s_data) parse_url = 0 for url in list(set(song_urls)): parse_url += 1 try: res, finalurl = url_resolver(url) # Now check the function if finalurl.endswith(".mp3") and finalurl not in visited_url and not finalurl.startswith(".."): with warnings.catch_warnings(): warnings.simplefilter("ignore") if self.play_mode: Player.play(finalurl) else: # call to write mp3 file in Disk self.write_mp3(res, filename=finalurl.split("/")[-1]) visited_url.append(finalurl) except: continue sys.stdout.write( "\r%d out of %d songs processed for movie ---> %s" % (parse_url, len(song_urls), movie_name) ) sys.stdout.flush() except: pass
"""