diff --git a/requirements.txt b/requirements.txt index 10b4d66..de595db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,3 +6,4 @@ requests==2.11.1 webkit-server==1.0 wsgiref==0.1.2 xvfbwrapper==0.2.8 +youtube_dl diff --git a/src/SongDownloadder/mp3skull/SongDownloader_mp3skull.py b/src/SongDownloadder/mp3skull/SongDownloader_mp3skull.py index 71effdd..6711e61 100644 --- a/src/SongDownloadder/mp3skull/SongDownloader_mp3skull.py +++ b/src/SongDownloadder/mp3skull/SongDownloader_mp3skull.py @@ -1,7 +1,6 @@ from bs4 import BeautifulSoup as bs -import urllib import requests -from urllib import re +import urllib max_options_limit = 20 url_prefix = r'http://mp3clan.ws/mp3/' @@ -13,8 +12,8 @@ titles = soup.find_all('div', {'class': 'unselectable'})[0:max_options_limit] download_links = soup.find_all('div', {'title': 'Download'})[0:max_options_limit] links = [] -for (count,title,download_link) in zip(range(1,max_options_limit + 1),titles,download_links): - print str(count) + '. ' + title.text +for(count, title, download_link) in zip(range(1, max_options_limit + 1), titles, download_links): + print(str(count) + '. ' + title.text) links.append(download_link.find('a')['href']) choice = int(raw_input()) # Download @@ -23,4 +22,4 @@ f = open("thisshouldwork.mp3", "w") f.write(mp3) f.close() -print "Done" +print("Done") diff --git a/src/SongDownloadder/youtube/SongDownloader.py b/src/SongDownloadder/youtube/SongDownloader.py index f22b0f3..3114d53 100644 --- a/src/SongDownloadder/youtube/SongDownloader.py +++ b/src/SongDownloadder/youtube/SongDownloader.py @@ -1,14 +1,14 @@ -import requests from bs4 import BeautifulSoup -import os import dryscrape -import urllib +import os +import requests +import youtube_dl def youtubedl(search): media = "audio" url = 'https://www.youtube.com/results?search_query=' + \ - search[:len(search)-3] + search[:len(search) - 3] sc = requests.get(url) soup = BeautifulSoup(sc.content, 'html.parser') title = soup.findAll('h3', {'class': 'yt-lockup-title '}) @@ -30,7 +30,7 @@ def youtubedl(search): except NameError: print ('!') continue - f_link = 'https://www.youtube.com'+link[user_input-1] + f_link = 'https://www.youtube.com' + link[user_input - 1] if search[::-1][:3] == 'v- ': media = "defvideo" @@ -39,12 +39,21 @@ def youtubedl(search): media = "video" if media == "video": - os.system("youtube-dl -f {} ".format(res) + f_link) + opts = { + 'format': str(res) + } + with youtube_dl.YoutubeDL(opts) as ydl: + ydl.download([f_link]) if media == "defvideo": - os.system("youtube-dl " + f_link) + with youtube_dl.YoutubeDL() as ydl: + ydl.download([f_link]) if media == "audio": - os.system("youtube-dl -f 140 " + f_link) - print "Downlod Complete" + opts = { + 'format': "140" + } + with youtube_dl.YoutubeDL(opts) as ydl: + ydl.download([f_link]) + print("Downlod Complete") flag = "" @@ -70,29 +79,29 @@ def youtubedl(search): link_.append(link) link__.append(link['href'][2:]) - except: + except Exception: pass if len(links) > 10: for i in range(20): temp = link_[i].text.split('\n') - print str(i + 1) + ".", temp[2], temp[3], temp[5] + print(str(i + 1) + ".", temp[2], temp[3], temp[5]) n = int(raw_input(">")) if n == 0: youtubedl(search) if n == 999: continue else: - download = base_url + link__[n-1] + download = base_url + link__[n - 1] session2 = dryscrape.Session() session2.visit(download) response2 = session2.body() soup1 = BeautifulSoup(response2, 'html.parser') final_link = soup1.findAll('span', {'class': 'url'}) final_link = str(final_link)[19:].split('<') - print "Downloading from: \n", final_link[0], "\n\n" + print("Downloading from: \n", final_link[0], "\n\n") # urllib.urlretrieve(g[0], "{}.mp3".format(names[n-1].text)) os.system("curl -O " + final_link[0]) - print "Download complete" + print("Download complete") else: youtubedl(search) diff --git a/src/SongDownloadder/youtube/SongDownloader_youtube.py b/src/SongDownloadder/youtube/SongDownloader_youtube.py index 7f125d0..e930c26 100644 --- a/src/SongDownloadder/youtube/SongDownloader_youtube.py +++ b/src/SongDownloadder/youtube/SongDownloader_youtube.py @@ -3,11 +3,9 @@ # youtube-dl should be installed -import requests -import os -import sys from bs4 import BeautifulSoup -import time +import requests +import youtube_dl media = "default" @@ -28,7 +26,7 @@ for i in range(len(title)): link.append(title[i].find('a')['href']) for i in range(len(title)): - print (str(i+1)+'. '+title[i].find('a').text) + print(str(i + 1) + '. ' + title[i].find('a').text) while True: try: @@ -41,15 +39,20 @@ except NameError: print ('!') continue -f_link = 'https://www.youtube.com'+link[user_input-1] +f_link = 'https://www.youtube.com' + link[user_input - 1] # print ('Downloading...') if media == "default": - os.system("youtube-dl -f 140 " + f_link) + opts = { + 'format': "140" + } + with youtube_dl.YoutubeDL(opts) as ydl: + ydl.download([f_link]) if media == "defvideo": - os.system("youtube-dl " + f_link) -print "Download Complete" + with youtube_dl.YoutubeDL() as ydl: + ydl.download([f_link]) +print("Download Complete") # File gets downloaded to your Python directory # Use os.rename() to rename the file if required