Check-in [6d065627b5]
Overview
Comment: | load Jamendo images in favour of favicons |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
6d065627b5a103fe153c5b2c5b801a4a |
User & Date: | mario on 2014-05-11 01:21:24 |
Other Links: | manifest | tags |
Context
2014-05-12
| ||
20:10 | Enable empty entries=[] display in mygtk.columns (empty channels/categories/bookmarks) check-in: fa410c856a user: mario tags: trunk | |
2014-05-11
| ||
01:21 | load Jamendo images in favour of favicons check-in: 6d065627b5 user: mario tags: trunk | |
2014-05-10
| ||
21:40 | Skip new_streams with undefined title or url check-in: 3c94abea16 user: mario tags: trunk | |
Changes
Modified channels/_generic.py from [d2e1c8074b] to [cfe3bb4bc7].
︙ | ︙ | |||
256 257 258 259 260 261 262 | # prepare data for display # # - favourite icon # - or deleted icon # def prepare(self, streams): | | | 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | # prepare data for display # # - favourite icon # - or deleted icon # def prepare(self, 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 # => might be fixed now, 1.9.8 # state icon: bookmark star |
︙ | ︙ | |||
279 280 281 282 283 284 285 | streams[i]["state"] = gtk.STOCK_DELETE # guess homepage url #self.postprocess(row) # favicons? if conf.show_favicons: | > > > > > > > > | | | | | 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | streams[i]["state"] = gtk.STOCK_DELETE # guess homepage url #self.postprocess(row) # favicons? if conf.show_favicons: # 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 # # - drop shoutcast homepage links |
︙ | ︙ |
Modified channels/jamendo.py from [4a00f6a5de] to [1623a27596].
︙ | ︙ | |||
51 52 53 54 55 56 57 | has_search = True base = "http://www.jamendo.com/en/" listformat = "url/http" api = "http://api.jamendo.com/v3.0/" cid = "49daa4f5" | | < < < < < | > | > > > > > | > | | | | | | | | | | | < < < | > | | | > > | | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 | has_search = True base = "http://www.jamendo.com/en/" listformat = "url/http" api = "http://api.jamendo.com/v3.0/" cid = "49daa4f5" 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'"} ] # refresh category list def update_categories(self): 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): entries = [] # return a static list for now if cat == "radios": 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", "order": "creationdate_desc", }) for e in json.loads(data)["results"]: entries.append({ "title": e["name"], "playing": e["user_name"], "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/?playlist_id=%s&n=all&order=random&from=app-%s" % (e["id"], self.cid), "format": "application/xspf+xml", }) # albums if cat in ["albums", "newest"]: data = http.get(self.api + "albums/musicinfo", params = { "client_id": self.cid, "format": "json", "limit": "200", "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"], "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", }) # genre list |
︙ | ︙ | |||
149 150 151 152 153 154 155 | "order": "popularity_week", "include": "musicinfo", }) for e in json.loads(data)["results"]: entries.append({ "lang": e["musicinfo"]["lang"], "genre": " ".join(e["musicinfo"]["tags"]["genres"]), | | | | 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | "order": "popularity_week", "include": "musicinfo", }) for e in json.loads(data)["results"]: entries.append({ "lang": e["musicinfo"]["lang"], "genre": " ".join(e["musicinfo"]["tags"]["genres"]), "extra": ", ".join(e["musicinfo"]["tags"]["vartags"]), "title": e["name"], "playing": e["album_name"] + " / " + e["artist_name"], "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", }) # done |
︙ | ︙ |
Modified favicon.py from [b3ed705ebd] to [bf959d4ee7].
︙ | ︙ | |||
48 49 50 51 52 53 54 | def download_all(entries): t = Thread(target= download_thread, args= ([entries])) t.start() def download_thread(entries): for e in entries: # try just once if e.get("homepage") in tried_urls: | < > | > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | def download_all(entries): t = Thread(target= download_thread, args= ([entries])) t.start() def download_thread(entries): for e in entries: # try just once if e.get("homepage") in tried_urls: continue # retrieve specific img url as favicon elif e.get("img"): localcopy(e["img"], True) continue # favicon from homepage URL elif e.get("homepage"): download(e["homepage"]) # remember tried_urls.append(e.get("homepage")) pass |
︙ | ︙ | |||
117 118 119 120 121 122 123 124 125 126 127 128 129 130 | os.mkdir(icon_dir) open(icon_dir+"/.nobackup", "w").close() return icon_dir + "/" + name(url) # does the favicon exist def available(url): return os.path.exists(file(url)) # download favicon for given URL def download(url): | > > > > > > > > > > > > > > > > > > | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | os.mkdir(icon_dir) open(icon_dir+"/.nobackup", "w").close() 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 def download(url): |
︙ | ︙ |