Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.89 KB | None | 0 0
  1. from bs4 import BeautifulSoup
  2. import urllib.request
  3. import random
  4. import subprocess
  5. try:
  6.  
  7.     input_genre = input('Please Enter A Genre: ')
  8.     input_bpm = input('Please Enter A BPM: ')
  9.     input_year1 = input('Please Enter Year 1: ')
  10.     input_year2 = input('Please Enter Year 2: ')
  11.  
  12.     if input_year1 != "" and input_year2 != "":
  13.  
  14.         yearlist = list(range(int(input_year1), int(input_year2) + 1))
  15.         stringyearlist = [str(i) for i in yearlist]
  16.     else:
  17.         stringyearlist = [0]
  18.  
  19.     while True:
  20.  
  21.         number = random.randint(0,9000000)
  22.         outfile = open("testfile.txt","w")
  23.        
  24.  
  25.         try:
  26.             print("\n\n")
  27.             url = "http://classic.beatport.com/track/song/" + str(number)
  28.             soup = BeautifulSoup(urllib.request.urlopen(url).read(), 'html.parser')
  29.             # title
  30.             title = soup.find('h2', attrs={'class': 'txt-xxlarge'}).contents[0]
  31.             # mix
  32.             try:
  33.                 mix = soup.find('h2', attrs={'class': 'txt-xxlarge'}).find('span').contents[0]
  34.             except:
  35.                 mix = ""
  36.             # artist
  37.             artist = soup.find('span', attrs={'class': 'artists-value h4 fontCondensed'}).findChild().contents[0]
  38.  
  39.             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]
  40.  
  41.             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]
  42.  
  43.             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]
  44.  
  45.             year = date.split("-").pop(0)
  46.  
  47.  
  48.             if input_genre == genre or input_genre == "":
  49.                 if input_bpm == bpm or input_bpm == "":
  50.                     if year in stringyearlist or stringyearlist[0] == 0:
  51.                         print("Artist: " + artist)
  52.                         outfile.write("Artist: " + artist + "\n")
  53.                         outfile.flush()
  54.                         print("Title: " + title + " " + "(" + mix + ")")
  55.                         outfile.write("Title: " + title + " " + "(" + mix + ")" + "\n")
  56.                         outfile.flush()
  57.                         print("Genre: " + genre)
  58.                         outfile.write("Genre: " + genre + "\n")
  59.                         outfile.flush()
  60.                         print("BPM: " + bpm)
  61.                         outfile.write("BPM: " + bpm + "\n")
  62.                         outfile.flush()
  63.                         print("Link: " + url.replace("classic.beatport.com", "crates.co"))
  64.                         outfile.write("Link: " + url + "\n")
  65.                         outfile.flush()
  66.                         print("CTRL+C to Stop\n\n")
  67.                         #p = subprocess.Popen("mplayer http://geo-samples.beatport.com/lofi/" + str(number) + ".LOFI.mp3 -cache 9999", shell=False)
  68.                         outfile.close()
  69.         except KeyboardInterrupt:
  70.             p.terminate()
  71.             print("press enter to continue")
  72.             input()
  73.         except:
  74.             pass
  75.  
  76. except:
  77.     outfile.close()
  78.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement