def post(self): links_fetched = 0 if not self.request.POST.get('id'): # This is a temporary workaround to free up the task queue. It # seems that old tasks are stuck in an error-retry loop log.error('id not found in POST') self.response.out.write(simplejson.dumps({'success': False})) return track = PlaylistTrack.get(self.request.POST['id']) if track is None: # Track was deleted by DJ, other scenarios? log.warning('track does not exist: %s' % self.request.POST['id']) self.response.out.write(simplejson.dumps({'success': False})) return try: fm = pylast.get_lastfm_network( api_key=dbconfig['lastfm.api_key']) fm_album = fm.get_album(track.artist_name, track.album_title) track.lastfm_url_sm_image = \ fm_album.get_cover_image(pylast.COVER_SMALL) track.lastfm_url_med_image = \ fm_album.get_cover_image(pylast.COVER_MEDIUM) track.lastfm_url_large_image = \ fm_album.get_cover_image(pylast.COVER_LARGE) except pylast.WSError: # Probably album not found log.exception('IGNORED while fetching LastFM data') track.lastfm_urls_processed = True # Even on error track.save() memcache.delete(CurrentPlaylist.cache_key) self.response.out.write(simplejson.dumps({ 'success': True, 'links_fetched': links_fetched }))
def post(self): links_fetched = 0 if not self.request.POST.get('id'): # This is a temporary workaround to free up the task queue. It # seems that old tasks are stuck in an error-retry loop log.error('id not found in POST') self.response.out.write(simplejson.dumps({'success': False})) return track = PlaylistTrack.get(self.request.POST['id']) if track is None: # Track was deleted by DJ, other scenarios? log.warning('track does not exist: %s' % self.request.POST['id']) self.response.out.write(simplejson.dumps({'success': False})) return try: fm = pylast.get_lastfm_network( api_key=dbconfig['lastfm.api_key']) fm_album = fm.get_album(track.artist_name, track.album_title) track.lastfm_url_sm_image = \ fm_album.get_cover_image(pylast.COVER_SMALL) track.lastfm_url_med_image = \ fm_album.get_cover_image(pylast.COVER_MEDIUM) track.lastfm_url_large_image = \ fm_album.get_cover_image(pylast.COVER_LARGE) except pylast.WSError: # Probably album not found log.exception('IGNORED while fetching LastFM data') track.lastfm_urls_processed = True # Even on error track.save() memcache.delete(CurrentPlaylist.cache_key) _push_notify('chirpradio.push.update-playlist-storage') self.response.out.write(simplejson.dumps({ 'success': True, 'links_fetched': links_fetched }))
def get_lastfm_image_urls(self): fm = pylast.get_lastfm_network(api_key=dbconfig["lastfm.api_key"]) fm_album = fm.get_album(self.artist_name, self.title) self.lastfm_sm_image_url = fm_album.get_cover_image(pylast.COVER_SMALL) self.lastfm_med_image_url = fm_album.get_cover_image(pylast.COVER_MEDIUM) self.lastfm_lg_image_url = fm_album.get_cover_image(pylast.COVER_LARGE) self.lastfm_xl_image_url = fm_album.get_cover_image(pylast.COVER_EXTRA_LARGE) self.lastfm_retrieval_time = datetime.now() self.save()
def get_lastfm_image_urls(self): fm = pylast.get_lastfm_network(api_key=dbconfig['lastfm.api_key']) fm_album = fm.get_album(self.artist_name, self.title) self.lastfm_sm_image_url = fm_album.get_cover_image( pylast.COVER_SMALL) self.lastfm_med_image_url = fm_album.get_cover_image( pylast.COVER_MEDIUM) self.lastfm_lg_image_url = fm_album.get_cover_image( pylast.COVER_LARGE) self.lastfm_xl_image_url = fm_album.get_cover_image( pylast.COVER_EXTRA_LARGE) self.lastfm_retrieval_time = datetime.now() self.save()