Skip to content

Commit

Permalink
fix techknowclub#13, and print consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
cnheider committed Oct 24, 2016
1 parent 41f5105 commit 4d35846
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
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
7 changes: 3 additions & 4 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


url_slice1 = r'http://mp3clan.ws/mp3/'
Expand All @@ -15,7 +14,7 @@
count = 1
for i in titles:
if count <= 20:
print count, '.', i.text
print(count, '.', i.text)
count = count + 1
temp_html = []
links = []
Expand All @@ -29,4 +28,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

0 comments on commit 4d35846

Please sign in to comment.