1
0
Fork 0
mirror of https://github.com/LaQuay/TDTChannels.git synced 2025-04-27 19:35:28 +02:00

Base commit for SRC

This commit is contained in:
Marc 2018-09-22 19:28:28 +02:00
parent dd2b46e1d3
commit 14cb3e74a2
8 changed files with 371 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
venv/
.idea/
__pycache__/

0
script/__init__.py Normal file
View file

33
script/ambito.py Normal file
View file

@ -0,0 +1,33 @@
class Ambito:
name = None
channels = []
def __init__(self, name, channels):
self.name = name
self.channels = channels
def __channels_to_json__(self):
channel_list = []
for channel in self.channels:
channel_list.append(channel.to_json())
return channel_list
def to_json(self):
return {
"name": self.name,
"channels": self.__channels_to_json__()
}
def __channels_to_m3u8__(self):
channels_list = ""
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"
return channels_list
def to_m3u8(self):
return self.__channels_to_m3u8__()
def __str__(self):
return self.name

60
script/channel.py Normal file
View file

@ -0,0 +1,60 @@
class Channel:
name = None
options = []
def __init__(self, name):
self.name = name
self.options = []
def add_option(self, format, url):
self.options.append(self.Web(format, url))
def get_name(self):
return self.name
def get_options(self):
return self.options
def __str__(self):
options_string = ""
for option in self.options:
options_string += "[Format: " + option.get_format() + ", URL: " + option.get_url() + "]"
return (self.name + " " + options_string)
def __options_to_json__(self):
options_list = []
for option in self.options:
options_list.append(option.to_json())
return options_list
def to_json(self):
return {
"name": self.name,
"options": self.__options_to_json__()
}
class Web:
format = None
url = None
def __init__(self, format, url):
self.format = format
self.url = url
def is_m3u8_valid(self):
return self.format == "m3u8"
def get_format(self):
return self.format
def get_url(self):
return self.url
def __str__(self):
return (self.format + ", " + self.url)
def to_json(self):
return {
"format": self.format,
"url": self.url
}

32
script/country.py Normal file
View file

@ -0,0 +1,32 @@
class Country:
name = None
ambits = []
def __init__(self, name):
self.name = name
self.ambits = []
def add_ambit(self, ambit):
self.ambits.append(ambit)
# TODO Habria que filtrar los que no tienen campos de url
def __ambits_to_json__(self):
ambits_list = []
for ambit in self.ambits:
ambits_list.append(ambit.to_json())
return ambits_list
def to_json(self):
return {
"name": self.name,
"ambits": self.__ambits_to_json__()
}
def __ambits_to_m3u8__(self):
ambits_list = ""
for ambit in self.ambits:
ambits_list += ambit.to_m3u8()
return ambits_list
def to_m3u8(self):
return self.__ambits_to_m3u8__()

133
script/my_script.py Normal file
View file

