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

⌈⌋ branch:  streamtuner2


Diff

Differences From Artifact [fa727fbb20]:

To Artifact [08769a579d]:


20
21
22
23
24
25
26

27
28
29
30
31
32
33
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34







+






# tab.


import copy
from config import conf, json, log
from uikit import *
import action
import compat2and3


# Welcome to my new blog.
#
# Now it's perhaps not even Gtks fault, but all the gory implementation
# details of XDND are pretty gory. Neither match up to reality anymore.
#
233
234
235
236
237
238
239
240

241
242
243
244


245
246

247

248

249
250
251
252

253
254
255
256




257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

287
288
234
235
236
237
238
239
240

241
242
243


244
245
246

247
248
249

250




251




252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273












274








-
+


-
-
+
+

-
+

+
-
+
-
-
-
-
+
-
-
-
-
+
+
+
+


















-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
        print info
                
        # Direct/internal row import
        if data and info >= 51:
            log.DND("Received row, append, reload")
            rows += [ json.loads(data) ]

        # Convertible formats
        # Convertible formats as direct payload
        elif data and info >= 5:
            cnv = action.extract_playlist(data)
            urls = cnv.format(self.cnv_types[info] if info>=20 else "raw")
            rows += [ self.imported_row(urls[0], cnv.title()) ]
            add = cnv.rows(self.cnv_types[info] if info>=20 else cnv.probe_fmt() or "raw")
            rows += [ cnv.mkrow(row) for row in add ]

        # Extract from playlist files, either passed as text/uri-list or FILE_NAME
        # Extract from playlist files, either passed as text/uri-list or single FILE_NAME
        elif urls:
            for fn in urls or [data]:
            for fn in [re.sub("^\w+://[^/]*", "", fn) for fn in urls or [data] if re.match("^(scp|file)://(localhost)?/|/", fn)]:
                if not re.match("^(scp|file)://(localhost)?/|/", fn):
                ext = action.probe_playlist_fn_ext(fn)
                if ext:  # don't import mp3s into stream lists directly
                    cnt = open(fn, "rt").read()
                    probe = action.probe_playlist_content(cnt)
                    continue
                    if ext == probe:
                        cnv = action.extract_playlist(cnt)
                        urls = cnv.format(probe)
                        rows += [ self.imported_row(urls[0], cnv.title() or os.path.basename(fn)) ]
                fn = compat2and3.urldecode(re.sub("^\w+://[^/]*", "", fn))
                cnv = action.extract_playlist(fn=fn)
                if cnv.src:
                    rows += [ cnv.mkrow(row) for row in cnv.rows() ]
        
        # Insert and update view
        if rows:
            # Inserting at correct row requires deducing index from dnd `y` position
            streams = cn.streams[cn.current]
            i_pos = (cn.gtk_list.get_path_at_pos(10, y) or [[len(streams) + 1]])[0][0]
            for row in rows:
                streams.insert(i_pos - 1, row)
                i_pos = i_pos + 1
            # Now appending to the liststore directly would be even nicer
            uikit.do(lambda *x: cn.load(cn.current))#, cn.gtk_list.scroll_to_point(0, y))
            if cn.module == "bookmarks":
                cn.save()
            #self.parent.streamedit()
        else:
            self.parent.status("Unsupported station format. Not imported.")


    # Stub row for dragged entries.
    # Which is a workaround for the missing full playlist conversion and literal URL input
    def imported_row(self, url, title=None):
        return {
            "title": title or "",
            "url": url,
            "homepage": "",
            "playling": "",
            "listformat": action.probe_playlist_fn_ext(url) or "href",
            "format": ",".join(re.findall("ogg|mpeg|mp\d+", url)),
            "genre": "copy",
        }