Artist new release search program

This is the first program I've written that has actually served a real purpose to me, that I use frequently. Feel free to criticize and make any suggestions or corrections, because the code is probably pretty ugly. I hope it's readable. The program searches for the newest release of whatever electronic music artist you specify from trackitdown.net. Keep in mind please, that I'm a total python noob.

 

 

#!/usr/bin/python

 

from urllib import urlopen

from subprocess import call

 

print "\n+++++++++++++++++++++++++++++++++++++++++++++++++++++"

print "Artist new release search v1.0"

print "This program utilizes www.trackitdown.net for results"

print "+++++++++++++++++++++++++++++++++++++++++++++++++++++\n"

 

try:

  def artist_search():

    try:

      try:

        artist = raw_input('\nEnter artist name: ')

        print "\nSearching..."

 

        website = urlopen('http://www.trackitdown.net/search/advanced?artist=' + artist)

        text = website.read()

 

        import re

 

        artist = re.search('Artist: <a href="/artist/([^"]+)" title="([^"]+)">([^"]+)</a>', text, re.IGNORECASE)

        artist.group(1)

        track = re.search('<a href="/genre/([^"]+)/track/([^"]+).html"><strong>([^"]+)</strong>', text, re.IGNORECASE)

        track.group(1)

        date = re.search('release date: ([^"]+)<br />', text, re.IGNORECASE)

        date.group(1)

        urlpreview = re.search('<a href="([^"]+).mp3"', text, re.IGNORECASE)

        url = urlpreview.group(1)

      except AttributeError: print '\nNo artist found! Exiting...', quit()

 

      print "\nFound result!"

      print "\n======================================"

      print "Artist: " + artist.group(3)

      print "Track name: " + track.group(3)

      print "Release date: " + date.group(1)

      print "======================================\n"

 

      try:

        print "\nPreview at: " + urlpreview.group(1) + ".mp3"

        preview = raw_input('Play preview? y/n: ')

        if preview == 'y' : call(['mpg123', url + ".mp3"])

        if preview == 'n' : print "Exiting...", quit()

      except OSError: print "Looks like you don't have mpg123 installed! Exiting...", quit()

    except KeyboardInterrupt: search_again = raw_input("\nWould you like to perform another search? y/n: ")

    if search_again == "n" : print 'Exiting...', quit()

    if search_again == "y" : artist_search()

 

  artist_search()

except UnboundLocalError: print "\n", artist_search() 




Copyright(c) 2017 - PythonBlogs.com
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved