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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [705c7d16c2]

Overview
Comment:Playlist DND import and conversion has been greatly simplified. (To the detriment of the action module now becoming more complex.)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 705c7d16c2be82d3b9165ab585cdc8dae134b14f
User & Date: mario on 2015-04-21 22:05:54
Other Links: manifest | tags
Context
2015-04-21
22:07
Remove old .ico workaround, as PIL2(Pillow) now integrates support. Leave the remaining code in shambles, and with excessive logging. Still needs a huge rewrite to optionalize Google reliance again. (The manual favicon fetching never worked, because the regexp is too crude for most sites; and URL joining is off too.) check-in: 743c60ff80 user: mario tags: trunk
22:05
Playlist DND import and conversion has been greatly simplified. (To the detriment of the action module now becoming more complex.) check-in: 705c7d16c2 user: mario tags: trunk
22:04
Major rewrite of playlist_extract handler. Now retains url and titles for playlist types that contain it. Still provides simpler urls() wrapper for old action.play/convert/interpol usage. Move probe_* functions into playlist_extract class as well. Introduce basic playlist_fmt_prio list for supported formats. (Too many regexps to probe for allowed file extensions, etc.) Add support for .url and .desktop files (import only.) check-in: f18b5c461f user: mario tags: trunk
Changes

Modified channels/dnd.py from [fa727fbb20] to [08769a579d].

20
21
22
23
24
25
26

27
28
29
30
31
32
33
# tab.


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



# 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.
#







>







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

        # Convertible formats
        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()) ]

        # Extract from playlist files, either passed as text/uri-list or FILE_NAME
        elif urls:

            for fn in [re.sub("^\w+://[^/]*", "", fn) for fn in urls or [data] if 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)
                    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)) ]
        
        # 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",
        }

        







|


|
|

|

>
|
<
<
<
|
<
>
|
|
|


















<
<
<
<
<
<
<
<
<
<
<
|
<
<
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 as direct payload
        elif data and info >= 5:
            cnv = action.extract_playlist(data)
            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 single FILE_NAME
        elif urls:
            for fn in urls or [data]:
                if not re.match("^(scp|file)://(localhost)?/|/", fn):



                    continue

                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.")