mirror of
https://github.com/LaQuay/TDTChannels.git
synced 2025-03-24 10:36:30 +01:00
Merge pull request #177 from poborp/Feature/json-propostal
Nueva propuesta para el archivo json
This commit is contained in:
commit
ba7270e3be
5 changed files with 51 additions and 36 deletions
|
@ -11,6 +11,7 @@
|
|||
- CaRLymx [@carlymx](https://github.com/carlymx)
|
||||
- Carlos [@profesorasix](https://github.com/profesorasix)
|
||||
- Carratraka [@carratraka](https://github.com/carratraka)
|
||||
- Jacobo [@poborp](https://github.com/poborp)
|
||||
- Jorge [@jaguaza](https://github.com/jaguaza)
|
||||
- Juan [@okelet](https://github.com/okelet)
|
||||
- Valentin [@vk496](https://github.com/vk496)
|
||||
|
|
|
@ -9,8 +9,8 @@ class Channel:
|
|||
self.options = []
|
||||
self.extra_info = extra_info
|
||||
|
||||
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
|
||||
|
@ -76,9 +76,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 +99,6 @@ class Channel:
|
|||
def to_json(self):
|
||||
return {
|
||||
"format": self.format,
|
||||
"url": self.url
|
||||
"url": self.url,
|
||||
"extra_info": self.info
|
||||
}
|
||||
|
|
|
@ -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,15 @@ 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(),
|
||||
"epg_url": None,
|
||||
"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
21
script/tv_script.py
Normal file → Executable 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(
|
||||
|
|
36
script/utils.py
Normal file → Executable file
36
script/utils.py
Normal file → Executable 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)
|
||||
|
@ -35,7 +41,7 @@ def get_tv_channels_from_part(text):
|
|||
if len(item_web) > 0 and item_web[0] != "-":
|
||||
item_web = stringbetweenparantheses(item_web)
|
||||
if len(item_web) == 1:
|
||||
item_web = ""
|
||||
item_web = None
|
||||
|
||||
if "HD" in item_name:
|
||||
item_resolution = "HD"
|
||||
|
@ -46,15 +52,17 @@ def get_tv_channels_from_part(text):
|
|||
if len(item_logo) > 0 and item_logo[0] != "-":
|
||||
item_logo = stringbetweenparantheses(item_logo)
|
||||
if len(item_logo) == 1:
|
||||
item_logo = ""
|
||||
item_logo = None
|
||||
|
||||
item_epg = list_to_iterate[i + 4].strip()
|
||||
if len(item_epg) == 1:
|
||||
item_epg = ""
|
||||
item_epg = None
|
||||
|
||||
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)
|
||||
item_options = item_options.split(" - ")
|
||||
|
@ -62,7 +70,11 @@ def get_tv_channels_from_part(text):
|
|||
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
|
||||
|
||||
|
@ -83,24 +95,26 @@ def get_radio_channels_from_part(text):
|
|||
if len(item_web) > 0 and item_web[0] != "-":
|
||||
item_web = stringbetweenparantheses(item_web)
|
||||
if len(item_web) == 1:
|
||||
item_web = ""
|
||||
item_web = None
|
||||
|
||||
item_logo = list_to_iterate[i + 3].strip()
|
||||
if len(item_logo) > 0 and item_logo[0] != "-":
|
||||
item_logo = stringbetweenparantheses(item_logo)
|
||||
if len(item_logo) == 1:
|
||||
item_logo = ""
|
||||
item_logo = None
|
||||
|
||||
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, None, item_logo, None, item_extra_info)
|
||||
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
|
||||
|
|
Loading…
Add table
Reference in a new issue