Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #13 and made prints more consistent #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ requests==2.11.1
webkit-server==1.0
wsgiref==0.1.2
xvfbwrapper==0.2.8
youtube_dl
9 changes: 4 additions & 5 deletions src/SongDownloadder/mp3skull/SongDownloader_mp3skull.py
Original file line number Diff line number Diff line change
@@ -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/'
Expand All @@ -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
Expand All @@ -23,4 +22,4 @@
f = open("thisshouldwork.mp3", "w")
f.write(mp3)
f.close()
print "Done"
print("Done")
37 changes: 23 additions & 14 deletions src/SongDownloadder/youtube/SongDownloader.py
Original file line number Diff line number Diff line change
@@ -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 '})
Expand All @@ -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"
Expand All @@ -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 = ""
Expand All @@ -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)
21 changes: 12 additions & 9 deletions src/SongDownloadder/youtube/SongDownloader_youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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
Expand Down