Пример #1
0
class mbzAPI:
    def __init__(self):
        self.q = Query()

    def findArtists(self, artist, limit = 20):
        try:
            aFilter = ArtistFilter(artist, limit)
            return self.q.getArtists(aFilter)
        except WebServiceError, e:
            # Logging Need
            return None
Пример #2
0
	def getArtists(self,filter=filter) :
		p = md5.new(pickle.dumps(filter)).hexdigest()
		cache_file = os.path.join(CACHE_DIR,'artist_q',p)
		if os.path.exists(cache_file) :
			instream = open(cache_file,"r")
			toret = pickle.loads(instream.read())
			instream.close()
			return toret
		else :
			self.throttle()
			toret = Query.getArtists(self,filter=filter)
			outstream = open(cache_file,"w")
			outstream.write(pickle.dumps(toret))
			outstream.close()
			return toret
Пример #3
0
 def getArtists(self, filter=filter):
     p = md5.new(pickle.dumps(filter)).hexdigest()
     cache_file = os.path.join('cache', 'artist_q', p)
     if os.path.exists(cache_file):
         instream = open(cache_file, "r")
         toret = pickle.loads(instream.read())
         instream.close()
         return toret
     else:
         self.throttle()
         toret = Query.getArtists(self, filter=filter)
         outstream = open(cache_file, "w")
         outstream.write(pickle.dumps(toret))
         outstream.close()
         return toret
Пример #4
0
def main(argv=None):
	if argv==None:
		argv=sys.argv
	
	q = Query()
	
	conn = sqlite3.connect('db/mu_trumps.sqlite3')
	c = conn.cursor()
	insert_cursor = conn.cursor()
	c.execute('select * from artists')
	
	for artist_id, created, modified, artist_name, artist_url in c:
		try:
			# Search for all artists matching the given name. Limit the results
			# to the best match. 
			f = ArtistFilter(name=artist_name, limit=5)
			artistResults = q.getArtists(f)
		except WebServiceError, e:
			print 'Error:', e
			if "HTTP Error 503" in str(e):
				print "taking a rest..."
				sleep(SLEEP_TIME*10)
			continue
		try:
			mbz_id = artistResults[0].artist.id
		except IndexError:
			print "Could not find a musicbrainz id for the artist", artist_name, "moving on..."
			continue
		if VERBOSE:
			print "For artist", artist_name, "found id", artist_id
		try:
			# The result should include all official albums.
			#
			inc = ws.ArtistIncludes(
				releases=(m.Release.TYPE_OFFICIAL, m.Release.TYPE_ALBUM),
				tags=True, releaseGroups=True)
			artist = q.getArtistById(mbz_id, inc)
		except ws.WebServiceError, e:
			print 'Error:', e
			if "HTTP Error 503" in str(e):
				print "taking a rest..."
				sleep(SLEEP_TIME*10)
			continue
Пример #5
0
 def get_musicbrainz_id(self):
     """
     Retrieve the MusicBrainz id for this artist and save it on the
     model.
     """
     # Make sure the useful bits of the musicbrainz2 package have been
     # imported.
     try:
         Query, ArtistFilter
     except NameError:
         return False
     # Query MusicBrainz.
     artist_filter = ArtistFilter(name=self.name)
     query = Query()
     try:
         artist = query.getArtists(artist_filter)[0].artist
         self.mbid = artist.id.rsplit("/", 1)[1]
         self.save()
     except (IndexError, AttributeError):
         return False
Пример #6
0
 def get_musicbrainz_id(self):
     """
     Retrieve the MusicBrainz id for this artist and save it on the
     model.
     """
     # Make sure the useful bits of the musicbrainz2 package have been
     # imported.
     try:
         Query, ArtistFilter
     except NameError:
         return False
     # Query MusicBrainz.
     artist_filter = ArtistFilter(name=self.name)
     query = Query()
     try:
         artist = query.getArtists(artist_filter)[0].artist
         self.mbid = artist.id.rsplit("/", 1)[1]
         self.save()
     except (IndexError, AttributeError):
         return False
Пример #7
0
    def getArtists(self, name, date=None, disambiguation=None):
        q = Query()

        if disambiguation:
            disPattern = re.compile(disambiguation, re.I)
        else:
            disPattern = None

        offset = 0
        limit = 100
        artistResults = set()
        while True:
            try:
                f = ArtistFilter(name=name, offset=offset, limit=limit)
                results = q.getArtists(f)
            except WebServiceError, e:
                raise SourceError

            results = filter(lambda res: res.getScore() == 100, results)
            # use filtered count because resulsts are score-ordered
            count = len(results)

            results = filter(
                lambda res:
                (not date or res.getArtist().getBeginDate() == date) and
                (not disPattern or disPattern.search(res.getArtist(
                ).getDisambiguation())), results)

            for r in results:
                ar = ArtistResult(name=r.getArtist().getName(),
                                  date=r.getArtist().getBeginDate(),
                                  disambiguation=disambiguation)
                # use original disambiguation cause it'll be used in
                # artist's comparation

                ar.setKey(MusicbrainzSource._sourceName, r.getArtist().getId())
                artistResults.add(ar)

            if count < limit:
                break
            offset += count
Пример #8
0
    def getArtists(self, name, date = None, disambiguation = None):
        q = Query()

        if disambiguation:
            disPattern = re.compile(disambiguation, re.I)
        else:
            disPattern = None

        offset = 0
        limit = 100
        artistResults = set()
        while True:
            try:
                f = ArtistFilter(name = name, offset = offset, limit = limit)
                results = q.getArtists(f)
            except WebServiceError, e:
                raise SourceError

            results = filter(lambda res: res.getScore() == 100, results)
            # use filtered count because resulsts are score-ordered
            count = len(results)

            results = filter(lambda res: 
                    (not date or res.getArtist().getBeginDate() == date)
                    and ( not disPattern or
                        disPattern.search(res.getArtist().getDisambiguation()) ),
                    results)

            for r in results:
                ar = ArtistResult(name = r.getArtist().getName(),
                        date = r.getArtist().getBeginDate(),
                        disambiguation = disambiguation)
                        # use original disambiguation cause it'll be used in 
                        # artist's comparation

                ar.setKey(MusicbrainzSource._sourceName, r.getArtist().getId())
                artistResults.add(ar)

            if count < limit:
                break
            offset += count
Пример #9
0
logger.setLevel(logging.ERROR)
sys.stdout = codecs.getwriter('utf8')(sys.stdout) # workaround for pipes

if len(sys.argv) < 2:
	print "Usage:", os.path.basename(sys.argv[0]), "'artist name' [offset]"
	sys.exit(1)

q = Query()

try:
	# Search for all artists matching the given name. Limit the results
	# to the 5 best matches. The offset parameter could be used to page
	# through the results.
	#
	f = ArtistFilter(name=sys.argv[1], limit=10)
	artistResults = q.getArtists(f)
except WebServiceError, e:
	print 'Error:', e
	sys.exit(1)

if len(sys.argv) > 2:
	artistResults = [artistResults[int(sys.argv[2])]]
else:
	artistResults = [artistResults[0]]
	
tracks_ids = []
for result in artistResults:
	artist_name = result.artist
	releases = []
	for rtype in [m.Release.TYPE_ALBUM, m.Release.TYPE_SINGLE, m.Release.TYPE_COMPILATION, m.Release.TYPE_REMIX]:
		artist = q.getArtistById(artist_name.id, ArtistIncludes(
Пример #10
0
import musicbrainz2.webservice as ws
import musicbrainz2.model as model

# Notifo API settings
USERNAME = ""
API_KEY = ""

# NZBMatrix Account Details
#API_URL = "http://api.nzbmatrix.com/v1.1/search.php?search=" + searchTerm + #"&catid=22&age=800&username=burningfire&apikey=75390295cf99a1db49c9314c86061405"

connection = sqlite3.connect('musicSearch.db')
cursor = connection.cursor()

q = Query()
query = ArtistFilter("Streetlight Manifesto", limit=2)
artistResults = q.getArtists(query)

path = "C:\Users\Mongo\Music\iTunes\iTunes Media\Music"
unknown = ".+unknown.+"

itunesArtist = os.listdir(path)
artistExists = 0


def findArtist():
    artistName = cursor.execute('SELECT ArtistName FROM Artists')

    for i in itunesArtist:
        try:
            filter = ArtistFilter(i, limit=2)
            artistResults = q.getArtists(filter)
Пример #11
0
import musicbrainz2.webservice as ws
import musicbrainz2.model as model

# Notifo API settings
USERNAME = ""
API_KEY = ""

# NZBMatrix Account Details
#API_URL = "http://api.nzbmatrix.com/v1.1/search.php?search=" + searchTerm + #"&catid=22&age=800&username=burningfire&apikey=75390295cf99a1db49c9314c86061405"

connection = sqlite3.connect('musicSearch.db')
cursor = connection.cursor()

q = Query()
query = ArtistFilter("Streetlight Manifesto", limit = 2)
artistResults = q.getArtists(query)

path = "C:\Users\Mongo\Music\iTunes\iTunes Media\Music"
unknown = ".+unknown.+"

itunesArtist = os.listdir(path)
artistExists = 0

def findArtist():
    artistName = cursor.execute('SELECT ArtistName FROM Artists')
    
    for i in itunesArtist:
        try:
            filter = ArtistFilter(i, limit = 2)
            artistResults = q.getArtists(filter)
        except WebServiceError, e: