Index: favicon.py ================================================================== --- favicon.py +++ favicon.py @@ -32,10 +32,11 @@ from config import * from threading import Thread import ahttp import compat2and3 from PIL import Image +from uikit import gtk # ensure that we don't try to download a single favicon twice per session, # if it's not available the first time, we won't get it after switching stations back and forth @@ -43,37 +44,58 @@ # walk through entries -def download_all(entries, treestore=None, pix_i=None): - t = Thread(target= download_thread, args= ([entries])) +def download_all(*args, **kwargs): + t = Thread(target=download_thread, args=args, kwargs=kwargs) t.start() -def download_thread(entries): - for e in entries: +def download_thread(entries, pixstore=None): + for i,e in enumerate(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 + tried_urls.append(e.get("img")) # favicon from homepage URL elif e.get("homepage"): download(e["homepage"]) - # remember - tried_urls.append(e.get("homepage")) + tried_urls.append(e.get("homepage")) + + # Update TreeView + update_pixstore(e, pixstore, i) pass # download a single favicon for currently playing station -def download_playing(row, treestore_pix=None): +def download_playing(row, pixstore=None): if conf.google_homepage and not row.get("homepage"): google_find_homepage(row) if conf.load_favicon and row.get("homepage"): - download_all([row]) + download_all([row], pixstore=pixstore) pass + +# Update favicon in treeview/liststore +def update_pixstore(row, pixstore=None, row_i=None): + log.PIXSTORE(pixstore, row_i) + if pixstore: + ls, pix_entry, i = pixstore + if i is None: + i = row_i + fn = None + if row.get("favicon"): + fn = row["favicon"] + elif row.get("img"): + fn = localcopy(row["img"], False) + elif row.get("homepage"): + fn = file(row["homepage"]) + if fn and os.path.exists(fn): + p = gtk.gdk.pixbuf_new_from_file(fn) + ls[i][pix_entry] = p #--- unrelated --- def google_find_homepage(row): """ Searches for missing homepage URL via Google. """ Index: st2.py ================================================================== --- st2.py +++ st2.py @@ -260,13 +260,15 @@ # Play button def on_play_clicked(self, widget, event=None, *args): self.status("Starting player...") - row = self.channel().play() + channel = self.channel() + pixstore = [channel._ls, channel._pix_entry, channel.rowno()] + row = channel.play() self.status("") - [callback(row) for callback in self.hooks["play"]] + [callback(row, pixstore=pixstore) for callback in self.hooks["play"]] # Recording: invoke streamripper for current stream URL def on_record_clicked(self, widget): self.status("Recording station...") row = self.channel().record() @@ -321,12 +323,12 @@ def update_categories(self, widget): Thread(target=self.channel().reload_categories).start() # Menu invocation: refresh favicons for all stations in current streams category def update_favicons(self, widget): - entries = self.channel().stations() - favicon.download_all(entries) + ch = self.channel() + favicon.download_all(entries=ch.stations(), pixstore=[ch._ls, ch._pix_entry, None]) # Save stream to file (.m3u) def save_as(self, widget): row = self.row() default_fn = row["title"] + ".m3u"