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

⌈⌋ ⎇ branch:  streamtuner2


Check-in [2b300a090d]

Overview
Comment:Make action.cmd() more explicit again. Introduce cmd= override flag for action.run_fmt_url(). So that specbuttons can use it instead of just interpol(). Thus the urn:/mime handlers will engage as well.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2b300a090dc95e45a813474619399c22ba87ba5a
User & Date: mario on 2016-11-06 12:45:15
Other Links: manifest | tags
Context
2016-11-06
14:41
Use subprocess.list2cmdline() for Windows, and pipes.quote() for BSD/Linux command execution. check-in: 5a6185c3aa user: mario tags: trunk
12:45
Make action.cmd() more explicit again. Introduce cmd= override flag for action.run_fmt_url(). So that specbuttons can use it instead of just interpol(). Thus the urn:/mime handlers will engage as well. check-in: 2b300a090d user: mario tags: trunk
12:42
Document row placeholders, such as %title or $playing check-in: 0fb24c100c user: mario tags: trunk
Changes

Modified action.py from [f35a591c53] to [53a5386135].

128
129
130
131
132
133
134





135
136

137
138
139
140
141
142
143
144

145
146
147
148
149


150

151
152
153
154
155
156
157
158
    # "urn:reciva": stream_resolve(),
}



# Exec wrapper
def run(cmd):





    log.EXEC(cmd)
    try:    os.system("start %s" % cmd if conf.windows else cmd + " &")

    except: log.ERR("Command not found:", cmd)

# Open help browser, streamtuner2 pages
def help(*args):
    run("yelp /usr/share/doc/streamtuner2/help/")

# Invokes player/recorder for stream url and format
def run_fmt_url(row={}, audioformat="audio/mpeg", source="pls", assoc={}, append=None):

    if audioformat in handler:
        handler[audioformat](row, audioformat, source, assoc)
    elif row.get("url", "").startswith("urn:"):
        row = resolve_urn(row);
    else:


        cmd = mime_app(audioformat, assoc)

        cmd = interpol(cmd, source, row)
        if append:
            cmd = re.sub('(["\']?\s*)$', " " + append + "\\1", cmd)
        run(cmd)

# Start web browser
def browser(url):
    run_fmt_url({"url": url, "homepage": url}, "url/http", "srv", conf.play)







>
>
>
>
>
|
|
>
|






|
>





>
>
|
>
|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
    # "urn:reciva": stream_resolve(),
}



# Exec wrapper
def run(cmd):
    if conf.windows:
        cmd = "start " + cmd
    else:
        cmd = cmd + " &"
    try:
        log.EXEC(cmd)
        os.system(cmd)
    except:
        log.ERR("Command not found:", cmd)

# Open help browser, streamtuner2 pages
def help(*args):
    run("yelp /usr/share/doc/streamtuner2/help/")

# Invokes player/recorder for stream url and format
def run_fmt_url(row={}, audioformat="audio/mpeg", source="pls", assoc={}, append=None, cmd=None, add_default=True):
    # look for specific "audio/type" or "urn:service:…" resolvers
    if audioformat in handler:
        handler[audioformat](row, audioformat, source, assoc)
    elif row.get("url", "").startswith("urn:"):
        row = resolve_urn(row);
    else:
        # use default handler for mime type
        if not cmd:
            cmd = mime_app(audioformat, assoc)
        # replace %u, %url or $title placeholders
        cmd = interpol(cmd, source, row, add_default=add_default)
        if append:
            cmd = re.sub('(["\']?\s*)$', " " + append + "\\1", cmd)
        run(cmd)

# Start web browser
def browser(url):
    run_fmt_url({"url": url, "homepage": url}, "url/http", "srv", conf.play)
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
            log.WARN("There's currently no action.handler[] for %s:#id streaming addresses (likely disabled channel plugin)." % urn_service)
    return row


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







|







217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
            log.WARN("There's currently no action.handler[] for %s:#id streaming addresses (likely disabled channel plugin)." % urn_service)
    return row


# Replaces instances of %m3u, %pls, %srv in a command string
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
#  · Also understands short aliases %l, %f, %d.
#  · And can embed %title or $genre placeholders (may use either % or $).
#  · 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"

Modified channels/specbuttons.py from [8c611155af] to [686c618002].

116
117
118
119
120
121
122
123
124
125
        conf.specbuttons = r
        self.update_buttons(self.parent)

    # Button callback, allow for %url/%title placeholders
    def action(self, cmd):
        if re.search("[%$]", cmd):
            row = self.parent.channel().row()
            cmd = action.interpol(cmd, row=row, add_default=False)
        action.run(cmd)








|


116
117
118
119
120
121
122
123
124
125
        conf.specbuttons = r
        self.update_buttons(self.parent)

    # Button callback, allow for %url/%title placeholders
    def action(self, cmd):
        if re.search("[%$]", cmd):
            row = self.parent.channel().row()
            cmd = action.run_fmt_url(cmd, row=row, add_default=False, cmd=cmd)
        action.run(cmd)