mirror of
https://github.com/LaQuay/TDTChannels.git
synced 2025-05-11 17:38:51 +02: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 channel in self.channels:
|
||||||
for option in channel.get_options():
|
for option in channel.get_options():
|
||||||
if option.is_m3u8_valid():
|
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
|
return channels_list
|
||||||
|
|
||||||
def to_m3u8(self):
|
def to_m3u8(self):
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
class Channel:
|
class Channel:
|
||||||
name = None
|
name = None
|
||||||
|
web = None
|
||||||
|
resolution = None
|
||||||
|
logo = None
|
||||||
|
epg_id = None
|
||||||
options = []
|
options = []
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name, web, resolution, logo, epg_id):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.web = web
|
||||||
|
self.resolution = resolution
|
||||||
|
self.logo = logo
|
||||||
|
self.epg_id = epg_id
|
||||||
self.options = []
|
self.options = []
|
||||||
|
|
||||||
def add_option(self, format, url):
|
def add_option(self, format, url):
|
||||||
|
@ -12,6 +20,15 @@
|
||||||
def get_name(self):
|
def get_name(self):
|
||||||
return self.name
|
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):
|
def get_options(self):
|
||||||
return self.options
|
return self.options
|
||||||
|
|
||||||
|
@ -19,7 +36,7 @@
|
||||||
options_string = ""
|
options_string = ""
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
options_string += "[Format: " + option.get_format() + ", URL: " + option.get_url() + "]"
|
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):
|
def __options_to_json__(self):
|
||||||
options_list = []
|
options_list = []
|
||||||
|
@ -30,9 +47,16 @@
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return {
|
return {
|
||||||
"name": self.name,
|
"name": self.name,
|
||||||
|
"resolution": self.resolution,
|
||||||
|
"logo": self.logo,
|
||||||
|
"epg_id": self.epg_id,
|
||||||
"options": self.__options_to_json__()
|
"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:
|
class Web:
|
||||||
format = None
|
format = None
|
||||||
url = None
|
url = None
|
||||||
|
@ -51,7 +75,7 @@
|
||||||
return self.url
|
return self.url
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return (self.format + ", " + self.url)
|
return self.format + ", " + self.url
|
||||||
|
|
||||||
def to_json(self):
|
def to_json(self):
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -20,17 +20,26 @@ def stringbetween(text, start, end):
|
||||||
|
|
||||||
|
|
||||||
def get_channels_from_part(text):
|
def get_channels_from_part(text):
|
||||||
|
line_where_first_channel_starts = 15
|
||||||
|
attributes_per_item = 6
|
||||||
channel_list = []
|
channel_list = []
|
||||||
list_to_iterate = text.split("| ")[4:]
|
list_to_iterate = text.split("|")[line_where_first_channel_starts:]
|
||||||
for i in range(0, len(list_to_iterate), 2):
|
while "\n" in list_to_iterate:
|
||||||
item_name = list_to_iterate[i]
|
list_to_iterate.remove("\n")
|
||||||
item_options = list_to_iterate[i + 1]
|
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.split(" - ")
|
||||||
item_options = (item_options.replace("|", "").replace("\n", "")).split(" - ")
|
|
||||||
|
|
||||||
channel = Channel(item_name)
|
channel = Channel(item_name, item_web, item_resolution, item_logo, item_epg)
|
||||||
if len(item_options) > 0 and item_options[0] != "":
|
if len(item_options) > 0 and item_options[0] != "-":
|
||||||
for option in item_options:
|
for option in item_options:
|
||||||
format = (option[1:5]).replace("]", "")
|
format = (option[1:5]).replace("]", "")
|
||||||
url = stringbetween(option, "(", ")")
|
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)))
|
spain.add_ambit(Ambito("Valencia", get_channels_from_part(canales_autonomicos_valencia)))
|
||||||
|
|
||||||
# Save data to JSON file
|
# Save data to JSON file
|
||||||
json_file = open('code/output/channels.json', "w+")
|
json_file = open('./output/channels.json', "w+")
|
||||||
# TODO Anadir copyright
|
# TODO Anadir copyright
|
||||||
json_file.write(json.dumps(spain.to_json()))
|
json_file.write(json.dumps(spain.to_json()))
|
||||||
json_file.close()
|
json_file.close()
|
||||||
|
|
||||||
# Save data to M3U8 file
|
# 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("#EXTM3U" + "\n")
|
||||||
text_file.write("# @LaQuay https://github.com/LaQuay/TDTChannels" + "\n")
|
text_file.write("# @LaQuay https://github.com/LaQuay/TDTChannels" + "\n")
|
||||||
text_file.write(spain.to_m3u8())
|
text_file.write(spain.to_m3u8())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue