Here's a modification of what I described above.
This python script which is a modification of 2E7AH's scripts fetches Genre and Style from discogs. When it meets a track from an album it has not processed before, it writes those tags to a text file. If it meets a track from an album it has processed a track from before, it does not check discogs - rather, it just fetches the tags from those text files. In essence, it fetches discogs genre and style while minimizing the amount of requests. This will allow you to tag thousands more files per 24 hours. For temporary storage of information, it uses text files.
My text files are in the folder C:\Python26 .. Edit the script and change them for whatever values you want to use!
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 GenStyles'
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%]")
album_file = open("C:\Python26\!album.txt", "r")
test = album_file.read()
album_file.close()
try:
if album == test:
text_file = open("C:\Python26\!tag3.txt", "r")
writeout = text_file.read()
text_file.close()
result.append(writeout)
else:
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
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=getGenres(xml.etree.ElementTree.fromstring(unzipped_data))
lyric.append('//')
lyric.append(getStyles(xml.etree.ElementTree.fromstring(unzipped_data)))
lyric=str(lyric).strip('[').strip(']').replace(',', ';').replace('\'','').replace('[','')
result.append(lyric)
album_file = open("C:\Python26\!album.txt", "w")
album_file.write(album)
album_file.close()
text_file = open("C:\Python26\!tag3.txt", "w")
text_file.write(lyric)
text_file.close()
except Exception, e:
traceback.print_exc(file=sys.stdout)
result.append('')
album_file = open("C:\Python26\!album.txt", "w")
album_file.write(album)
album_file.close()
text_file = open("C:\Python26\!tag3.txt", "w")
text_file.write('')
text_file.close()
continue
return result
if __name__ == "__main__":
LyricProviderInstance = Discogs_GetGenre()
The output to the tag will be "%genre%; //; %style%". I don't know how to get rid of the semicolons just yet, but you can clean those up as you split the tag into genre and style tags.
And yes, it's written quick and dirty. I haven't yet beautified it and the script probably won't look the same tomorrow.
edit :
I've tested it on some 5000 files and it works perfectly