@ -0,0 +1,133 @@
# coding=utf-8
import json
import requests
from ambito import Ambito
from channel import Channel
from country import Country
def substring(text, match):
return text.split(match)
def stringbetween(text, start, end):
text_from_start_to_all = substring(text, start)[1]
text_from_start_to_end = substring(text_from_start_to_all, end)[0]
return text_from_start_to_end
def get_channels_from_part(text):
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]
item_name = item_name.replace("|", "").replace("\n", "").strip()
item_options = (item_options.replace("|", "").replace("\n", "")).split(" - ")
channel = Channel(item_name)
if len(item_options) > 0 and item_options[0] != "":
for option in item_options:
format = (option[1:5]).replace("]", "")
url = stringbetween(option, "(", ")")
channel.add_option(format, url)
channel_list.append(channel)
return channel_list
page = requests.get('https://raw.githubusercontent.com/LaQuay/TDTChannels/master/README.md',
headers={'Cache-Control': 'no-cache'})
content = str(page.text)
spain = Country("Spain")
canales_nacionales = stringbetween(content, "### Nacionales", "### Informativos")
spain.add_ambit(Ambito("Generalistas", get_channels_from_part(canales_nacionales)))
canales_informativos = stringbetween(content, "### Informativos", "### Deportivos")
spain.add_ambit(Ambito("Informativos", get_channels_from_part(canales_informativos)))
canales_deportivos = stringbetween(content, "### Deportivos", "### Infantiles")
spain.add_ambit(Ambito("Deportivos", get_channels_from_part(canales_deportivos)))
canales_infantiles = stringbetween(content, "### Infantiles", "### Musicales")
spain.add_ambit(Ambito("Infantiles", get_channels_from_part(canales_infantiles)))
canales_musicales = stringbetween(content, "### Musicales", "### Autonómicos")
spain.add_ambit(Ambito("Musicales", get_channels_from_part(canales_musicales)))
canales_autonomicos_andalucia = stringbetween(content, "#### Andalucía", "#### Aragón")
spain.add_ambit(Ambito("Andalucía", get_channels_from_part(canales_autonomicos_andalucia)))
canales_autonomicos_aragon = stringbetween(content, "#### Aragón", "#### Asturias")
spain.add_ambit(Ambito("Aragón", get_channels_from_part(canales_autonomicos_aragon)))
canales_autonomicos_asturias = stringbetween(content, "#### Asturias", "#### Canarias")
spain.add_ambit(Ambito("Asturias", get_channels_from_part(canales_autonomicos_asturias)))
canales_autonomicos_canarias = stringbetween(content, "#### Canarias", "#### Cantabria")
spain.add_ambit(Ambito("Canarias", get_channels_from_part(canales_autonomicos_canarias)))
canales_autonomicos_cantabria = stringbetween(content, "#### Cantabria", "#### Castilla la Mancha")
spain.add_ambit(Ambito("Cantabria", get_channels_from_part(canales_autonomicos_cantabria)))
canales_autonomicos_castilla_mancha = stringbetween(content, "#### Castilla la Mancha", "#### Castilla y León")
spain.add_ambit(Ambito("Castilla la Mancha", get_channels_from_part(canales_autonomicos_castilla_mancha)))
canales_autonomicos_castilla_leon = stringbetween(content, "#### Castilla y León", "#### Catalunya")
spain.add_ambit(Ambito("Castilla y León", get_channels_from_part(canales_autonomicos_castilla_leon)))
canales_autonomicos_catalunya = stringbetween(content, "#### Catalunya", "#### Ceuta")
spain.add_ambit(Ambito("Catalunya", get_channels_from_part(canales_autonomicos_catalunya)))
canales_autonomicos_ceuta = stringbetween(content, "#### Ceuta", "#### Extremadura")
spain.add_ambit(Ambito("Ceuta", get_channels_from_part(canales_autonomicos_ceuta)))
canales_autonomicos_extremadura = stringbetween(content, "#### Extremadura", "#### Galicia")
spain.add_ambit(Ambito("Extremadura", get_channels_from_part(canales_autonomicos_extremadura)))
canales_autonomicos_galicia = stringbetween(content, "#### Galicia", "#### Islas Baleares")
spain.add_ambit(Ambito("Galicia", get_channels_from_part(canales_autonomicos_galicia)))
canales_autonomicos_islas_baleares = stringbetween(content, "### Islas Baleares", "#### Madrid")
spain.add_ambit(Ambito("Islas Baleares", get_channels_from_part(canales_autonomicos_islas_baleares)))
canales_autonomicos_madrid = stringbetween(content, "#### Madrid", "#### Melilla")
spain.add_ambit(Ambito("Madrid", get_channels_from_part(canales_autonomicos_madrid)))
canales_autonomicos_melilla = stringbetween(content, "#### Melilla", "#### Murcia")
spain.add_ambit(Ambito("Melilla", get_channels_from_part(canales_autonomicos_melilla)))
canales_autonomicos_murcia = stringbetween(content, "#### Murcia", "#### Navarra")
spain.add_ambit(Ambito("Murcia", get_channels_from_part(canales_autonomicos_murcia)))
canales_autonomicos_navarra = stringbetween(content, "#### Navarra", "#### Pais Vasco")
spain.add_ambit(Ambito("Navarra", get_channels_from_part(canales_autonomicos_navarra)))
canales_autonomicos_pais_vasco = stringbetween(content, "#### Pais Vasco", "#### La Rioja")
spain.add_ambit(Ambito("Pais Vasco", get_channels_from_part(canales_autonomicos_pais_vasco)))
canales_autonomicos_la_rioja = stringbetween(content, "#### La Rioja", "#### Valencia")
spain.add_ambit(Ambito("La Rioja", get_channels_from_part(canales_autonomicos_la_rioja)))
canales_autonomicos_valencia = stringbetween(content, "#### Valencia", "## Internacionales")
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+")
# 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.write("#EXTM3U" + "\n")
text_file.write("# @LaQuay https://github.com/LaQuay/TDTChannels" + "\n")
text_file.write(spain.to_m3u8())
text_file.close()
print("JSON + M3U8 Updated")

37
script/public/index.html Normal file
View file

@ -0,0 +1,37 @@
<html>
<head>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/clappr@latest/dist/clappr.min.js"></script>
</head>
<body>
<div id="player"></div>
<script>
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var channelToReproduce = getUrlParameter("channel");
if (channelToReproduce.includes("m3u8")) {
var player = new Clappr.Player({
source: channelToReproduce,
parentId: '#player',
height: '100%',
width: '100%',
autoPlay: true,
});
}
</script>
</body>
</html>

View file

@ -0,0 +1,73 @@
<html>
<head>
<link href="https://unpkg.com/video.js/dist/video-js.css" rel="stylesheet">
<script src="https://unpkg.com/video.js/dist/video.js"></script>
<script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
<style>
* {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<video autoplay preload="auto" controls id="player" class="video-js vjs-default-skin">
</video>
<script>
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var channelToReproduce = getUrlParameter("channel");
if (channelToReproduce.includes("m3u8")) {
videojs('player').src({type: 'application/x-mpegURL', src: channelToReproduce});
videojs('player').ready(function () {
var myPlayer = this;
myPlayer.play();
// Store the video object
var myPlayer = this, id = myPlayer.id();
// Make up an aspect ratio
var aspectRatio = 9.0/17.5;
var reduction = 0.95;
function resizeVideoJS(){
var width = document.getElementById(id).parentElement.offsetWidth;
myPlayer.width(width*reduction);
myPlayer.height(width*aspectRatio*reduction);
}
// Initialize resizeVideoJS()
resizeVideoJS();
// Then on resize call resizeVideoJS()
window.onresize = resizeVideoJS();
});
videojs('player').on('dblclick', function() {
var myPlayer = this;
if (myPlayer.isFullscreen()) {
myPlayer.exitFullscreen();
} else {
myPlayer.requestFullscreen();
}
});
}
</script>
</body>
</html>