mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2025-12-22 00:19:40 +01:00
wrap m3u data
This commit is contained in:
@@ -361,8 +361,11 @@ class HttpAPI:
|
|||||||
elif req_type is HttpRequestType.PLAY or req_type is HttpRequestType.PLAYER_REMOVE:
|
elif req_type is HttpRequestType.PLAY or req_type is HttpRequestType.PLAYER_REMOVE:
|
||||||
url += "{}{}".format(ref_prefix, urllib.parse.quote(ref).replace("%3A", "%253A"))
|
url += "{}{}".format(ref_prefix, urllib.parse.quote(ref).replace("%3A", "%253A"))
|
||||||
|
|
||||||
|
def done_callback(f):
|
||||||
|
callback(f.result())
|
||||||
|
|
||||||
future = self._executor.submit(get_response, req_type, url, self._data)
|
future = self._executor.submit(get_response, req_type, url, self._data)
|
||||||
future.add_done_callback(lambda f: callback(f.result()))
|
future.add_done_callback(done_callback)
|
||||||
|
|
||||||
@run_task
|
@run_task
|
||||||
def init(self):
|
def init(self):
|
||||||
@@ -386,7 +389,7 @@ def get_response(req_type, url, data=None):
|
|||||||
try:
|
try:
|
||||||
with urlopen(Request(url, data=data), timeout=10) as f:
|
with urlopen(Request(url, data=data), timeout=10) as f:
|
||||||
if req_type is HttpRequestType.STREAM or req_type is HttpRequestType.STREAM_CURRENT:
|
if req_type is HttpRequestType.STREAM or req_type is HttpRequestType.STREAM_CURRENT:
|
||||||
return f.read().decode("utf-8")
|
return {"m3u": f.read().decode("utf-8")}
|
||||||
elif req_type is HttpRequestType.CURRENT:
|
elif req_type is HttpRequestType.CURRENT:
|
||||||
for el in ETree.fromstring(f.read().decode("utf-8")).iter("e2event"):
|
for el in ETree.fromstring(f.read().decode("utf-8")).iter("e2event"):
|
||||||
return {el.tag: el.text for el in el.iter()} # return first[current] event from the list
|
return {el.tag: el.text for el in el.iter()} # return first[current] event from the list
|
||||||
|
|||||||
@@ -1854,11 +1854,10 @@ class Application(Gtk.Application):
|
|||||||
else:
|
else:
|
||||||
self._http_api.send(HttpRequestType.STREAM_CURRENT, None, self.record)
|
self._http_api.send(HttpRequestType.STREAM_CURRENT, None, self.record)
|
||||||
|
|
||||||
def record(self, m3u):
|
def record(self, data):
|
||||||
if m3u:
|
url = self.get_url_from_m3u(data)
|
||||||
url = [s for s in m3u.split("\n") if not s.startswith("#")]
|
|
||||||
if url:
|
if url:
|
||||||
self._recorder.record(url[0], self._service_name_label.get_text())
|
self._recorder.record(url, self._service_name_label.get_text())
|
||||||
GLib.timeout_add_seconds(1, self.update_record_button, priority=GLib.PRIORITY_LOW)
|
GLib.timeout_add_seconds(1, self.update_record_button, priority=GLib.PRIORITY_LOW)
|
||||||
|
|
||||||
def update_record_button(self):
|
def update_record_button(self):
|
||||||
@@ -1924,11 +1923,20 @@ class Application(Gtk.Application):
|
|||||||
""" Switch to the channel and watch in the player """
|
""" Switch to the channel and watch in the player """
|
||||||
self._http_api.send(HttpRequestType.STREAM_CURRENT, None, self.watch)
|
self._http_api.send(HttpRequestType.STREAM_CURRENT, None, self.watch)
|
||||||
|
|
||||||
def watch(self, m3u):
|
def watch(self, data):
|
||||||
if m3u:
|
url = self.get_url_from_m3u(data)
|
||||||
url = [s for s in m3u.split("\n") if not s.startswith("#")]
|
|
||||||
if url:
|
if url:
|
||||||
GLib.timeout_add_seconds(1, self.play, url[0])
|
GLib.timeout_add_seconds(1, self.play, url)
|
||||||
|
|
||||||
|
def get_url_from_m3u(self, data):
|
||||||
|
error_code = data.get("error_code", 0)
|
||||||
|
if error_code or self._http_status_image.get_visible():
|
||||||
|
self.show_error_dialog("No connection to the receiver!")
|
||||||
|
return
|
||||||
|
|
||||||
|
m3u = data.get("m3u", None)
|
||||||
|
if m3u:
|
||||||
|
return [s for s in m3u.split("\n") if not s.startswith("#")][0]
|
||||||
|
|
||||||
@run_idle
|
@run_idle
|
||||||
def on_zap(self, callback=None):
|
def on_zap(self, callback=None):
|
||||||
|
|||||||
@@ -2900,7 +2900,7 @@ Author: Dmitriy Yefremov
|
|||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="http_status_image">
|
<object class="GtkImage" id="http_status_image">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="tooltip_text" translatable="yes">No connection to the receiver</property>
|
<property name="tooltip_text" translatable="yes">No connection to the receiver!</property>
|
||||||
<property name="margin_left">10</property>
|
<property name="margin_left">10</property>
|
||||||
<property name="margin_right">10</property>
|
<property name="margin_right">10</property>
|
||||||
<property name="icon_name">network-offline</property>
|
<property name="icon_name">network-offline</property>
|
||||||
|
|||||||
Reference in New Issue
Block a user