here are two scripts which can fetch GENRE and STYLE tags from Discogs and put them in appropriate tags on any number of files or maybe your whole library
speed isn't it strong side, but it functions like this:
from every track ARTIST and ALBUM tags are used to get the discogs release ID, which is chosen as the first from the response list, and then according to GENRE/STYLE tags they are written to files
to use them you need to copy the files to the scripts folder (usually "C:\Program Files\foobar2000\pygrabber\scripts")
then, go to context menu > lyrics grabber > configuration and change the lyric field to appropriate field i.e. GENRE or STYLE depending on which script will run
Discogs_GetGenre.py
import urllib, urllib2, gzip, cStringIO
import xml.etree.ElementTree
from xml.dom import minidom
from encodings import utf_8
from grabber import LyricProviderBase
class Discogs_GetGenre(LyricProviderBase):
def GetName(self):
return 'Discogs Genre Tag'
def GetVersion(self):
return '0.1'
def GetURL(self):
return 'http://www.discogs.com'
def Query(self, handles, status, abort):
result = []
api_key = '783001745d'
for handle in handles:
status.Advance()
if abort.Aborting():
return result
artist = handle.Format("[%artist%]")
album = handle.Format("[%album%]")
try:
URL_s = 'http://www.discogs.com/search?type=all&q=' + artist.lower().replace(' ','+') + '+' + album.lower().replace(' ','+') + '&f=xml&api_key=' + api_key
request = urllib2.Request(URL_s)
request.add_header('Accept-Encoding', 'gzip')
response = urllib2.urlopen(request)
data = response.read()
unzipped_data = gzip.GzipFile(fileobj = cStringIO.StringIO(data)).read()
res = minidom.parseString(unzipped_data)
uri_1 = res.getElementsByTagName("uri")[0]
rel_id = uri_1.childNodes[0].data.encode('utf-8').rpartition('/')[2]
URL_r = 'http://www.discogs.com/release/' + rel_id + '?f=xml&api_key=' + api_key
request = urllib2.Request(URL_r)
request.add_header('Accept-Encoding', 'gzip')
response = urllib2.urlopen(request)
data = response.read()
unzipped_data = gzip.GzipFile(fileobj = cStringIO.StringIO(data)).read()
xml.etree.ElementTree.fromstring(unzipped_data)
def getGenres(tree):
genres = []
release = tree.find('release')
genreList = release.find('genres')
if genreList:
for i in genreList:
genres.append(i.text)
return genres
lyric=getGenres(xml.etree.ElementTree.fromstring(unzipped_data))
lyric=str(lyric).strip('[]').replace(',', ';').replace('\'','')
result.append(lyric)
except Exception, e:
traceback.print_exc(file=sys.stdout)
result.append('')
continue
return result
if __name__ == "__main__":
LyricProviderInstance = Discogs_GetGenre()
Discogs_GetStyle.py
import urllib, urllib2, gzip, cStringIO
import xml.etree.ElementTree
from xml.dom import minidom
from encodings import utf_8
from grabber import LyricProviderBase
class Discogs_GetStyle(LyricProviderBase):
def GetName(self):
return 'Discogs Style Tag'
def GetVersion(self):
return '0.1'
def GetURL(self):
return 'http://www.discogs.com'
def Query(self, handles, status, abort):
result = []
api_key = '783001745d'
for handle in handles:
status.Advance()
if abort.Aborting():
return result
artist = handle.Format("[%artist%]")
album = handle.Format("[%album%]")
try:
URL_s = 'http://www.discogs.com/search?type=all&q=' + artist.lower().replace(' ','+') + '+' + album.lower().replace(' ','+') + '&f=xml&api_key=' + api_key
request = urllib2.Request(URL_s)
request.add_header('Accept-Encoding', 'gzip')
response = urllib2.urlopen(request)
data = response.read()
unzipped_data = gzip.GzipFile(fileobj = cStringIO.StringIO(data)).read()
res = minidom.parseString(unzipped_data)
uri_1 = res.getElementsByTagName("uri")[0]
rel_id = uri_1.childNodes[0].data.encode('utf-8').rpartition('/')[2]
URL_r = 'http://www.discogs.com/release/' + rel_id + '?f=xml&api_key=' + api_key
request = urllib2.Request(URL_r)
request.add_header('Accept-Encoding', 'gzip')
response = urllib2.urlopen(request)
data = response.read()
unzipped_data = gzip.GzipFile(fileobj = cStringIO.StringIO(data)).read()
xml.etree.ElementTree.fromstring(unzipped_data)
def getStyles(tree):
styles = []
release = tree.find('release')
styleList = release.find('styles')
if styleList:
for i in styleList:
styles.append(i.text)
return styles
lyric=getStyles(xml.etree.ElementTree.fromstring(unzipped_data))
lyric=str(lyric).strip('[]').replace(',', ';').replace('\'','')
result.append(lyric)
except Exception, e:
traceback.print_exc(file=sys.stdout)
result.append('')
continue
return result
if __name__ == "__main__":
LyricProviderInstance = Discogs_GetStyle()
[edit] well, it is limited to 5,000 requests per 24-hour period, per IP address