Skip to content
Open

Tau #21

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
17 changes: 12 additions & 5 deletions GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def populate_Song_Metadata(self, relevant_data):
"""
relevant_data: a dictionary containing (key:value) pairs of metadata.
"""
print 'POPULATING'
self.lbox2.delete(0, END)
print(relevant_data)
for key in relevant_data.keys():
Expand All @@ -36,8 +37,9 @@ def populate_Similar_Songs(self, search):
search: the text entered in the search bar.
"""
songs = populateSongs(search)
self.lbox.delete(0, END)
self.lbox.insert(END, songs)
self.lbox.delete(0, END)
for song in songs:
self.lbox.insert(END, songs)

#Function to initiate a search for the song.
def search(self):
Expand All @@ -47,7 +49,10 @@ def search(self):
search_string = self.search_var.get()
print(search_string)
self.populate_Similar_Songs(search_string)
metadata = initiate_Search(search_string)
metadata = initiate_Search(search_string)
print metadata
# raw_input('>>>')

self.populate_Song_Metadata(metadata)
initiate_Download(search_string, metadata)

Expand All @@ -63,6 +68,7 @@ def onDouble(self, event):
value = widget.get(selection[0])
self.entry.delete(0, END)
self.entry.insert(END, value)
self.search()

#Function to setup the basic layout of the Graphical User Interface
def widgets(self):
Expand All @@ -74,7 +80,8 @@ def widgets(self):
Label(self, text="Song Downloader System", background="#CC0001", font= ("Comic Sans MS",16)).grid(row=0, column=0, padx=20)
self.search_var = StringVar()

self.entry = Entry(self, textvariable=self.search_var, width=45)
self.entry = Entry(self, textvariable=self.search_var, width=45)
self.entry.grid()

self.b1=Button(self, text='Search', command=self.search)
self.b1.grid(row=1, column=1, sticky=W, padx=20, pady=10)
Expand All @@ -84,7 +91,7 @@ def widgets(self):
self.lbox.bind("<Double-Button-1>", self.onDouble)

self.lbox2 = Listbox(self, width=45, height=15)
self.lbox2.grid(row=2, column=1, columnspan=6,sticky=W, padx=2000, pady=10)
self.lbox2.grid(row=2, column=1, columnspan=6,sticky=W, padx=20, pady=10)


"""
Expand Down
8 changes: 2 additions & 6 deletions crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def getMetaData(soup, noOfRecords):
if(s != None):
if(s.has_attr('title')):
if(s['title'] == 'Verified'):
pass
d['Verified'] = True

#Third child of yt-lockup-content division
metaDataTags = video.contents[2].ul
Expand All @@ -210,11 +210,7 @@ def checkIfVerified(meta):
#Function that converts Youtube views (a string) to an integer
#Eg: Youtube views -> 123,456,789 should become 123456789
def toNumber(string):
number = string
try:
return int(number)
except:
return -1
return int(string.replace(',', ''))

#Function that filters out the most relevant Youtube video
def getMostRelevant(metaData, searchWord):
Expand Down
Binary file modified crawler.pyc
Binary file not shown.
10 changes: 6 additions & 4 deletions downloader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from bs4 import BeautifulSoup
import dryscrape
#import dryscrape
import requests
import time

Expand All @@ -9,8 +9,8 @@ def convert_youtubeURL_to_download_URL(youtube_URL):
https://www.ssyoutube.com/XXX contains a link which allows music videos to be downloaded.
youtube_URL: the URL of the music video to be downloaded
"""
index = youtube_URL.find('https')
file_retrieve_URL = youtube_URL[0:index] + 'ss' + youtube_URL[index:]
#index = youtube_URL.find('https')
file_retrieve_URL = youtube_URL
redirect_response = requests.get(file_retrieve_URL)
print(redirect_response.url)
return redirect_response.url
Expand All @@ -28,7 +28,9 @@ def retrieve_File_URL(ss_downloaded_URL):
sess.visit(ss_downloaded_URL)
time.sleep(10)
response = sess.body()
response = response.encode('ascii', 'ignore')
#r = requests.get(ss_downloaded_URL)
#response = r.content
response = response.encode('"ascii"', 'ignore')
soup = BeautifulSoup(response.decode('ascii', 'ignore'), 'html.parser')
div = soup.find('div', {'class':'def-btn-box'})
print('*************************')
Expand Down
Binary file modified downloader.pyc
Binary file not shown.
12 changes: 8 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ def initiate_Search(search):
soup = init(base_url)
metaData = getMetaData(soup, 10)
print(metaData)

relevant = getMostRelevant(metaData, searchWord)
print(relevant)

return relevant

except urllib2.HTTPError as e:
Expand All @@ -38,6 +39,8 @@ def initiate_Search(search):
"""
***************No error section ends******************
"""



#Function to download the most relevant video.
def initiate_Download(search, relevant):
Expand All @@ -47,10 +50,11 @@ def initiate_Download(search, relevant):
search: the search text
relevant: a dictionary containing (key:value) pairs of metadata.
"""
youtube_URL = 'https://www.youtube.com'+relevant['Link']
ssyoutube_URL = convert_youtubeURL_to_download_URL(youtube_URL)
ssyoutube_URL = 'https://www.ssyoutube.com'+relevant['Link']
#ssyoutube_URL = convert_youtubeURL_to_download_URL(youtube_URL)
file_URL = retrieve_File_URL(ssyoutube_URL)
download_video(file_URL, search)
ext = '.mp4'
download_video(file_URL, search + ext)



Expand Down
Binary file modified main.pyc
Binary file not shown.
4 changes: 3 additions & 1 deletion song_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ def searchStringLogic(cursor, search_string):

def getAllSongs(cursor, artist, song):
songs = []
query = "SELECT song, year FROM lyrics WHERE artist LIKE '%s' AND song NOT LIKE '%s';" %(song, artist)
query = "SELECT song, year FROM lyrics WHERE artist LIKE '%s' AND song NOT LIKE '%s';" %(artist, song)
cursor.execute(query)
rows=cursor.fetchall()
for row in rows:
print(row[0], row[1])
songs.append(str(row[0]) + str(row[1]))
print 'Returning'
print songs
return songs

def populateSongs(search):
Expand Down
Binary file modified song_finder.pyc
Binary file not shown.