Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from bs4 import BeautifulSoup
- import urllib.request
- import random
- import subprocess
- try:
- input_genre = input('Please Enter A Genre: ')
- input_bpm = input('Please Enter A BPM: ')
- input_year1 = input('Please Enter Year 1: ')
- input_year2 = input('Please Enter Year 2: ')
- if input_year1 != "" and input_year2 != "":
- yearlist = list(range(int(input_year1), int(input_year2) + 1))
- stringyearlist = [str(i) for i in yearlist]
- else:
- stringyearlist = [0]
- while True:
- number = random.randint(0,9000000)
- outfile = open("testfile.txt","w")
- try:
- print("\n\n")
- url = "http://classic.beatport.com/track/song/" + str(number)
- soup = BeautifulSoup(urllib.request.urlopen(url).read(), 'html.parser')
- # title
- title = soup.find('h2', attrs={'class': 'txt-xxlarge'}).contents[0]
- # mix
- try:
- mix = soup.find('h2', attrs={'class': 'txt-xxlarge'}).find('span').contents[0]
- except:
- mix = ""
- # artist
- artist = soup.find('span', attrs={'class': 'artists-value h4 fontCondensed'}).findChild().contents[0]
- genre = soup.find('div', attrs={'class': 'waveform-meta-container'}).find('ul', attrs={'class': 'waveform-meta'}).find('li').find_next_sibling('li').find_next_sibling('li').find_next_sibling('li').find_next_sibling('li').find('a').contents[0]
- bpm = soup.find('div', attrs={'class': 'waveform-meta-container'}).find('ul', attrs={'class': 'waveform-meta'}).find('li').find_next_sibling('li').find_next_sibling('li').find('span', attrs={'class': 'meta-value txt-dark-grey fontCondensed'}).contents[0]
- date = soup.find('div', attrs={'class': 'waveform-meta-container'}).find('ul', attrs={'class': 'waveform-meta'}).find('li').find_next_sibling('li').find('span', attrs={'class': 'meta-value txt-dark-grey fontCondensed'}).contents[0]
- year = date.split("-").pop(0)
- if input_genre == genre or input_genre == "":
- if input_bpm == bpm or input_bpm == "":
- if year in stringyearlist or stringyearlist[0] == 0:
- print("Artist: " + artist)
- outfile.write("Artist: " + artist + "\n")
- outfile.flush()
- print("Title: " + title + " " + "(" + mix + ")")
- outfile.write("Title: " + title + " " + "(" + mix + ")" + "\n")
- outfile.flush()
- print("Genre: " + genre)
- outfile.write("Genre: " + genre + "\n")
- outfile.flush()
- print("BPM: " + bpm)
- outfile.write("BPM: " + bpm + "\n")
- outfile.flush()
- print("Link: " + url.replace("classic.beatport.com", "crates.co"))
- outfile.write("Link: " + url + "\n")
- outfile.flush()
- print("CTRL+C to Stop\n\n")
- #p = subprocess.Popen("mplayer http://geo-samples.beatport.com/lofi/" + str(number) + ".LOFI.mp3 -cache 9999", shell=False)
- outfile.close()
- except KeyboardInterrupt:
- p.terminate()
- print("press enter to continue")
- input()
- except:
- pass
- except:
- outfile.close()
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement