Esempio n. 1
0
def extract_review_artists(artist):

	print ('Extracting reviews: {0}').format(artist['name'].encode('ascii', 'ignore'))
	try:
		en_artist = echonest_artist.Artist(artist['echonest_data']['echonest_id'])

		print en_artist.reviews
	
		for review in en_artist.reviews:
			url = review['url']
			domain = urlparse.urlparse(url).netloc
			
			try:
				text = Goose().extract(url).cleaned_text
				review_artists = []

				for extracted_artist in echonest_artist.extract(text, results=99):
					print extracted_artist
					review_artists.append(find_insert({"name":extracted_artist.name}, {"name":extracted_artist.name,"echonest_data":{"echonest_id":extracted_artist.id}}, False, False)['_id'])
			
				db.artist.update({"_id": artist['_id']}, {"$set": {"echonest_data.review_artists":review_artists}})	

			except Exception as e:
				print 'Goose Error {0}'.format(e)
			
	except EchoNestAPIError as e:
		print e	
		if e.code == 3:
			print "sleeping 10 seconds"
			time.sleep(10)
			extract_review_artists(artist)
Esempio n. 2
0
    def create_artist_from_text(text, venue, redis=None):
        """
        Static method that aims in extracting artist name from a text
        and creating an instance of this class based on it
        """

        # remove venue name from the title of the event
        # it will improve the finding of the artist name from the event title
        if venue:
            text = text.replace(venue, '')

        try:
            event_artist = echonest_artist.extract(text=text, results=1)
        except (EchoNestAPIError, EchoNestIOError):
            log.error('could not find artist %s', sys.exc_info()[0])
            return

        log.debug('Event artist from echonest: %s', event_artist)

        artist_name = ''
        if event_artist:
            artist_name = event_artist[0].name

        if artist_name:
            return Artist(artist_name, redis)

        return
Esempio n. 3
0
def parse(text):
	# TODO: Return only hotttest artist? Or list of artists?
	# TODO: Remove text containing time string  
	results = artist.extract(text=text, limit=False, buckets="id:spotify-WW")
	artist_uri = None
	hotttnesss_max = 0
	for result in results:		
		hotttnesss = result.get_hotttnesss()
		if hotttnesss > hotttnesss_max:
			hotttnesss_max = hotttnesss
			spotify_ww = result.get_foreign_id(idspace="spotify-WW")
			if spotify_ww:
				artist_uri = spotify_ww.replace("spotify-WW", "spotify")
	return artist_uri
Esempio n. 4
0
    def get_context_data(self, **kwargs):
        query = self.request.GET.get('query', '')
        parts = query.lower().split()
        artists, songs = [], []

        if any(p in moods for p in parts):
            for part in parts:
                if part in moods:
                    artists.extend(eartist.similar(mood=part, results=15))
        if any(p in styles for p in parts):
            for part in parts:
                if part in styles:
                    artists.extend(eartist.similar(style=part, results=15))

        random.shuffle(artists)

        extracted = eartist.extract(query)
        if extracted:
            for artist in extracted:
                artists.insert(0, eartist.Artist(id=artist.id))
            artists.extend(eartist.similar(ids=[art.id for art in extracted], results=15))

        if artists:
            songs = list(flatten_iterator(a.get_songs() for a in artists))
            #random.shuffle(songs)

        real = {}
        for song in songs:
            real[song.title] = song

        retval = [{
            'track': s.title,
            'artist': s.artist_name,
            'album': ''
        } for s in real.values()[:15]]

        print retval, len(retval)

        info = requests.get('http://api.jamendo.com/get2/id+name+duration+stream+album_name+artist_name/track/json/track_album+album_artist/',
                            params={'searchquery': query, 'streamencoding': 'ogg2', 'n': 5})

        items = [{
            'track': s['name'],
            'artist': s['artist_name'],
            'album': s['album_name']
        } for s in json.loads(info.content)]
        for item in items:
            retval.append(item)

        return retval
Esempio n. 5
0
	print str(page) + " - " + str(len(scores))
	for score in scores:
		try:
			scoreid = score['id']

			#get a score
			url = endpoint + "/" + str(scoreid) + '.' +format + '&oauth_consumer_key=' + apikey
			r = requests.get(url)
			score = r.json()

			scoreComposer = score['metadata']['composer']

			description = False
			# try to get the score composer in the composer string
			
			results = artist.extract(scoreComposer)
			
			# if not found try in the description
			if (len(results) == 0):	
				results = artist.extract(score['description'])
				description = True

			
			if (len(results) > 0):
			    found = findSongsInArray(results, score)
			    if( not found and not description):
			    	try:
			    		results = artist.extract(score['description'])
			    		found = findSongsInArray(results, score)
			    	except EchoNestIOError:
						print "pyechonest.util.EchoNestIOError"