Attempt to get tracker icon from html source

Use blank icon for trackers that do not have a favicon available (to 
make things aligned)
Force 16x16 for tracker icons
This commit is contained in:
Andrew Resch 2008-10-27 04:49:06 +00:00
parent ac9959a92b
commit eb9578c41d
2 changed files with 32 additions and 9 deletions

View File

@ -237,12 +237,17 @@ class FilterTreeView(component.Component):
return None return None
def set_row_image(self, cat, value, filename): def set_row_image(self, cat, value, filename):
pix = None
try: #assume we could get trashed images here.. try: #assume we could get trashed images here..
pix = gtk.gdk.pixbuf_new_from_file(filename) pix = gtk.gdk.pixbuf_new_from_file_at_size(filename, 16, 16)
row = self.filters[(cat, value)]
self.treestore.set_value(row, 4, pix)
except Exception, e: except Exception, e:
log.debug(e.message) log.debug(e.message)
if not pix:
pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16)
pix.fill(0x00000000)
row = self.filters[(cat, value)]
self.treestore.set_value(row, 4, pix)
return False return False

View File

@ -45,7 +45,7 @@ RENAMES = {
"aelitis.com":"www.vuze.com" "aelitis.com":"www.vuze.com"
} }
VALID_ICO_TYPES = ["octet-stream","x-icon"] VALID_ICO_TYPES = ["octet-stream", "x-icon", "image/vnd.microsoft.icon"]
VALID_PNG_TYPES = ["octet-stream", "png"] VALID_PNG_TYPES = ["octet-stream", "png"]
def fetch_url(url, valid_subtypes=None): def fetch_url(url, valid_subtypes=None):
@ -98,6 +98,25 @@ class TrackerIcons(object):
if png: if png:
return ("png", png) return ("png", png)
# FIXME: This should be cleaned up and not copy the top code
html = urlopen("http://%s/" % (host_name,))
if html:
icon_path = ""
line = html.readline()
while line:
if '<link rel="icon"' in line or '<link rel="shortcut icon"' in line:
log.debug("line: %s", line)
icon_path = line[line.find("href"):].split("\"")[1]
break
line = html.readline()
if icon_path:
ico = fetch_url(("http://%s/" + icon_path) % host_name, VALID_ICO_TYPES)
if ico:
return ("ico", ico)
png = fetch_url(("http://%s/" + icon_path) % host_name, VALID_PNG_TYPES)
if png:
return ("png", png)
""" """
TODO: need a test-site first... TODO: need a test-site first...
html = fetch_url("http://%s/" % (host_name,)) html = fetch_url("http://%s/" % (host_name,))
@ -166,4 +185,3 @@ if __name__ == "__main__":
test_get() test_get()
#test_async() #test_async()