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

⌈⌋ branch:  streamtuner2


Check-in [27c88c7dcd]

Overview
Comment:action: Allow %url %title placeholders also with $ prefix. Also reuse interpolate() function for specbuttons and without default %pls.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:27c88c7dcdf8c5fd70ecd0ec2c2829769ba96cd1
User & Date: mario on 2016-10-23 16:28:52
Other Links: manifest | tags
Context
2016-10-23
16:29
Cleaner specbuttons plugin, add support for placeholders in button commands. Add documentation and some config ideas. check-in: 824186a7c3 user: mario tags: trunk
16:28
action: Allow %url %title placeholders also with $ prefix. Also reuse interpolate() function for specbuttons and without default %pls. check-in: 27c88c7dcd user: mario tags: trunk
2016-10-22
19:07
new plugin: specbuttons allows to define mini toolbar buttons to control applications (audio settings, mute/volume, start/kill players or other apps). Has been externalized as plugin. The UI features are built into gtk3.xml specbuttons check-in: 43b36ed35b user: mario tags: trunk
Changes

Modified action.py from [96185346f2] to [fa6ea02044].

189
190
191
192
193
194
195
196

197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
...
213
214
215
216
217
218
219



220
221
222
223
224
225
226
227

# Replaces instances of %m3u, %pls, %srv in a command string
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
#  · Also understands short aliases %l, %f, %d.
#  · And can embed %title or %genre placeholders.
#  · Replace .pls URL with local .m3u file depending on map.
#
def interpol(cmd, source="pls", row={}):


    # Inject other meta fields (%title, %genre, %playing, %format, etc.)
    row = copy.copy(row)
    for field in set(re.findall("%(\w+)", cmd)).intersection(row.keys()):
        cmd = cmd.replace("%"+field, "%r" % row.get(field))

    # Add default %pls if cmd has no %url placeholder
    if cmd.find("%") < 0:
        cmd = cmd + " %pls"
        # "pls" as default requires no conversion for most channels, and seems broadly supported by players

    # Playlist type placeholders (%pls, %m3u, %xspf, etc.)
    for dest, rx in placeholder_map.items():
        if re.search(rx, cmd, re.X):
            # no conversion
................................................................................
                url = row["url"]
            # e.g. from .m3u to .pls
            else:
                url = convert_playlist(row["url"], listfmt(source), listfmt(dest), local_file=True, row=row)
            # insert quoted URL/filepath
            return re.sub(rx, quote(url), cmd, 2, re.X)




    return "/bin/false"


# Substitute streaming address with desired playlist format
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Converts input rows/urls, probes for playlist format, fetches them
# and possibly converts remote .pls to local .m3u/.xpsf filename or
# just returns direct "srv" urls.







|
>


<
|
|


|







 







>
>
>
|







189
190
191
192
193
194
195
196
197
198
199

200
201
202
203
204
205
206
207
208
209
210
211
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230

# Replaces instances of %m3u, %pls, %srv in a command string
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
#  · Also understands short aliases %l, %f, %d.
#  · And can embed %title or %genre placeholders.
#  · Replace .pls URL with local .m3u file depending on map.
#
def interpol(cmd, source="pls", row={}, add_default=True):
    row = copy.copy(row)

    # Inject other meta fields (%title, %genre, %playing, %format, etc.)

    rx_keys = "[\$\%](" + "|".join(row.keys()) + ")\\b"
    cmd = re.sub(rx_keys, lambda m: "%r" % str(row.get(m.group(1))), cmd)

    # Add default %pls if cmd has no %url placeholder
    if not add_default and cmd.find("%") < 0:
        cmd = cmd + " %pls"
        # "pls" as default requires no conversion for most channels, and seems broadly supported by players

    # Playlist type placeholders (%pls, %m3u, %xspf, etc.)
    for dest, rx in placeholder_map.items():
        if re.search(rx, cmd, re.X):
            # no conversion
................................................................................
                url = row["url"]
            # e.g. from .m3u to .pls
            else:
                url = convert_playlist(row["url"], listfmt(source), listfmt(dest), local_file=True, row=row)
            # insert quoted URL/filepath
            return re.sub(rx, quote(url), cmd, 2, re.X)

    if not add_default:
        return cmd
    else:
         return "/bin/false"


# Substitute streaming address with desired playlist format
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Converts input rows/urls, probes for playlist format, fetches them
# and possibly converts remote .pls to local .m3u/.xpsf filename or
# just returns direct "srv" urls.