mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2025-12-21 16:09:41 +01:00
webtv download/upload
This commit is contained in:
@@ -1,20 +1,29 @@
|
|||||||
|
""" Module for m3u import """
|
||||||
|
from app.properties import Profile
|
||||||
from .ecommons import BqServiceType, Service
|
from .ecommons import BqServiceType, Service
|
||||||
|
|
||||||
|
# url, description, urlkey, account, usrname, psw, s_type, iconsrc, iconsrc_b, group
|
||||||
|
NEUTRINO_FAV_ID_FORMAT = "{}::{}::{}::{}::{}::{}::{}::{}::{}::{}"
|
||||||
|
ENIGMA2_FAV_ID_FORMAT = " 1:0:1:0:0:0:0:0:0:0:{}:{}\n#DESCRIPTION: {}\n"
|
||||||
|
|
||||||
def parse_m3u(path):
|
|
||||||
|
def parse_m3u(path, profile):
|
||||||
with open(path) as file:
|
with open(path) as file:
|
||||||
aggr = [None] * 10
|
aggr = [None] * 10
|
||||||
channels = []
|
channels = []
|
||||||
count = 0
|
count = 0
|
||||||
name = None
|
name = None
|
||||||
|
fav_id = None
|
||||||
for line in file.readlines():
|
for line in file.readlines():
|
||||||
if line.startswith("#EXTINF"):
|
if line.startswith("#EXTINF"):
|
||||||
name = line[1 + line.index(","):].strip()
|
name = line[1 + line.index(","):].strip()
|
||||||
count += 1
|
count += 1
|
||||||
elif count == 1:
|
elif count == 1:
|
||||||
count = 0
|
count = 0
|
||||||
fav_id = " 1:0:1:0:0:0:0:0:0:0:{}:{}\n#DESCRIPTION: {}\n".format(
|
if profile is Profile.ENIGMA_2:
|
||||||
line.strip().replace(":", "%3a"), name, name, None)
|
fav_id = ENIGMA2_FAV_ID_FORMAT.format(line.strip().replace(":", "%3a"), name, name, None)
|
||||||
|
elif profile is Profile.NEUTRINO_MP:
|
||||||
|
fav_id = NEUTRINO_FAV_ID_FORMAT.format(line.strip(), "", 0, None, None, None, None, "", "", 1)
|
||||||
srv = Service(*aggr[0:3], name, *aggr[0:3], BqServiceType.IPTV.name, *aggr, fav_id, None)
|
srv = Service(*aggr[0:3], name, *aggr[0:3], BqServiceType.IPTV.name, *aggr, fav_id, None)
|
||||||
channels.append(srv)
|
channels.append(srv)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import os
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
from xml.dom.minidom import parse, Document
|
from xml.dom.minidom import parse, Document
|
||||||
|
|
||||||
|
from app.eparser.iptv import NEUTRINO_FAV_ID_FORMAT
|
||||||
from app.ui import LOCKED_ICON, HIDE_ICON
|
from app.ui import LOCKED_ICON, HIDE_ICON
|
||||||
from ..ecommons import Bouquets, Bouquet, BouquetService, BqServiceType, PROVIDER
|
from ..ecommons import Bouquets, Bouquet, BouquetService, BqServiceType, PROVIDER
|
||||||
|
|
||||||
@@ -76,7 +77,8 @@ def parse_webtv(path, name, bq_type):
|
|||||||
if elem.hasAttributes():
|
if elem.hasAttributes():
|
||||||
title = elem.attributes["title"].value
|
title = elem.attributes["title"].value
|
||||||
url = elem.attributes["url"].value
|
url = elem.attributes["url"].value
|
||||||
description = elem.attributes["description"].value
|
description = elem.attributes.get("description")
|
||||||
|
description = description.value if description else description
|
||||||
urlkey = elem.attributes.get("urlkey", None)
|
urlkey = elem.attributes.get("urlkey", None)
|
||||||
urlkey = urlkey.value if urlkey else urlkey
|
urlkey = urlkey.value if urlkey else urlkey
|
||||||
account = elem.attributes.get("account", None)
|
account = elem.attributes.get("account", None)
|
||||||
@@ -93,8 +95,8 @@ def parse_webtv(path, name, bq_type):
|
|||||||
iconsrc_b = iconsrc_b.value if iconsrc_b else iconsrc_b
|
iconsrc_b = iconsrc_b.value if iconsrc_b else iconsrc_b
|
||||||
group = elem.attributes.get("group", None)
|
group = elem.attributes.get("group", None)
|
||||||
group = group.value if group else group
|
group = group.value if group else group
|
||||||
fav_id = "{}::{}::{}::{}::{}::{}::{}::{}::{}::{}".format(url, description, urlkey, account, usrname,
|
fav_id = NEUTRINO_FAV_ID_FORMAT.format(url, description, urlkey, account, usrname, psw, s_type, iconsrc,
|
||||||
psw, s_type, iconsrc, iconsrc_b, group)
|
iconsrc_b, group)
|
||||||
srv = BouquetService(name=title,
|
srv = BouquetService(name=title,
|
||||||
type=BqServiceType.IPTV,
|
type=BqServiceType.IPTV,
|
||||||
data=fav_id,
|
data=fav_id,
|
||||||
|
|||||||
45
app/ftp.py
45
app/ftp.py
@@ -11,12 +11,16 @@ from app.properties import Profile
|
|||||||
__DATA_FILES_LIST = ("tv", "radio", "lamedb", "blacklist", "whitelist", # enigma 2
|
__DATA_FILES_LIST = ("tv", "radio", "lamedb", "blacklist", "whitelist", # enigma 2
|
||||||
"services.xml", "myservices.xml", "bouquets.xml", "ubouquets.xml") # neutrino
|
"services.xml", "myservices.xml", "bouquets.xml", "ubouquets.xml") # neutrino
|
||||||
|
|
||||||
|
_SATELLITES_XML_FILE = "satellites.xml"
|
||||||
|
_WEBTV_XML_FILE = "webtv.xml"
|
||||||
|
|
||||||
|
|
||||||
class DownloadDataType(Enum):
|
class DownloadDataType(Enum):
|
||||||
ALL = 0
|
ALL = 0
|
||||||
BOUQUETS = 1
|
BOUQUETS = 1
|
||||||
SATELLITES = 2
|
SATELLITES = 2
|
||||||
PICONS = 3
|
PICONS = 3
|
||||||
|
WEBTV = 4
|
||||||
|
|
||||||
|
|
||||||
def download_data(*, properties, download_type=DownloadDataType.ALL, callback=None):
|
def download_data(*, properties, download_type=DownloadDataType.ALL, callback=None):
|
||||||
@@ -35,20 +39,21 @@ def download_data(*, properties, download_type=DownloadDataType.ALL, callback=No
|
|||||||
name = str(file).strip()
|
name = str(file).strip()
|
||||||
if name.endswith(__DATA_FILES_LIST):
|
if name.endswith(__DATA_FILES_LIST):
|
||||||
name = name.split()[-1]
|
name = name.split()[-1]
|
||||||
with open(save_path + name, "wb") as f:
|
download_file(ftp, name, save_path)
|
||||||
ftp.retrbinary("RETR " + name, f.write)
|
# satellites.xml and webtv section
|
||||||
# satellites.xml section
|
if download_type in (DownloadDataType.ALL, DownloadDataType.SATELLITES, DownloadDataType.WEBTV):
|
||||||
if download_type is DownloadDataType.ALL or download_type is DownloadDataType.SATELLITES:
|
|
||||||
ftp.cwd(properties["satellites_xml_path"])
|
ftp.cwd(properties["satellites_xml_path"])
|
||||||
files.clear()
|
files.clear()
|
||||||
ftp.dir(files.append)
|
ftp.dir(files.append)
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
name = str(file).strip()
|
name = str(file).strip()
|
||||||
xml_file = "satellites.xml"
|
if download_type in (DownloadDataType.ALL, DownloadDataType.SATELLITES):
|
||||||
if name.endswith(xml_file):
|
if name.endswith(_SATELLITES_XML_FILE):
|
||||||
with open(save_path + xml_file, 'wb') as f:
|
download_file(ftp, _SATELLITES_XML_FILE, save_path)
|
||||||
ftp.retrbinary("RETR " + xml_file, f.write)
|
elif download_type in (DownloadDataType.ALL, DownloadDataType.WEBTV):
|
||||||
|
if name.endswith(_WEBTV_XML_FILE):
|
||||||
|
download_file(ftp, _WEBTV_XML_FILE, save_path)
|
||||||
|
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
callback()
|
callback()
|
||||||
@@ -71,9 +76,20 @@ def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused
|
|||||||
|
|
||||||
if download_type is DownloadDataType.ALL or download_type is DownloadDataType.SATELLITES:
|
if download_type is DownloadDataType.ALL or download_type is DownloadDataType.SATELLITES:
|
||||||
ftp.cwd(properties["satellites_xml_path"])
|
ftp.cwd(properties["satellites_xml_path"])
|
||||||
file_name = "satellites.xml"
|
send = send_file(_SATELLITES_XML_FILE, data_path, ftp)
|
||||||
send = send_file(file_name, data_path, ftp)
|
if download_type is DownloadDataType.SATELLITES:
|
||||||
if download_type == DownloadDataType.SATELLITES:
|
tn.send("init 3" if profile is Profile.ENIGMA_2 else "init 6")
|
||||||
|
if callback is not None:
|
||||||
|
callback()
|
||||||
|
return send
|
||||||
|
|
||||||
|
if profile is Profile.NEUTRINO_MP and download_type in (DownloadDataType.ALL, DownloadDataType.WEBTV):
|
||||||
|
ftp.cwd(properties["satellites_xml_path"])
|
||||||
|
send = send_file(_WEBTV_XML_FILE, data_path, ftp)
|
||||||
|
if download_type is DownloadDataType.WEBTV:
|
||||||
|
tn.send("init 6")
|
||||||
|
if callback is not None:
|
||||||
|
callback()
|
||||||
return send
|
return send
|
||||||
|
|
||||||
if download_type is DownloadDataType.ALL or download_type is DownloadDataType.BOUQUETS:
|
if download_type is DownloadDataType.ALL or download_type is DownloadDataType.BOUQUETS:
|
||||||
@@ -88,7 +104,7 @@ def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused
|
|||||||
ftp.delete(name)
|
ftp.delete(name)
|
||||||
|
|
||||||
for file_name in os.listdir(data_path):
|
for file_name in os.listdir(data_path):
|
||||||
if file_name == "satellites.xml":
|
if file_name == _SATELLITES_XML_FILE or file_name == _WEBTV_XML_FILE:
|
||||||
continue
|
continue
|
||||||
if file_name.endswith(__DATA_FILES_LIST):
|
if file_name.endswith(__DATA_FILES_LIST):
|
||||||
send_file(file_name, data_path, ftp)
|
send_file(file_name, data_path, ftp)
|
||||||
@@ -123,6 +139,11 @@ def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused
|
|||||||
callback()
|
callback()
|
||||||
|
|
||||||
|
|
||||||
|
def download_file(ftp, name, save_path):
|
||||||
|
with open(save_path + name, "wb") as f:
|
||||||
|
ftp.retrbinary("RETR " + name, f.write)
|
||||||
|
|
||||||
|
|
||||||
def send_file(file_name, path, ftp):
|
def send_file(file_name, path, ftp):
|
||||||
""" Opens the file in binary mode and transfers into receiver """
|
""" Opens the file in binary mode and transfers into receiver """
|
||||||
with open(path + file_name, "rb") as f:
|
with open(path + file_name, "rb") as f:
|
||||||
|
|||||||
@@ -220,7 +220,21 @@ dmitry.v.yefremov@gmail.com
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<placeholder/>
|
<object class="GtkRadioButton" id="webtv_radio_button">
|
||||||
|
<property name="label" translatable="yes">WebTV</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">False</property>
|
||||||
|
<property name="xalign">0</property>
|
||||||
|
<property name="yalign">0.52999997138977051</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
<property name="draw_indicator">True</property>
|
||||||
|
<property name="group">all_radio_button</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">4</property>
|
||||||
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
|||||||
@@ -35,16 +35,19 @@ class DownloadDialog:
|
|||||||
self._all_radio_button = builder.get_object("all_radio_button")
|
self._all_radio_button = builder.get_object("all_radio_button")
|
||||||
self._bouquets_radio_button = builder.get_object("bouquets_radio_button")
|
self._bouquets_radio_button = builder.get_object("bouquets_radio_button")
|
||||||
self._satellites_radio_button = builder.get_object("satellites_radio_button")
|
self._satellites_radio_button = builder.get_object("satellites_radio_button")
|
||||||
|
self._webtv_radio_button = builder.get_object("webtv_radio_button")
|
||||||
|
if profile is Profile.NEUTRINO_MP:
|
||||||
|
self._webtv_radio_button.set_visible(True)
|
||||||
# self._dialog.get_content_area().set_border_width(0)
|
# self._dialog.get_content_area().set_border_width(0)
|
||||||
|
|
||||||
@run_idle
|
@run_idle
|
||||||
def on_receive(self, item):
|
def on_receive(self, item):
|
||||||
self.download(True, d_type=self.get_download_type())
|
self.download(True, self.get_download_type())
|
||||||
|
|
||||||
@run_idle
|
@run_idle
|
||||||
def on_send(self, item):
|
def on_send(self, item):
|
||||||
if show_dialog(DialogType.QUESTION, self._dialog) != Gtk.ResponseType.CANCEL:
|
if show_dialog(DialogType.QUESTION, self._dialog) != Gtk.ResponseType.CANCEL:
|
||||||
self.download(d_type=self.get_download_type())
|
self.download(False, self.get_download_type())
|
||||||
|
|
||||||
def get_download_type(self):
|
def get_download_type(self):
|
||||||
download_type = DownloadDataType.ALL
|
download_type = DownloadDataType.ALL
|
||||||
@@ -52,6 +55,8 @@ class DownloadDialog:
|
|||||||
download_type = DownloadDataType.BOUQUETS
|
download_type = DownloadDataType.BOUQUETS
|
||||||
elif self._satellites_radio_button.get_active():
|
elif self._satellites_radio_button.get_active():
|
||||||
download_type = DownloadDataType.SATELLITES
|
download_type = DownloadDataType.SATELLITES
|
||||||
|
elif self._webtv_radio_button.get_active():
|
||||||
|
download_type = DownloadDataType.WEBTV
|
||||||
return download_type
|
return download_type
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
@@ -65,7 +70,7 @@ class DownloadDialog:
|
|||||||
|
|
||||||
@run_idle
|
@run_idle
|
||||||
@run_task
|
@run_task
|
||||||
def download(self, download=False, d_type=DownloadDataType.ALL):
|
def download(self, download, d_type):
|
||||||
""" Download/upload data from/to receiver """
|
""" Download/upload data from/to receiver """
|
||||||
try:
|
try:
|
||||||
if download:
|
if download:
|
||||||
|
|||||||
@@ -821,7 +821,7 @@ class MainAppWindow:
|
|||||||
show_dialog(DialogType.ERROR, self.__main_window, text="No m3u file is selected!")
|
show_dialog(DialogType.ERROR, self.__main_window, text="No m3u file is selected!")
|
||||||
return
|
return
|
||||||
|
|
||||||
channels = parse_m3u(response)
|
channels = parse_m3u(response, Profile(self.__profile))
|
||||||
bq_selected = self.is_bouquet_selected()
|
bq_selected = self.is_bouquet_selected()
|
||||||
if channels and bq_selected:
|
if channels and bq_selected:
|
||||||
bq_services = self.__bouquets.get(bq_selected)
|
bq_services = self.__bouquets.get(bq_selected)
|
||||||
|
|||||||
Reference in New Issue
Block a user