Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ ⎇ branch:  streamtuner2


Diff

Differences From Artifact [684fc768c9]:

To Artifact [9ae90f0624]:

  • File favicon.py — part of check-in [aac4fcacbf] at 2015-05-09 21:40:07 on branch trunk — Implement favicon live updating. Play event and download_all now pass the treestore, with row index, and pix_entry number (column index in liststore). Favicon module checks for downloaded images twice now, and updates PixBuf in ListStore. (Works for both single station view, and download_all.) (user: mario, size: 8280) [annotate] [blame] [check-ins using]

30
31
32
33
34
35
36

37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
from compat2and3 import xrange, urllib
import re
from config import *
from threading import Thread
import ahttp
import compat2and3
from PIL import Image




# 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
tried_urls = []




# walk through entries
def download_all(entries, treestore=None, pix_i=None):
  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

# download a single favicon for currently playing station
def download_playing(row, treestore_pix=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])
    pass





















#--- unrelated ---
def google_find_homepage(row):
    """ Searches for missing homepage URL via Google. """
    if row.get("url") not in tried_urls:
        tried_urls.append(row.get("url"))







>











|
|

|
|



>



|



<
|
>
>
>



|



|


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
from compat2and3 import xrange, urllib
import re
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
tried_urls = []




# walk through entries
def download_all(*args, **kwargs):
  t = Thread(target=download_thread, args=args, kwargs=kwargs)
  t.start()
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)
            tried_urls.append(e.get("img"))
        # favicon from homepage URL
        elif e.get("homepage"):
            download(e["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, 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], 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. """
    if row.get("url") not in tried_urls:
        tried_urls.append(row.get("url"))