diff --git a/GUI.py b/GUI.py index b177c64..99c5b36 100755 --- a/GUI.py +++ b/GUI.py @@ -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(): @@ -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): @@ -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) @@ -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): @@ -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) @@ -84,7 +91,7 @@ def widgets(self): self.lbox.bind("", 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) """ diff --git a/crawler.py b/crawler.py index 90a50b8..d2e675c 100644 --- a/crawler.py +++ b/crawler.py @@ -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 @@ -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): diff --git a/crawler.pyc b/crawler.pyc index ef88d48..0869448 100644 Binary files a/crawler.pyc and b/crawler.pyc differ diff --git a/downloader.py b/downloader.py index e349c38..5c3a9d6 100644 --- a/downloader.py +++ b/downloader.py @@ -1,5 +1,5 @@ from bs4 import BeautifulSoup -import dryscrape +#import dryscrape import requests import time @@ -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 @@ -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('*************************') diff --git a/downloader.pyc b/downloader.pyc index 635eb55..c78050a 100644 Binary files a/downloader.pyc and b/downloader.pyc differ diff --git a/main.py b/main.py index 4e169ba..8552a8e 100644 --- a/main.py +++ b/main.py @@ -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: @@ -38,6 +39,8 @@ def initiate_Search(search): """ ***************No error section ends****************** """ + + #Function to download the most relevant video. def initiate_Download(search, relevant): @@ -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) diff --git a/main.pyc b/main.pyc index 148d4ff..d574719 100644 Binary files a/main.pyc and b/main.pyc differ diff --git a/song_finder.py b/song_finder.py index a3040ad..eaad035 100755 --- a/song_finder.py +++ b/song_finder.py @@ -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): diff --git a/song_finder.pyc b/song_finder.pyc index a5b17b3..1c689f2 100644 Binary files a/song_finder.pyc and b/song_finder.pyc differ