write channels(lamedb) impl

This commit is contained in:
Dmitriy Yefremov
2017-10-26 16:23:05 +03:00
parent 9168adfb63
commit 512cb8b05f
6 changed files with 128 additions and 42 deletions

View File

@@ -22,6 +22,6 @@ SYSTEM = {"0": "DVB-S", "1": "DVB-S2"}
MODULATION = {"0": "Auto", "1": "QPSK", "2": "8PSK", "3": "16APSK", "5": "32APSK"}
SERVICE_TYPE = {-2: "Unknown", 1: "TV", 2: "Radio", 3: "Data",
10: "Radio", 12: "Data", 22: "TV", 25: "TV (HD)",
136: "Data", 139: "Data"}
SERVICE_TYPE = {"-2": "Unknown", "1": "TV", "2": "Radio", "3": "Data",
"10": "Radio", "12": "Data", "22": "TV", "25": "TV (HD)",
"136": "Data", "139": "Data"}

View File

@@ -1,4 +1,4 @@
from .lamedb import get_channels, write_channels
from .lamedb import get_channels, write_channels, Channel
from .bouquets import get_bouquets, write_bouquets, Bouquet, Bouquets
from .satxml import get_satellites, write_satellites, Satellite, Transponder

View File

@@ -11,9 +11,9 @@ _HEADER = "eDVB services /4/"
_FILE_PATH = "../data/lamedb"
_SEP = ":" # separator
Channel = namedtuple("Channel", ["service", "package", "service_type",
Channel = namedtuple("Channel", ["flags_cas", "transponder_type", "service", "package", "service_type",
"ssid", "freq", "rate", "pol", "fec",
"system", "pos", "data_id", "fav_id"])
"system", "pos", "data_id", "fav_id", "transponder"])
def get_channels(path):
@@ -21,7 +21,29 @@ def get_channels(path):
def write_channels(path, channels):
print(channels)
lines = [_HEADER, "\ntransponders\n"]
tr_lines = []
services_lines = ["end\nservices\n"]
tr_set = set()
for ch in channels:
data_id = str(ch.data_id).split(_SEP)
tr_id = "{}:{}:{}".format(data_id[1], data_id[2], data_id[3])
if tr_id not in tr_set:
transponder = "{}\n\t{}\n/\n".format(tr_id, ch.transponder)
tr_lines.append(transponder)
tr_set.add(tr_id)
# Services
flags = "," + ch.flags_cas if ch.flags_cas else ""
services_lines.append("{}\n{}\np:{}{}".format(ch.data_id, ch.service, ch.package, flags))
tr_lines.sort()
lines.extend(tr_lines)
lines.extend(services_lines)
lines.append("\nend\nFile was created in DemonEditor.\n....Enjoy watching!....\n")
with open(path + "lamedb", "w") as file:
file.writelines(lines)
def parse(path):
@@ -61,14 +83,32 @@ def parse_channels(*args):
# For comparison in bouquets. Needed in upper case!!!
fav_id = "{}:{}:{}:{}".format(str(data[0]).lstrip(sp), str(data[2]).lstrip(sp),
str(data[3]).lstrip(sp), str(data[1]).lstrip(sp))
pack = str(ch[2])
transponder = transponders.get(str(data[1] + _SEP + data[2] + _SEP + data[3]), None)
package, sp, cas = str(ch[2]).partition(",")
_, sp, package = package.partition(_SEP)
transponder_id = "{}:{}:{}".format(data[1], data[2], data[3])
transponder = transponders.get(transponder_id, None)
if transponder is not None:
tr = str(transponder)[2:].split(_SEP) # Removing type of DVB transponders (s , t, c) and split
pack = pack[2:] if pack.find(",") < 0 else pack[2:pack.find(",")]
channels.append(Channel(ch[1], pack, SERVICE_TYPE.get(int(data[4]), SERVICE_TYPE[-2]), data[0], tr[0],
tr[1], POLARIZATION[tr[2]], FEC[tr[3]], SYSTEM[tr[6]],
"{}{}.{}".format(*list(tr[4])), ch[0], fav_id.upper()))
tr_type, sp, tr = str(transponder).partition(" ")
tr = tr.split(_SEP)
service_type = SERVICE_TYPE.get(data[4], SERVICE_TYPE["-2"])
channels.append(Channel(flags_cas=cas,
transponder_type=tr_type,
service=ch[1],
package=package,
service_type=service_type,
ssid=data[0],
freq=tr[0],
rate=tr[1],
pol=POLARIZATION[tr[2]],
fec=FEC[tr[3]],
system=SYSTEM[tr[6]],
pos="{}{}.{}".format(*list(tr[4])),
data_id=ch[0],
fav_id=fav_id.upper(),
transponder=transponder))
return channels

