Merge pull request #26290 from garbear/peripheral-improvements
[xbmc.git] / addons / metadata.generic.albums / lib / fanarttv.py
blob18efbcde5cdec4cfb47558791fb91af301de1c2a
1 # -*- coding: utf-8 -*-
3 def fanarttv_albumart(data):
4 if 'albums' in data:
5 albumdata = {}
6 thumbs = []
7 extras = []
8 discs = {}
9 for mbid, art in data['albums'].items():
10 if 'albumcover' in art:
11 for thumb in art['albumcover']:
12 thumbdata = {}
13 thumbdata['image'] = thumb['url']
14 thumbdata['preview'] = thumb['url'].replace('/fanart/', '/preview/')
15 thumbdata['aspect'] = 'thumb'
16 thumbs.append(thumbdata)
17 if 'cdart' in art:
18 for cdart in art['cdart']:
19 extradata = {}
20 extradata['image'] = cdart['url']
21 extradata['preview'] = cdart['url'].replace('/fanart/', '/preview/')
22 extradata['aspect'] = 'discart'
23 extras.append(extradata)
24 # support for multi-disc albums
25 multidata = {}
26 num = cdart['disc']
27 multidata['image'] = cdart['url']
28 multidata['preview'] = cdart['url'].replace('/fanart/', '/preview/')
29 multidata['aspect'] = 'discart%s' % num
30 if not num in discs:
31 discs[num] = [multidata]
32 else:
33 discs[num].append(multidata)
34 if thumbs:
35 albumdata['thumb'] = thumbs
36 # only return for multi-discs, not single discs
37 if len(discs) > 1:
38 for k, v in discs.items():
39 for item in v:
40 extras.append(item)
41 if extras:
42 albumdata['extras'] = extras
43 return albumdata