[ExecString] combine SplitParameters with identical function of CUtil
[xbmc.git] / addons / metadata.generic.artists / lib / discogs.py
blob42fa1301d256cf5f3f58d285f85c0cc2277c3a04
1 # -*- coding: utf-8 -*-
2 import difflib
4 def discogs_artistfind(data, artist):
5 artists = []
6 for item in data.get('results',[]):
7 artistdata = {}
8 artistdata['artist'] = item['title']
9 # filter inaccurate results
10 match = difflib.SequenceMatcher(None, artist.lower(), item['title'].lower()).ratio()
11 score = round(match, 2)
12 if score > 0.90:
13 artistdata['thumb'] = item['thumb']
14 artistdata['genre'] = ''
15 artistdata['born'] = ''
16 artistdata['dcid'] = item['id']
17 # discogs does not provide relevance, use our own
18 artistdata['relevance'] = str(score)
19 artists.append(artistdata)
20 return artists
22 def discogs_artistdetails(data):
23 artistdata = {}
24 artistdata['artist'] = data['name']
25 artistdata['biography'] = data['profile']
26 if 'images' in data:
27 thumbs = []
28 for item in data['images']:
29 thumbdata = {}
30 thumbdata['image'] = item['uri']
31 thumbdata['preview'] = item['uri150']
32 thumbdata['aspect'] = 'thumb'
33 thumbs.append(thumbdata)
34 artistdata['thumb'] = thumbs
35 return artistdata
37 def discogs_artistalbums(data):
38 albums = []
39 for item in data['releases']:
40 if item['role'] == 'Main':
41 albumdata = {}
42 albumdata['title'] = item['title']
43 albumdata['year'] = str(item.get('year', ''))
44 albums.append(albumdata)
45 return albums