Index: channels/_generic.py ================================================================== --- channels/_generic.py +++ channels/_generic.py @@ -258,11 +258,11 @@ # # - favourite icon # - or deleted icon # def prepare(self, streams): - __print__(dbg.PROC, "prepare", streams) + #__print__(dbg.PROC, "prepare", streams) for i,row in enumerate(streams): # oh my, at least it's working # at start the bookmarks module isn't fully registered at instantiation in parent.channels{} - might want to do that step by step rather # then display() is called too early to take effect - load() & co should actually be postponed to when a notebook tab gets selected first @@ -281,14 +281,22 @@ # guess homepage url #self.postprocess(row) # favicons? if conf.show_favicons: - homepage_url = row.get("homepage") - # check for availability of PNG file, inject local icons/ filename - if homepage_url and favicon.available(homepage_url): - streams[i]["favicon"] = favicon.file(homepage_url) + + # entry provides its own image + if "img" in row: + favicon_url = row["img"] + streams[i]["favicon"] = favicon.localcopy(favicon_url) + + # get actual homepage favicon.png + elif "homepage" in row: + homepage_url = row.get("homepage") + # check for availability of PNG file, inject local icons/ filename + if homepage_url and favicon.available(homepage_url): + streams[i]["favicon"] = favicon.file(homepage_url) return streams # data preparations directly after reload Index: channels/jamendo.py ================================================================== --- channels/jamendo.py +++ channels/jamendo.py @@ -53,17 +53,12 @@ base = "http://www.jamendo.com/en/" listformat = "url/http" api = "http://api.jamendo.com/v3.0/" cid = "49daa4f5" - categories = [ - "radios", - "playlists", - "albums", - "tracks", - ["pop", "rock", "dance", "classical", "jazz", "instrumental"] - ] + categories = ["radios"] + titles = dict( title="Title", playing="Album/Artist/User", bitrate=False, listeners=False ) config = [ {"name":"jamendo_stream_format", "value":"ogg2", "type":"text", "description":"streaming format, 'ogg2' or 'mp31'"} ] @@ -71,12 +66,19 @@ # refresh category list def update_categories(self): - pass - + self.categories = [ + "radios", + "playlists", + "albums", + ["newest"], + "tracks", + ["pop", "rock", "dance", "classical", "jazz", "instrumental"] + ] + return self.categories # retrieve category or search def update_streams(self, cat, search="", force=0): @@ -83,31 +85,29 @@ entries = [] # return a static list for now if cat == "radios": - entries = [ - {"title": "Best Of", "url": "http://streaming.radionomy.com/BestOf", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/bestof30.jpg"}, - {"title": "Pop", "url": "http://streaming.radionomy.com/JamPop", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/pop30.jpg"}, - {"title": "Rock", "url": "http://streaming.radionomy.com/JamRock", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/rock30.jpg"}, - {"title": "Lounge", "url": "http://streaming.radionomy.com/JamLounge", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/lounge30.jpg"}, - {"title": "Electro", "url": "http://streaming.radionomy.com/JamElectro", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/electro30.jpg"}, - {"title": "HipHop", "url": "http://streaming.radionomy.com/JamHipHop", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/hiphop30.jpg"}, - {"title": "World", "url": "http://streaming.radionomy.com/JamWorld", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/world30.jpg"}, - {"title": "Jazz", "url": "http://streaming.radionomy.com/JamJazz", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/jazz30.jpg"}, - {"title": "Metal", "url": "http://streaming.radionomy.com/JamMetal", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/metal30.jpg"}, - {"title": "Soundtrack", "url": "http://streaming.radionomy.com/JamSoundtrack", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/soundtrack30.jpg"}, - {"title": "Relaxation", "url": "http://streaming.radionomy.com/JamRelaxation", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/relaxation30.jpg"}, - {"title": "Classical", "url": "http://streaming.radionomy.com/JamClassical", "playing": "", "format": "audio/mpeg", "homepage": "http://www.jamendo.com/en/radios", "favicon": "http://imgjam1.jamendo.com/new_jamendo_radios/classical30.jpg"}, - ] + entries = [] + for radio in ["BestOf", "Pop", "Rock", "Lounge", "Electro", "HipHop", "World", "Jazz", "Metal", "Soundtrack", "Relaxation", "Classical"]: + entries.append({ + "genre": radio, + "title": radio, + "url": "http://streaming.radionomy.com/Jam" + radio, + "playing": "various artists", + "format": "audio/mpeg", + "homepage": "http://www.jamendo.com/en/radios", + "img": "http://imgjam1.jamendo.com/new_jamendo_radios/%s30.jpg" % radio.lower(), + }) # playlist if cat == "playlists": data = http.get(self.api + cat, params = { "client_id": self.cid, "format": "json", - "limit": "200" + "limit": "200", + "order": "creationdate_desc", }) for e in json.loads(data)["results"]: entries.append({ "title": e["name"], "playing": e["user_name"], @@ -116,22 +116,24 @@ "url": "http://api.jamendo.com/get2/stream/track/xspf/?playlist_id=%s&n=all&order=random&from=app-%s" % (e["id"], self.cid), "format": "application/xspf+xml", }) # albums - if cat == "albums": - data = http.get(self.api + cat, params = { + if cat in ["albums", "newest"]: + data = http.get(self.api + "albums/musicinfo", params = { "client_id": self.cid, "format": "json", "limit": "200", - "imagesize": "50" + "imagesize": "50", + "order": ("popularity_week" if cat == "albums" else "releasedate_desc"), }) for e in json.loads(data)["results"]: entries.append({ + "genre": " ".join(e["musicinfo"]["tags"]), "title": e["name"], "playing": e["artist_name"], - "favicon": e["image"], + "img": e["image"], "homepage": e["shareurl"], #"url": "http://api.jamendo.com/v3.0/playlists/file?client_id=%s&id=%s" % (self.cid, e["id"]), "url": "http://api.jamendo.com/get2/stream/track/xspf/?album_id=%s&streamencoding=ogg2&n=all&from=app-%s" % (e["id"], self.cid), "format": "application/xspf+xml", }) @@ -151,14 +153,14 @@ }) for e in json.loads(data)["results"]: entries.append({ "lang": e["musicinfo"]["lang"], "genre": " ".join(e["musicinfo"]["tags"]["genres"]), - "description": ", ".join(e["musicinfo"]["tags"]["vartags"]), + "extra": ", ".join(e["musicinfo"]["tags"]["vartags"]), "title": e["name"], "playing": e["album_name"] + " / " + e["artist_name"], - "favicon": e["album_image"], + "img": e["album_image"], "homepage": e["shareurl"], #"url": e["audio"], "url": "http://storage-new.newjamendo.com/?trackid=%s&format=ogg2&u=0&from=app-%s" % (e["id"], self.cid), "format": "audio/ogg", }) Index: favicon.py ================================================================== --- favicon.py +++ favicon.py @@ -50,14 +50,15 @@ t.start() def download_thread(entries): for e in entries: # try just once if e.get("homepage") in tried_urls: - pass + continue # retrieve specific img url as favicon elif e.get("img"): - pass + localcopy(e["img"], True) + continue # favicon from homepage URL elif e.get("homepage"): download(e["homepage"]) # remember tried_urls.append(e.get("homepage")) @@ -119,10 +120,28 @@ return icon_dir + "/" + name(url) # does the favicon exist def available(url): return os.path.exists(file(url)) + + +# copy image from url into icons/ directory +def localcopy(url, download=False): + if url.startswith("http"): + fn = re.sub("[:/]", "_", url) + fn = conf.dir + "/icons/" + fn + if os.path.exists(fn): + return fn + elif download: + imgdata = ahttp.get(url, binary=1) + with open(fn, "wb") as f: + f.write(imgdata) + f.close() + if os.path.exists(fn): + return fn + else: + return url # download favicon for given URL