1
0
Fork 0
mirror of https://github.com/LaQuay/TDTChannels.git synced 2024-09-30 09:12:01 +02:00

New propostal for json file

This commit is contained in:
Jacobo Rodriguez 2019-06-13 12:10:42 +02:00
parent 9957babe97
commit ce8cc6562a
4 changed files with 49 additions and 34 deletions

View file

@ -1,6 +1,6 @@
# TODO Create TVChannel and RadioChannel
class Channel:
def __init__(self, name, web, resolution, logo, epg_id, extra_info):
def __init__(self, name, web, resolution, logo, epg_id, extra_info, type):
self.name = name
self.web = web
self.resolution = resolution
@ -8,9 +8,10 @@ class Channel:
self.epg_id = epg_id
self.options = []
self.extra_info = extra_info
self.type = type
def add_option(self, format, url):
self.options.append(self.Web(format, url))
def add_option(self, format, url, info):
self.options.append(self.Web(format, url, info))
def get_name(self):
return self.name
@ -50,7 +51,8 @@ class Channel:
"resolution": self.resolution,
"epg_id": self.epg_id,
"options": self.__options_to_json__(),
"extra_info": self.extra_info
"extra_info": self.extra_info,
"type": self.type
}
def to_m3u8(self, ambit_name, option):
@ -76,9 +78,10 @@ class Channel:
return info
class Web:
def __init__(self, format, url):
def __init__(self, format, url, info):
self.format = format
self.url = url
self.info = info
def is_m3u8_valid(self):
return self.format == "m3u8"
@ -98,5 +101,6 @@ class Channel:
def to_json(self):
return {
"format": self.format,
"url": self.url
"url": self.url,
"extra_info": self.info
}

View file

@ -5,7 +5,7 @@ import requests
from ambit import Ambito
from country import Country
from utils import stringbetween, get_radio_channels_from_part, get_license_info
from utils import stringbetween, get_radio_channels_from_part, get_license_info, get_current_timestamp
page = requests.get('https://raw.githubusercontent.com/LaQuay/TDTChannels/master/RADIO.md',
headers={'Cache-Control': 'no-cache'})
@ -147,16 +147,14 @@ canales_andorra = stringbetween(content, "## Andorra", "")
andorra.add_ambit(Ambito("Andorra", get_radio_channels_from_part(canales_andorra)))
# Save data to JSON file
json_result = {"license": get_license_info(),
"countries": [spain.to_json(),
international.to_json(),
andorra.to_json()],
"updated": get_current_timestamp()
}
json_file = open('./public/output/radio_channels.json', "w+")
json_file.write("[")
json_file.write(json.dumps(get_license_info()))
json_file.write(", ")
json_file.write(json.dumps(spain.to_json()))
json_file.write(", ")
json_file.write(json.dumps(international.to_json()))
json_file.write(", ")
json_file.write(json.dumps(andorra.to_json()))
json_file.write("]")
json_file.write(json.dumps(json_result, indent=4, sort_keys=False))
json_file.close()
print("JSON Updated")

21
script/tv_script.py Normal file → Executable file
View file

@ -5,7 +5,7 @@ import requests
from ambit import Ambito
from country import Country
from utils import stringbetween, get_tv_channels_from_part, get_license_info
from utils import stringbetween, get_tv_channels_from_part, get_license_info, get_current_timestamp
page = requests.get('https://raw.githubusercontent.com/LaQuay/TDTChannels/master/TELEVISION.md',
headers={'Cache-Control': 'no-cache'})
@ -159,20 +159,19 @@ canales_andorra = stringbetween(content, "## Andorra", "")
andorra.add_ambit(Ambito("Andorra", get_tv_channels_from_part(canales_andorra)))
# Save data to JSON file
json_result = {"license": get_license_info(),
"epg_url": "https://raw.githubusercontent.com/HelmerLuzo/TDTChannels_EPG/master/TDTChannels_EPG.xml",
"countries": [spain.to_json(),
international.to_json(),
andorra.to_json()],
"updated": get_current_timestamp()
}
json_file = open('./public/output/channels.json', "w+")
json_file.write("[")
json_file.write(json.dumps(get_license_info()))
json_file.write(", ")
json_file.write(json.dumps(spain.to_json()))
json_file.write(", ")
json_file.write(json.dumps(international.to_json()))
json_file.write(", ")
json_file.write(json.dumps(andorra.to_json()))
json_file.write("]")
json_file.write(json.dumps(json_result, indent=4, sort_keys=False))
json_file.close()
print("JSON Updated")
# Save data to M3U8 file
# Save data to M3U8 file
text_file = open('./public/output/channels.m3u8', "w+")
text_file.write("#EXTM3U @LaQuay https://github.com/LaQuay/TDTChannels" + "\n")
text_file.write(

28
script/utils.py Normal file → Executable file
View file

@ -1,4 +1,6 @@
import re
import calendar
import time
from channel import Channel
@ -6,10 +8,14 @@ from channel import Channel
def get_license_info():
return {
"source": "https://github.com/LaQuay/TDTChannels",
"license": "https://github.com/LaQuay/TDTChannels/blob/master/LICENSE"
"url": "https://github.com/LaQuay/TDTChannels/blob/master/LICENSE"
}
def get_current_timestamp():
return calendar.timegm(time.gmtime())
def stringbetween(text, start, end):
result = re.search('(?<=' + start + ')(.*)(?=' + end + ')', text, re.DOTALL)
return result.group(1)
@ -54,15 +60,21 @@ def get_tv_channels_from_part(text):
item_extra_info = list_to_iterate[i + 5].strip()
if len(item_extra_info) == 1:
item_extra_info = ""
item_extra_info = []
else:
item_extra_info = item_extra_info.split(",")
channel = Channel(item_name, item_web, item_resolution, item_logo, item_epg, item_extra_info)
channel = Channel(item_name, item_web, item_resolution, item_logo, item_epg, item_extra_info, "Video")
item_options = item_options.split(" - ")
if len(item_options) > 0 and item_options[0] != "-":
for option in item_options:
format = (option[1:5]).replace("]", "")
url = stringbetweenparantheses(option)
channel.add_option(format, url)
if "# GEO" in option:
more_info = ["GEO"]
else:
more_info =[]
channel.add_option(format, url, more_info)
channel_list.append(channel)
return channel_list
@ -93,14 +105,16 @@ def get_radio_channels_from_part(text):
item_extra_info = list_to_iterate[i + 4].strip()
if len(item_extra_info) == 1:
item_extra_info = ""
item_extra_info = []
else:
item_extra_info = item_extra_info.split(",")
channel = Channel(item_name, item_web, "", item_logo, "", item_extra_info)
channel = Channel(item_name, item_web, "", item_logo, "", item_extra_info, "Audio")
item_options = item_options.split(" - ")
if len(item_options) > 0 and item_options[0] != "-":
for option in item_options:
format = (option[1:5]).replace("]", "")
url = stringbetweenparantheses(option)
channel.add_option(format, url)
channel.add_option(format, url, [])
channel_list.append(channel)
return channel_list