130
131
132
133
134
135
136
137
138
139
140
141
142
143 | 130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152 |
+
+
+
+
+
+
+
+
+
| self.title = self.meta.get("title", self.module)
# add default options values to config.conf.* dict
conf.add_plugin_defaults(self.meta, self.module)
# Only if streamtuner2 is run in graphical mode
if (parent):
# Update/display stream processors
self.prepare_filters += [
self.prepare_filter_icons,
]
self.postprocess_filters += [
self.postprocess_filter_required_fields,
self.postprocess_filter_homepage,
]
# Load cache, instantiate Gtk widgets
self.cache()
self.gui(parent)
# Stub for ST2 main window / dispatcher
else:
self.parent = stub_parent(None)
|
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176 | 171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 |
-
+
| self.columns([])
# add to main menu
uikit.add_menu([parent.channelmenuitems], self.meta["title"], lambda w: parent.channel_switch_by_name(self.module) or 1)
# Just wraps uikit.columns() to retain liststore, rowmap and pix_entry
def columns(self, entries=None):
self.ls, self.rowmap, self.pix_entry = uikit.columns(self.gtk_list, self.datamap, entries)
self.ls, self.rowmap, self.pix_entry = uikit.columns(self.gtk_list, self.datamap, entries, show_favicons=conf.show_favicons)
# Statusbar stub (defers to parent/main window, if in GUI mode)
def status(self, *args, **kw):
if self.parent: self.parent.status(*args, **kw)
else: log.INFO("status():", *v)
|
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313 | 297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316 |
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
| self.status("Updating streams...")
self.status(-0.1)
if category == "empty":
new_streams = self.empty_stub
else:
new_streams = self.update_streams(category)
# Postprocess new list of streams (e.g. assert existing title and url)
if new_streams:
# check and modify entry;
# assert that title and url are present
modified = []
for row in new_streams:
if len(set(["", None]) & set([row.get("title"), row.get("url")])):
continue
try:
modified.append( self.postprocess(row) )
except Exception as e:
log.DATA(e, "Missing title or url. Postprocessing failed:", row)
try:
new_streams = self.postprocess(new_streams)
except Exception as e:
log.ERR(e, "Updating new streams, postprocessing failed:", row)
new_streams = modified
# don't lose forgotten streams
if conf.retain_deleted:
self.streams[category] = new_streams + self.deleted_streams(new_streams, self.streams.get(category,[]))
else:
self.streams[category] = new_streams
|
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409 | 355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406 |
-
+
-
-
+
-
-
+
-
-
-
+
+
+
+
+
-
-
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
+
| for row in old:
if ("url" in row and (row.get("url") not in new)):
row["deleted"] = 1
diff.append(row)
return diff
# prepare data for display
# Prepare stream list for display
#
# - favourite icon
prepare_filters = []
# - or deleted icon
#
def prepare(self, streams):
for f in self.prepare_filters:
for i,row in enumerate(streams):
# state icon: bookmark star
if (conf.show_bookmarks and "bookmarks" in self.parent.channels and self.parent.bookmarks.is_in(streams[i].get("url", "file:///tmp/none"))):
map(f, streams)
return streams
# state icon: bookmark star, or deleted mark
def prepare_filter_icons(self, row):
if conf.show_bookmarks:# and "bookmarks" in self.parent.channels:
streams[i]["favourite"] = 1
row["favourite"] = self.parent.bookmarks.is_in(row.get("url", "file:///tmp/none"))
# state icon: INFO or DELETE
if (not row.get("state")):
if row.get("favourite"):
streams[i]["state"] = gtk.STOCK_ABOUT
if conf.retain_deleted and row.get("deleted"):
streams[i]["state"] = gtk.STOCK_DELETE
if not row.get("state"):
if row.get("favourite"):
row["state"] = gtk.STOCK_ABOUT
if row.get("deleted"):
row["state"] = gtk.STOCK_DELETE
# Favicons? construct local cache filename, basically reimplements favicon.row_to_fn()
if conf.show_favicons and "favicon" in self.parent.features:
url = row.get("img") or row.get("homepage")
if url:
# Normalize by stripping proto:// and non-alphanumeric chars
url = re.sub("[^\w._-]", "_", re.sub("^\w+://|/$", "", url.lower()))
streams[i]["favicon"] = "{}/icons/{}.png".format(conf.dir, url)
# Stream list prepareations directly after reload,
# can remove entries, or just update fields.
postprocess_filters = []
def postprocess(self, streams):
for f in self.postprocess_filters:
streams = filter(f, streams)
return streams
# Filter entries without title or url
# data preparations directly after reload
#
# - drop shoutcast homepage links
# - or find homepage name in title
#
def postprocess(self, row):
# deduce homepage URLs from title
# by looking for www.xyz.com domain names
def postprocess_filter_required_fields(self, row):
return not len(set(["", None]) & set([row.get("title"), row.get("url")]))
# Deduce homepage URLs from title
# by looking for www.xyz.com domain names
def postprocess_filter_homepage(self, row):
if not row.get("homepage"):
url = self.rx_www_url.search(row.get("title", ""))
if url:
url = url.group(0).lower().replace(" ", "")
url = (url if url.find("www.") == 0 else "www."+url)
row["homepage"] = ahttp.fix_url(url)
print row
return row
return True
# reload current stream from web directory
def reload(self):
self.load(self.current, force=1)
def switch(self): |