def beatportSearch(filename, track, artistVariations, titleVariations, headers, search, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, labelFrame, searchFrame, pageFrame, componentFrame, audio, options, initialCounter, imageCounter, images): global count count = 0 widgetList = allWidgets(searchFrame) for item in widgetList: item.pack_forget() if len(filename) > 60: tk.Label(searchFrame, text="\nSearching Beatport for " + str(filename)[0:59] + "...", font=("Proxima Nova Rg", 13), fg="white", bg=bg).pack(side="left", padx=(10, 0), anchor='w') else: tk.Label(searchFrame, text="\nSearching Beatport for " + str(filename), font=("Proxima Nova Rg", 13), fg="white", bg=bg).pack(side="left", padx=(10, 0), anchor='w') leftComponentFrame, rightComponentFrame = resetLeftRightFrames(componentFrame) refresh(webScrapingWindow) url = "https://www.google.co.in/search?q=" + search + " Beatport" soup = prepareRequest(url, headers, webScrapingWindow, leftComponentFrame) if soup == False: Label(leftComponentFrame, text="Connection Failure", font=("Proxima Nova Rg", 11), fg="white", bg=bg).pack(anchor='w') refresh(webScrapingWindow) return track, imageCounter, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, searchFrame, pageFrame, componentFrame for link in soup.find_all('a'): if "www.beatport.com" in link.get('href').split('&')[0]: mismatch = True resultString = str(link).lower() for variation in titleVariations: if variation in resultString: mismatch = False break if not mismatch: link = link.get('href').split('&')[0].split('=')[1] if "remix" in link and "remix" in track.title.lower() or "remix" not in track.title.lower() and "remix" not in link: # clear component frames of existing content widgetList = allWidgets(componentFrame) for item in widgetList: item.pack_forget() widgetList = allWidgets(pageFrame) for item in widgetList: item.pack_forget() webScrapingPage += 1 leftComponentFrame, rightComponentFrame = resetLeftRightFrames(componentFrame) # page counter and navigation buttons rerenderControls(pageFrame, webScrapingPage) if len(link) > 75: label = tk.Label(leftComponentFrame, text="\n" + str(link)[0:74] + "...", cursor="hand2", font=("Proxima Nova Rg", 11), fg="white", bg=bg) else: label = tk.Label(leftComponentFrame, text="\n" + str(link), cursor="hand2", font=("Proxima Nova Rg", 11), fg="white", bg=bg) label.bind("<Button-1>", lambda e, link=link: webbrowser.open_new(link)) label.pack(padx=(10, 0), pady=(0, 25), anchor='w') webScrapingLeftPane[webScrapingPage] = leftComponentFrame # assume match will fail and no image will be found webScrapingRightPane[webScrapingPage] = "NA" webScrapingLinks[webScrapingPage] = link refresh(webScrapingWindow) soup = prepareRequest(link, headers, webScrapingWindow, leftComponentFrame) if soup != False and "Oops... the page you were looking for could not be found" not in str(soup): # check if page is a track (single) or a release (album) # case 1: release if link[25:32] == "release": imageCounter, images, webScrapingLeftPane, webScrapingRightPane = beatportRelease(soup, titleVariations, track, headers, audio, leftComponentFrame, rightComponentFrame, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingPage, options, initialCounter, imageCounter, images) # case 2: track elif link[25:30] == "track": imageCounter, images, webScrapingLeftPane, webScrapingRightPane = beatportTrack(soup, track, headers, audio, leftComponentFrame, rightComponentFrame, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingPage, options, initialCounter, imageCounter, images) else: tk.Label(leftComponentFrame, text="Track failed due to dead link or territory restriction", font=("Proxima Nova Rg", 11), fg="white", bg=bg).pack(padx=(10, 0), pady=(5, 0), anchor='w') if options['Limit Number of Matches per Site (B)'].get() and count >= options['Match Limit (I)'].get(): break return track, imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, searchFrame, pageFrame, componentFrame
def searchQuery(track, result, headers, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, pageFrame, leftComponentFrame, componentFrame, artistVariations, titleVariations, audio, options, initialCounter, imageCounter, images): link = str(result.find('a').get('href')).split('&')[0].split('=')[1] soup = prepareRequest(link, headers, webScrapingWindow, leftComponentFrame) if soup != False: # first check if the title is in the tracklist, push data if it is link = soup.find('table', class_="playlist") # handle 404 links if link != None: # post link to web scraping window widgetList = allWidgets(componentFrame) for item in widgetList: item.pack_forget() widgetList = allWidgets(pageFrame) for item in widgetList: item.pack_forget() webScrapingPage += 1 leftComponentFrame, rightComponentFrame = resetLeftRightFrames(componentFrame) # page counter and navigation buttons rerenderControls(pageFrame, webScrapingPage) weblink = str(result.find('a').get('href')).split('&')[0].split('=')[1] label = tk.Label(leftComponentFrame, text="\n" + str(weblink), cursor="hand2", font=("Proxima Nova Rg", 11), fg="white", bg=bg) label.bind("<Button-1>", lambda e, link=weblink: webbrowser.open_new(link)) label.pack(padx=(10, 0), pady=(0, 25), anchor="w") webScrapingLeftPane[webScrapingPage] = leftComponentFrame webScrapingRightPane[webScrapingPage] = "NA" webScrapingLinks[webScrapingPage] = weblink refresh(webScrapingWindow) finalMatch = False # artist + title format if link.find('td', class_="track tracklist_track_title mini_playlist_track_has_artist")!=None: # first entry goes by different class name temp = link.find('tr', class_='first tracklist_track track') if temp != None: finalMatch, imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage = artistTitleSearch(temp, artistVariations, titleVariations, audio, soup, track, headers, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingPage, webScrapingLinks, leftComponentFrame, rightComponentFrame, options, initialCounter, imageCounter, images) # remaining entries if not finalMatch: for temp in link.find_all('tr', class_="tracklist_track track"): finalMatch, imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage = artistTitleSearch(temp, artistVariations, titleVariations, audio, soup, track, headers, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingPage, webScrapingLinks, leftComponentFrame, rightComponentFrame, options, initialCounter, imageCounter, images) if finalMatch: break # title format elif link.find('td', class_="track tracklist_track_title")!=None: # first entry goes by different class name temp = link.find('tr', class_='first tracklist_track track') if temp != None: finalMatch, imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage = titleSearch(temp, titleVariations, audio, soup, track, headers, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingPage, webScrapingLinks, leftComponentFrame, rightComponentFrame, options, initialCounter, imageCounter, images) # remaining entries if not finalMatch: for temp in link.find_all('tr', class_="tracklist_track track"): finalMatch, imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage = titleSearch(temp, titleVariations, audio, soup, track, headers, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingPage, webScrapingLinks, leftComponentFrame, rightComponentFrame, options, initialCounter, imageCounter, images) if finalMatch: break if not finalMatch: tk.Label(leftComponentFrame, text="Track did not match with any of the listings", font=("Proxima Nova Rg", 11), fg="white", bg=bg).pack(padx=(10, 0), pady=(5, 0), anchor="w") refresh(webScrapingWindow) return imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage
def discogsSearch(filename, track, artistVariations, titleVariations, headers, search, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, labelFrame, searchFrame, pageFrame, componentFrame, audio, options, initialCounter, imageCounter, images): global count count = 0 widgetList = allWidgets(searchFrame) for item in widgetList: item.pack_forget() if len(filename) > 60: tk.Label(searchFrame, text="\nSearching Discogs for " + str(filename)[0:59] + "...", font=("Proxima Nova Rg", 13), fg="white", bg=bg).pack(side="left", padx=(10, 0), anchor='w') else: tk.Label(searchFrame, text="\nSearching Discogs for " + str(filename), font=("Proxima Nova Rg", 13), fg="white", bg=bg).pack(side="left", padx=(10, 0), anchor='w') leftComponentFrame, rightComponentFrame = resetLeftRightFrames(componentFrame) refresh(webScrapingWindow) url = "https://www.google.co.in/search?q=" + search + " Discogs" soup = prepareRequest(url, headers, webScrapingWindow, leftComponentFrame) if soup != False: # result includes link and description for result in soup.find_all('div', class_="ZINbbc xpd O9g5cc uUPGi"): if "www.discogs.com" in str(result.find('a').get('href')).lower().split('&')[0]: searchTitle = track.title if ' (' in track.title and ')' in track.title: searchTitle = track.title[:track.title.index(' (')] if searchTitle.lower() in str(result).lower(): imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage = searchQuery(track, result, headers, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, pageFrame, leftComponentFrame, componentFrame, artistVariations, titleVariations, audio, options, initialCounter, imageCounter, images) else: resultString = str(result).replace('-', ' ').lower() for variation in titleVariations: variation = variation.replace('-', ' ') if variation.lower() in resultString: imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage = searchQuery(track, result, headers, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, pageFrame, leftComponentFrame, componentFrame, artistVariations, titleVariations, audio, options, initialCounter, imageCounter, images) break if options['Limit Number of Matches per Site (B)'].get() and count >= options['Match Limit (I)'].get(): break return track, imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, searchFrame, pageFrame, componentFrame
def enableControls(searchFrame, pageFrame, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, componentFrame): global currentPage currentPage = webScrapingPage # clear page frame widgetList = allWidgets(searchFrame) for item in widgetList: item.pack_forget() widgetList = allWidgets(pageFrame) for item in widgetList: item.pack_forget() tk.Label(searchFrame, text="\nSearch Complete", font=("Proxima Nova Rg", 13), fg="white", bg=bg).pack(side="left", padx=(10, 0), anchor="w") farRightButton = tk.Button(pageFrame, text=">>", state=DISABLED, font=("Proxima Nova Rg", 11), fg="white", bg=bg, width=2, command=lambda: navigateFarRight(leftButton, farLeftButton, rightButton, farRightButton, pageIndicator, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, componentFrame)) farRightButton.pack(side="right", padx=(5, 30)) rightButton = tk.Button(pageFrame, text=">", state=DISABLED, font=("Proxima Nova Rg", 11), fg="white", bg=bg, width=2, command=lambda: navigateRight(leftButton, farLeftButton, rightButton, farRightButton, pageIndicator, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, componentFrame)) rightButton.pack(side="right", padx=(5,5)) pageIndicator = tk.Label(pageFrame, text=str(webScrapingPage) + "/" + str(webScrapingPage), font=("Proxima Nova Rg", 11), fg="white", bg=bg, anchor='e') pageIndicator.pack(side="right", padx=(5,5)) leftButton = tk.Button(pageFrame, text="<", font=("Proxima Nova Rg", 11), fg="white", bg=bg, width=2, command=lambda: navigateLeft(leftButton, farLeftButton, rightButton, farRightButton, pageIndicator, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, componentFrame)) farLeftButton = tk.Button(pageFrame, text="<<", font=("Proxima Nova Rg", 11), fg="white", bg=bg, width=2, command=lambda: navigateFarLeft(leftButton, farLeftButton, rightButton, farRightButton, pageIndicator, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, componentFrame)) leftButton.pack(side="right", padx=(5,5)) farLeftButton.pack(side="right", padx=(5,5)) if webScrapingPage <= 1: leftButton.config(state=DISABLED) farLeftButton.config(state=DISABLED)
def navigateRight(leftNavigationButton, rightNavigationButton, titleFrame, contentFrame, imageFrame, finalTitles, finalResults, imageSelections, imageCounter, thumbnails, pageIndicator): global currentPage currentPage += 1 # handle navigation frame if currentPage == len(finalResults): rightNavigationButton.config(state=DISABLED) leftNavigationButton.config(state=NORMAL) pageIndicator.config(text=str(currentPage) + "/" + str(len(finalResults))) # rerender title, content, and image frame widgetList = allWidgets(titleFrame) for item in widgetList: item.pack_forget() widgetList = allWidgets(contentFrame) for item in widgetList: item.pack_forget() widgetList = allWidgets(imageFrame) for item in widgetList: item.pack_forget() tk.Label(titleFrame, text=finalTitles[(currentPage - 1)] + "\n", font=("Proxima Nova Rg", 11), fg="white", bg=bg, bd=-10, anchor="w").pack(side="top", anchor="w") # remove leading newline character tk.Label(contentFrame, text=finalResults[(currentPage - 1)].lstrip() + '\n', font=("Proxima Nova Rg", 11), fg="white", bg=bg, justify="left", bd=-10, anchor="center").pack(anchor="center") renderImage(imageFrame, imageSelections, imageCounter, thumbnails, (currentPage - 1))
def navigateFarLeft(leftButton, farLeftButton, rightButton, farRightButton, pageIndicator, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, componentFrame): global currentPage currentPage=1 leftButton.config(state=DISABLED) farLeftButton.config(state=DISABLED) if webScrapingPage > 1: rightButton.config(state=NORMAL) farRightButton.config(state=NORMAL) # rerender page indicator pageIndicator.config(text=str(currentPage) + "/" + str(webScrapingPage)) # rerender left and right components widgetList = allWidgets(componentFrame) for item in widgetList: item.pack_forget() leftComponentFrame, rightComponentFrame = resetLeftRightFrames(componentFrame) # left component renderLeftComponent(webScrapingLeftPane, leftComponentFrame, webScrapingLinks, currentPage) # right component renderRightComponent(webScrapingRightPane, rightComponentFrame, currentPage)
def navigateLeft(leftButton, farLeftButton, rightButton, farRightButton, pageIndicator, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, componentFrame): global currentPage currentPage -= 1 if currentPage <= 1: leftButton.config(state=DISABLED) farLeftButton.config(state=DISABLED) rightButton.config(state=NORMAL) farRightButton.config(state=NORMAL) # rerender page indicator pageIndicator.config(text=str(currentPage) + "/" + str(webScrapingPage)) # rerender left and right components widgetList = allWidgets(componentFrame) for item in widgetList: item.pack_forget() leftComponentFrame = tk.Frame(componentFrame, bg=bg) leftComponentFrame.pack(side="left", anchor="w", fill=Y) rightComponentFrame = tk.Frame(componentFrame, bg=bg) rightComponentFrame.pack(side="right", anchor="e", fill=Y) # left component renderLeftComponent(webScrapingLeftPane, leftComponentFrame, webScrapingLinks, currentPage) # right component renderRightComponent(webScrapingRightPane, rightComponentFrame, currentPage)
def junodownloadSearch(filename, track, artistVariations, titleVariations, headers, search, webScrapingWindow, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, labelFrame, searchFrame, pageFrame, componentFrame, audio, options, initialCounter, imageCounter, images): global count count = 0 widgetList = allWidgets(searchFrame) for item in widgetList: item.pack_forget() if len(filename) > 60: tk.Label(searchFrame, text="\nSearching Juno Download for " + str(filename)[0:59] + "...", font=("Proxima Nova Rg", 13), fg="white", bg=bg).pack(side="left", padx=(10, 0), anchor='w') else: tk.Label(searchFrame, text="\nSearching Juno Download for " + str(filename), font=("Proxima Nova Rg", 13), fg="white", bg=bg).pack(side="left", padx=(10, 0), anchor='w') leftComponentFrame, rightComponentFrame = resetLeftRightFrames( componentFrame) refresh(webScrapingWindow) url = "https://www.google.co.in/search?q=" + search + " Junodownload" soup = prepareRequest(url, headers, webScrapingWindow, leftComponentFrame) if soup != False: for result in soup.find_all('div', class_="ZINbbc xpd O9g5cc uUPGi"): if 'junodownload.com' and 'products' in result.find('a').get( 'href').split('&')[0].lower(): resultString = str(result).replace('&', 'and').lower() for variation in titleVariations: variation = variation.replace('-', ' ') if variation.lower() in resultString: link = result.find('a').get('href').split('&')[0][7:] refresh(webScrapingWindow) soup = prepareRequest(link, headers, webScrapingWindow, leftComponentFrame) if soup != False: # post link to web scraping window widgetList = allWidgets(componentFrame) for widget in widgetList: widget.pack_forget() widgetList = allWidgets(pageFrame) for widget in widgetList: widget.pack_forget() # increment web scraping page and rerender count webScrapingPage += 1 leftComponentFrame, rightComponentFrame = resetLeftRightFrames( componentFrame) rerenderControls(pageFrame, webScrapingPage) if len(link) >= 75: label = tk.Label(leftComponentFrame, text="\n" + str(link)[0:74] + "...", cursor="hand2", font=("Proxima Nova Rg", 11), fg="white", bg=bg) else: label = tk.Label(leftComponentFrame, text="\n" + str(link), cursor="hand2", font=("Proxima Nova Rg", 11), fg="white", bg=bg) label.bind( "<Button-1>", lambda e, link=link: webbrowser.open_new(link)) label.pack(padx=(10, 0), pady=(0, 25), anchor='w') # update left component history frame webScrapingLeftPane[ webScrapingPage] = leftComponentFrame # assume match will fail and no image will be found webScrapingRightPane[webScrapingPage] = "NA" # update link webScrapingLinks[webScrapingPage] = link finalMatch = False # search individual listings in table for item in soup.find_all( 'div', class_= "row gutters-sm align-items-center product-tracklist-track" ): name = item.find('span').get_text() if ' - ' in name: trackArtist = item.find( 'span').get_text().split(' - ')[0] trackTitle = item.find( 'span').get_text().split(' - ')[1] else: trackArtist = '' trackTitle = item.find('span').get_text() if not compareTokens(variation, trackTitle): # check runtime to ensure track is correct runtime = item.find( 'div', class_= "col-1 d-none d-lg-block text-center" ).get_text() if not compareRuntime(runtime, audio): count += 1 finalMatch = True for value in item.find_all( 'div', class_= "col-1 d-none d-lg-block text-center" ): # extract BPM if ":" not in value.get_text( ) and value.get_text( ) != '\xa0' and "BPM" in options[ "Selected Tags (L)"]: BPM = value.get_text() tk.Label( leftComponentFrame, text="BPM: " + str(BPM), font=("Proxima Nova Rg", 11), fg="white", bg=bg).pack(padx=(10, 0), pady=(5, 0), anchor='w') webScrapingLeftPane[ webScrapingPage] = leftComponentFrame refresh(webScrapingWindow) track.BPMList.append(int(BPM)) track.BPMList.append(int(BPM)) # only push release and genre from header if title is found in tracklist for data in soup.select( 'div[class=mb-3]'): # extract release date if "Release_Date" in options[ "Selected Tags (L)"]: release = data.find( "span", itemprop="datePublished" ).get_text() tk.Label( leftComponentFrame, text="Year: " + str(release), font=("Proxima Nova Rg", 11), fg="white", bg=bg).pack(padx=(10, 0), pady=(5, 0), anchor='w') track.yearList.append( int(release[-4:])) # extract genre if "Genre" in options[ "Selected Tags (L)"]: genre = data.find( "a").get_text() tk.Label( leftComponentFrame, text="Genre: " + str(genre), font=("Proxima Nova Rg", 11), fg="white", bg=bg).pack(padx=(10, 0), pady=(5, 0), anchor='w') track.genreList.append(genre) webScrapingLeftPane[ webScrapingPage] = leftComponentFrame # extract image if options[ "Extract Image from Website (B)"].get( ) == True and track.stop == False: try: item = soup.find( 'div', class_="jw-page") item = item.find('img').get( 'data-src-full') # write junodownload image to drive with open( resource_path( 'Temp/' + str(imageCounter) + '.jpg'), "wb") as file: file.write( requests.get( item, headers=headers). content) track.URLList.append(item) # load file icon fileImageImport = Image.open( resource_path( 'Temp/' + str(imageCounter) + '.jpg')) width, height = fileImageImport.size fileImageImport = fileImageImport.resize( (200, 200), Image.ANTIALIAS) images.append([ fileImageImport, width, height ]) photo = ImageTk.PhotoImage( fileImageImport) fileImage = tk.Label( rightComponentFrame, image=photo, bg=bg) fileImage.image = photo fileImage.pack(padx=(0, 100), anchor="e") imageCounter += 1 refresh(webScrapingWindow) webScrapingRightPane[ webScrapingPage] = rightComponentFrame # perform image scraping if enabled in options if options[ "Reverse Image Search (B)"].get( ) == True and not track.stop: if not performSearch( initialCounter, imageCounter): imageCounter, images, track = reverseImageSearch( item, headers, imageCounter, images, track, options) except: pass # avoid counting the same entry twice if not finalMatch: tk.Label( leftComponentFrame, text= "Track did not match with any of the listings", font=("Proxima Nova Rg", 11), fg="white", bg=bg).pack(padx=(10, 0), pady=(5, 0), anchor="w") refresh(webScrapingWindow) break if options['Limit Number of Matches per Site (B)'].get( ) and count >= options['Match Limit (I)'].get(): break return track, imageCounter, images, webScrapingLeftPane, webScrapingRightPane, webScrapingLinks, webScrapingPage, searchFrame, pageFrame, componentFrame