mirror of
https://github.com/LaQuay/TDTChannels.git
synced 2025-03-26 11:22:26 +01:00
Update to add EPG info in script
This commit is contained in:
parent
14cb3e74a2
commit
2f7dd65d9e
3 changed files with 47 additions and 14 deletions
|
@ -23,7 +23,7 @@ class Ambito:
|
|||
for channel in self.channels:
|
||||
for option in channel.get_options():
|
||||
if option.is_m3u8_valid():
|
||||
channels_list += "#EXTINF:-1, " + channel.get_name() + "\n" + option.get_url() + "\n"
|
||||
channels_list += channel.to_m3u8(option)
|
||||
return channels_list
|
||||
|
||||
def to_m3u8(self):
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
class Channel:
|
||||
name = None
|
||||
web = None
|
||||
resolution = None
|
||||
logo = None
|
||||
epg_id = None
|
||||
options = []
|
||||
|
||||
def __init__(self, name):
|
||||
def __init__(self, name, web, resolution, logo, epg_id):
|
||||
self.name = name
|
||||
self.web = web
|
||||
self.resolution = resolution
|
||||
self.logo = logo
|
||||
self.epg_id = epg_id
|
||||
self.options = []
|
||||
|
||||
def add_option(self, format, url):
|
||||
|
@ -12,6 +20,15 @@
|
|||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
def get_resolution(self):
|
||||
return self.get_resolution
|
||||
|
||||
def get_logo(self):
|
||||
return self.logo
|
||||
|
||||
def get_epg(self):
|
||||
return self.epg_id
|
||||
|
||||
def get_options(self):
|
||||
return self.options
|
||||
|
||||
|
@ -19,7 +36,7 @@
|
|||
options_string = ""
|
||||
for option in self.options:
|
||||
options_string += "[Format: " + option.get_format() + ", URL: " + option.get_url() + "]"
|
||||
return (self.name + " " + options_string)
|
||||
return self.name + " " + options_string
|
||||
|
||||
def __options_to_json__(self):
|
||||
options_list = []
|
||||
|
@ -30,9 +47,16 @@
|
|||
def to_json(self):
|
||||
return {
|
||||
"name": self.name,
|
||||
"resolution": self.resolution,
|
||||
"logo": self.logo,
|
||||
"epg_id": self.epg_id,
|
||||
"options": self.__options_to_json__()
|
||||
}
|
||||
|
||||
def to_m3u8(self, option):
|
||||
return ('#EXTINF:-1 tvg-id="' + self.epg_id + '" tvg-logo="' + self.logo + '", ' + self.name + "\n" +
|
||||
option.get_url() + "\n")
|
||||
|
||||
class Web:
|
||||
format = None
|
||||
url = None
|
||||
|
@ -51,7 +75,7 @@
|
|||
return self.url
|
||||
|
||||
def __str__(self):
|
||||
return (self.format + ", " + self.url)
|
||||
return self.format + ", " + self.url
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
|
|
|
@ -20,17 +20,26 @@ def stringbetween(text, start, end):
|
|||
|
||||
|
||||
def get_channels_from_part(text):
|
||||
line_where_first_channel_starts = 15
|
||||
attributes_per_item = 6
|
||||
channel_list = []
|
||||
list_to_iterate = text.split("| ")[4:]
|
||||
for i in range(0, len(list_to_iterate), 2):
|
||||
item_name = list_to_iterate[i]
|
||||
item_options = list_to_iterate[i + 1]
|
||||
list_to_iterate = text.split("|")[line_where_first_channel_starts:]
|
||||
while "\n" in list_to_iterate:
|
||||
list_to_iterate.remove("\n")
|
||||
while "\n\n" in list_to_iterate:
|
||||
list_to_iterate.remove("\n\n")
|
||||
for i in range(0, len(list_to_iterate), attributes_per_item):
|
||||
item_name = list_to_iterate[i].strip()
|
||||
item_options = list_to_iterate[i + 1].strip()
|
||||
item_web = list_to_iterate[i + 2].strip()
|
||||
item_resolution = list_to_iterate[i + 3].strip()
|
||||
item_logo = list_to_iterate[i + 4].strip()
|
||||
item_epg = list_to_iterate[i + 5].strip()
|
||||
|
||||
item_name = item_name.replace("|", "").replace("\n", "").strip()
|
||||
item_options = (item_options.replace("|", "").replace("\n", "")).split(" - ")
|
||||
item_options = item_options.split(" - ")
|
||||
|
||||
channel = Channel(item_name)
|
||||
if len(item_options) > 0 and item_options[0] != "":
|
||||
channel = Channel(item_name, item_web, item_resolution, item_logo, item_epg)
|
||||
if len(item_options) > 0 and item_options[0] != "-":
|
||||
for option in item_options:
|
||||
format = (option[1:5]).replace("]", "")
|
||||
url = stringbetween(option, "(", ")")
|
||||
|
@ -118,13 +127,13 @@ canales_autonomicos_valencia = stringbetween(content, "#### Valencia", "## Inter
|
|||
spain.add_ambit(Ambito("Valencia", get_channels_from_part(canales_autonomicos_valencia)))
|
||||
|
||||
# Save data to JSON file
|
||||
json_file = open('code/output/channels.json', "w+")
|
||||
json_file = open('./output/channels.json', "w+")
|
||||
# TODO Anadir copyright
|
||||
json_file.write(json.dumps(spain.to_json()))
|
||||
json_file.close()
|
||||
|
||||
# Save data to M3U8 file
|
||||
text_file = open('code/output/channels.m3u8', "w+")
|
||||
text_file = open('./output/channels.m3u8', "w+")
|
||||
text_file.write("#EXTM3U" + "\n")
|
||||
text_file.write("# @LaQuay https://github.com/LaQuay/TDTChannels" + "\n")
|
||||
text_file.write(spain.to_m3u8())
|
||||
|
|
Loading…
Add table
Reference in a new issue