View File

@@ -14,6 +14,7 @@ pls_code: 0 - 262142
"""
from collections import namedtuple
from xml.dom.minidom import parse, Document
from main.eparser.__constants import POLARIZATION, FEC, SYSTEM, MODULATION, PLS_MODE
__FILE_NAME = "satellites.xml"

View File

@@ -1,7 +1,7 @@
from contextlib import suppress
from main.commons import run_task
from main.eparser import get_channels, get_bouquets, write_bouquets, write_channels, Bouquets, Bouquet
from main.eparser import get_channels, get_bouquets, write_bouquets, write_channels, Bouquets, Bouquet, Channel
from main.ftp import download_data, upload_data
from main.properties import get_config, write_config
from . import Gtk, Gdk
@@ -320,7 +320,7 @@ def on_data_save(*args):
write_bouquets(path + "tmp/", bouquets, __bouquets)
# Getting services
services_model.foreach(lambda model, s_path, itr:
services.append(model.get(itr, *[item for item in range(s_n_columns)])))
services.append(Channel(*model.get(itr, *[item for item in range(s_n_columns)]))))
write_channels(path + "tmp/", services)

View File

@@ -114,6 +114,10 @@
</object>
<object class="GtkListStore" id="services_list_store">
<columns>
<!-- column-name cas -->
<column type="gchararray"/>
<!-- column-name type -->
<column type="gchararray"/>
<!-- column-name service -->
<column type="gchararray"/>
<!-- column-name package -->
@@ -138,6 +142,8 @@
<column type="gchararray"/>
<!-- column-name fav_id -->
<column type="gchararray"/>
<!-- column-name transponder -->
<column type="gchararray"/>
</columns>
</object>
<object class="GtkApplicationWindow" id="main_window">
@@ -646,7 +652,7 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">services_list_store</property>
<property name="search_column">0</property>
<property name="search_column">2</property>
<property name="hover_selection">True</property>
<property name="enable_grid_lines">both</property>
<property name="activate_on_single_click">True</property>
@@ -659,6 +665,32 @@
<property name="mode">multiple</property>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="cas_column">
<property name="visible">False</property>
<property name="sizing">autosize</property>
<property name="title" translatable="yes">CAS</property>
<child>
<object class="GtkCellRendererText" id="cas_cellrenderertext1"/>
<attributes>
<attribute name="text">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="type_column">
<property name="visible">False</property>
<property name="sizing">autosize</property>
<property name="title" translatable="yes">Type</property>
<child>
<object class="GtkCellRendererText" id="type_cellrenderertext2"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="service_column2">
<property name="resizable">True</property>
@@ -666,11 +698,11 @@
<property name="title" translatable="yes">Service</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">0</property>
<property name="sort_column_id">2</property>
<child>
<object class="GtkCellRendererText" id="service_cellrenderertext"/>
<attributes>
<attribute name="text">0</attribute>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
@@ -682,11 +714,11 @@
<property name="title" translatable="yes">Package</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">1</property>
<property name="sort_column_id">3</property>
<child>
<object class="GtkCellRendererText" id="package_cellrenderertext"/>
<attributes>
<attribute name="text">1</attribute>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
@@ -697,13 +729,13 @@
<property name="title" translatable="yes">Type</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">2</property>
<property name="sort_column_id">4</property>
<child>
<object class="GtkCellRendererText" id="type_cellrenderertex">
<object class="GtkCellRendererText" id="service_type_cellrenderertex">
<property name="xalign">0.51999998092651367</property>
</object>
<attributes>
<attribute name="text">2</attribute>
<attribute name="text">4</attribute>
</attributes>
</child>
</object>
@@ -715,13 +747,13 @@
<property name="title" translatable="yes">Ssid</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">3</property>
<property name="sort_column_id">5</property>
<child>
<object class="GtkCellRendererText" id="ssid_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">3</attribute>
<attribute name="text">5</attribute>
</attributes>
</child>
</object>
@@ -733,13 +765,13 @@
<property name="title" translatable="yes">Freq</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">4</property>
<property name="sort_column_id">6</property>
<child>
<object class="GtkCellRendererText" id="freq_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">4</attribute>
<attribute name="text">6</attribute>
</attributes>
</child>
</object>
@@ -751,13 +783,13 @@
<property name="title" translatable="yes">Rate</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">5</property>
<property name="sort_column_id">7</property>
<child>
<object class="GtkCellRendererText" id="rate_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">5</attribute>
<attribute name="text">7</attribute>
</attributes>
</child>
</object>
@@ -769,13 +801,13 @@
<property name="title" translatable="yes">Pol</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">6</property>
<property name="sort_column_id">8</property>
<child>
<object class="GtkCellRendererText" id="pol_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">6</attribute>
<attribute name="text">8</attribute>
</attributes>
</child>
</object>
@@ -787,13 +819,13 @@
<property name="title" translatable="yes">FEC</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">7</property>
<property name="sort_column_id">9</property>
<child>
<object class="GtkCellRendererText" id="fec_cellrenderertext">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">7</attribute>
<attribute name="text">9</attribute>
</attributes>
</child>
</object>
@@ -805,13 +837,13 @@
<property name="title" translatable="yes">System</property>
<property name="expand">True</property>
<property name="reorderable">True</property>
<property name="sort_column_id">8</property>
<property name="sort_column_id">10</property>
<child>
<object class="GtkCellRendererText" id="system_cellrenderertex">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">8</attribute>
<attribute name="text">10</attribute>
</attributes>
</child>
</object>
@@ -821,13 +853,13 @@
<property name="resizable">True</property>
<property name="title" translatable="yes">Pos</property>
<property name="expand">True</property>
<property name="sort_column_id">9</property>
<property name="sort_column_id">11</property>
<child>
<object class="GtkCellRendererText" id="pos_cellrenderertext1">
<property name="xalign">0.50999999046325684</property>
</object>
<attributes>
<attribute name="text">9</attribute>
<attribute name="text">11</attribute>
</attributes>
</child>
</object>
@@ -840,7 +872,7 @@
<child>
<object class="GtkCellRendererText" id="data_id_cellrenderertext"/>
<attributes>
<attribute name="text">10</attribute>
<attribute name="text">12</attribute>
</attributes>
</child>
</object>
@@ -853,7 +885,20 @@
<child>
<object class="GtkCellRendererText" id="fav_id_cellrenderertext"/>
<attributes>
<attribute name="text">11</attribute>
<attribute name="text">13</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="transponder_column">
<property name="visible">False</property>
<property name="sizing">autosize</property>
<property name="title" translatable="yes">transponder</property>
<child>
<object class="GtkCellRendererText" id="transponder_cellrenderertext3"/>
<attributes>
<attribute name="text">14</attribute>
</attributes>
</child>
</object>
@@ -923,7 +968,7 @@
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="type_column">
<object class="GtkTreeViewColumn" id="type_column1">
<property name="title" translatable="yes">Type</property>
<property name="expand">True</property>
<child>
@@ -955,7 +1000,7 @@
<property name="visible">False</property>
<property name="title" translatable="yes">fav_id</property>
<child>
<object class="GtkCellRendererText" id="fav_id_cellrenderertext2"/>
<object class="GtkCellRendererText" id="fav_id_cellrenderertext4"/>
<attributes>
<attribute name="text">4</attribute>
</attributes>