def discogs_id_by_url(url, type='uri'): log = logging.getLogger('importer.base.discogs_artist_id_by_url') discogs_id = None discogs.user_agent = "NRG Processor 0.01 http://anorg.net/" try: id = url.split('/') id = id[-1] if '/master/' in url: log.debug('Type is "master-release"') item = discogs.MasterRelease(int(id)) if '/release/' in url: log.debug('Type is "release"') item = discogs.Release(int(id)) if '/artist/' in url: log.debug('Type is "artist"') item = discogs.Artist(id) time.sleep(1.1) discogs_id = item.data['id'] except Exception, e: log.info('Unable to get id: %s', e)
def discogs_id_by_url(url, type='uri'): discogs_id = None discogs.user_agent = "NRG Processor 0.01 http://anorg.net/" try: id = url.split('/') id = id[-1] try: return '%s' % int(id) except: if '/master/' in url: log.debug('Type is "master-release"') item = discogs.MasterRelease(int(id)) if '/release/' in url: log.debug('Type is "release"') item = discogs.Release(int(id)) if '/artist/' in url: log.debug('Type is "artist"') item = discogs.Artist(id) time.sleep(1.1) return item.data['id'] except Exception, e: log.info('Unable to get id: %s', e)
def discogs_get_image(search): artist = discogs.Artist(search) if search.startswith('The'): artist = discogs.Artist(search[3:] + ', The') images = artist.data['images'] location = settings.STATIC_ROOT + 'discogs/images/' + clean_names( search) + '/' mkdir_p(location) for img in images: url = img['uri'] if not os.path.isfile(location + filename(url)): urllib.urlretrieve(url, location + filename(url)) json_dump = json.dumps(dir_contents(location)) return json_dump
def DiscogsCrawler(path, queue): info = Struct() threadCrawlerLock.acquire(0) filename = os.path.basename(path) filename = os.path.splitext(filename)[0].lower() keywords = filename.split(' - ')[0] keywords = keywords.split('pres')[0] keywords = keywords.split('feat')[0] keywords = keywords.split('with')[0] keywords = keywords.split('and')[0] discogs.user_agent = 'muteklab/1.0 +http://www.muteklab.com' artist = discogs.Artist(keywords) try: keys = artist.data.keys() except Exception: queue.put(None) return if u'id' in keys: info.id = artist.data[u'id'] if u'name' in keys: info.name = artist.data[u'name'] if u'aliases' in keys: info.aliases = artist.data[u'aliases'] if u'namevariations' in keys: info.namevariations = artist.data[u'namevariations'] if u'realname' in keys: info.realname = artist.data[u'realname'] if u'members' in keys: info.members = artist.data[u'members'] collected = gc.collect() info.images = list() info.releases = list() random.randrange(0, len(artist.releases)) randomIdx = random.sample(range(len(artist.releases)), len(artist.releases)) for i in randomIdx: try: release = artist.releases[i] data = '%s %s' % (release.data['year'], release.data['title']) info.releases.append(data) if 'images' in release.data.keys(): # uri = release.data['images'][0]['uri'] uri = release.data['images'][0]['uri150'] artwork = urllib.urlopen(uri).read() info.images.append(artwork) queue.put(info) except Exception: pass gc.collect()
def discogs_image_by_url(url, type='uri'): log = logging.getLogger('importer.base.discogs_image_by_url') image = None discogs.user_agent = "NRG Processor 0.01 http://anorg.net/" try: id = url.split('/') id = id[-1] log.debug('Lookup image for discog id: %s' % (id)) if '/master/' in url: log.debug('Type is "master-release"') item = discogs.MasterRelease(int(id)) if '/release/' in url: log.debug('Type is "release"') item = discogs.Release(int(id)) if '/artist/' in url: log.debug('Type is "artist"') item = discogs.Artist(id) time.sleep(1.1) imgs = item.data['images'] have_img = False for img in imgs: if img['type'] == 'primary': print img image = img[type] have_img = True if not have_img: for img in imgs: if img['type'] == 'secondary': print img image = img[type] except Exception, e: log.info('Unable to get image: %s', e)
def run(self): # socket.setdefaulttimeout(3) artist = self.parent.parent.parent.GetSelectedItemsKeyValue( 'artist')[0] discogs.user_agent = 'muteklab/1.0 +http://www.muteklab.com' artist = discogs.Artist(artist) try: keys = artist.data.keys() except Exception: # queue.put(None) return if u'id' in keys: self.info.id = artist.data[u'id'] if u'name' in keys: self.info.name = artist.data[u'name'] if u'aliases' in keys: self.info.aliases = artist.data[u'aliases'] if u'namevariations' in keys: self.info.namevariations = artist.data[u'namevariations'] if u'realname' in keys: self.info.realname = artist.data[u'realname'] if u'members' in keys: self.info.members = artist.data[u'members'] collected = gc.collect() self.info.images = list() self.info.releases = list() random.randrange(0, len(artist.releases)) randomIdx = random.sample(range(len(artist.releases)), len(artist.releases)) for i in randomIdx: try: release = artist.releases[i] data = '%s %s' % (release.data['year'], release.data['title']) self.info.releases.append(data) # print(i) # if 'images' in release.data.keys(): # # uri = release.data['images'][0]['uri'] # uri = release.data['images'][0]['uri150'] # artwork = urllib.urlopen(uri).read() # info.images.append(artwork) # queue.put(info) except Exception: pass gc.collect()
def MetaCrawler(path, queue): threadCrawlerLock.acquire(0) info = Struct() info.google = Struct() info.discogs = Struct(idx=None, name=None, aliases=None, namevariations=None, realname=None, members=None, releases=None) info.echonest = Struct(artist=None, similar=None) info.gracenote = Struct() filename = os.path.basename(path) filename = os.path.splitext(filename)[0].lower() keywords = filename.split(' - ')[0] keywords = keywords.split('pres')[0] keywords = keywords.split('feat')[0] keywords = keywords.split('with')[0] keywords = keywords.split('and')[0] keywords = u'%s' % (keywords) echonest_config.ECHO_NEST_API_KEY = '3NUCRNQMMTWBDJCSL' try: bk = echonest_artist.Artist(keywords) info.echonest.artist = bk.name info.echonest.similar = list() for v in bk.similar: info.echonest.similar.append(v.name) except Exception: pass queue.put(info) discogs.user_agent = 'muteklab/1.0 +http://www.muteklab.com' artist = discogs.Artist(keywords) try: keys = artist.data.keys() if u'id' in keys: info.discogs.idx = artist.data[u'id'] if u'name' in keys: info.discogs.name = artist.data[u'name'] if u'aliases' in keys: info.discogs.aliases = artist.data[u'aliases'] if u'namevariations' in keys: info.discogs.namevariations = artist.data[u'namevariations'] if u'realname' in keys: info.discogs.realname = artist.data[u'realname'] if u'members' in keys: info.discogs.members = artist.data[u'members'] except Exception: pass queue.put(info) # info.discogs.images = list() info.discogs.releases = list() try: # random.randrange(0, len(artist.releases)) # randomIdx = random.sample(range(len(artist.releases)), len(artist.releases)) # for i in randomIdx: for i in range(len(artist.releases)): release = artist.releases[i] data = '%s %s' % (release.data['year'], release.data['title']) info.discogs.releases.append(data) # if 'images' in release.data.keys(): # # uri = release.data['images'][0]['uri'] # uri = release.data['images'][0]['uri150'] # artwork = urllib.urlopen(uri).read() # info.discogs.images.append(artwork) queue.put(info) except Exception: pass queue.put(info) gc.collect()