2018-09-22 19:28:28 +02:00
|
|
|
# coding=utf-8
|
|
|
|
import json
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
2018-09-23 11:52:56 +02:00
|
|
|
from ambit import Ambito
|
2018-09-22 19:28:28 +02:00
|
|
|
from country import Country
|
2019-01-08 15:57:44 +01:00
|
|
|
from utils import stringbetween, get_channels_from_part, get_license_info
|
2019-01-08 15:47:06 +01:00
|
|
|
|
2019-01-08 15:57:44 +01:00
|
|
|
page = requests.get('https://raw.githubusercontent.com/LaQuay/TDTChannels/master/TELEVISION.md',
|
2018-09-22 19:28:28 +02:00
|
|
|
headers={'Cache-Control': 'no-cache'})
|
|
|
|
content = str(page.text)
|
|
|
|
|
|
|
|
spain = Country("Spain")
|
2019-01-08 15:57:44 +01:00
|
|
|
andorra = Country("Andorra")
|
2018-11-04 21:59:53 +01:00
|
|
|
international = Country("International")
|
2018-09-22 19:28:28 +02:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
content_nacional = stringbetween(content, "## Nacionales", "## Locales")
|
|
|
|
content_local = stringbetween(content, "## Locales", "## Internacionales")
|
2019-01-07 23:45:27 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_nacionales = stringbetween(content_nacional, "", "## Informativos")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Generalistas", get_channels_from_part(canales_nacionales)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_informativos = stringbetween(content_nacional, "## Informativos", "## Deportivos")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Informativos", get_channels_from_part(canales_informativos)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_deportivos = stringbetween(content_nacional, "## Deportivos", "## Infantiles")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Deportivos", get_channels_from_part(canales_deportivos)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_infantiles = stringbetween(content_nacional, "## Infantiles", "## Musicales")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Infantiles", get_channels_from_part(canales_infantiles)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_musicales = stringbetween(content_nacional, "## Musicales", "## Autonómicos")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Musicales", get_channels_from_part(canales_musicales)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_andalucia = stringbetween(content_nacional, "### Andalucía", "### Aragón")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Andalucía", get_channels_from_part(canales_autonomicos_andalucia)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_aragon = stringbetween(content_nacional, "### Aragón", "### Asturias")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Aragón", get_channels_from_part(canales_autonomicos_aragon)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_asturias = stringbetween(content_nacional, "### Asturias", "### Canarias")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Asturias", get_channels_from_part(canales_autonomicos_asturias)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_canarias = stringbetween(content_nacional, "### Canarias", "### Cantabria")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Canarias", get_channels_from_part(canales_autonomicos_canarias)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_cantabria = stringbetween(content_nacional, "### Cantabria", "### Castilla La-Mancha")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Cantabria", get_channels_from_part(canales_autonomicos_cantabria)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_castilla_mancha = stringbetween(content_nacional, "### Castilla La-Mancha", "### Castilla y León")
|
2019-01-07 22:45:12 +01:00
|
|
|
spain.add_ambit(Ambito("Castilla La-Mancha", get_channels_from_part(canales_autonomicos_castilla_mancha)))
|
2018-09-22 19:28:28 +02:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_castilla_leon = stringbetween(content_nacional, "### Castilla y León", "### Cataluña")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Castilla y León", get_channels_from_part(canales_autonomicos_castilla_leon)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_catalunya = stringbetween(content_nacional, "### Cataluña", "### Ceuta")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.add_ambit(Ambito("Cataluña", get_channels_from_part(canales_autonomicos_catalunya)))
|
2018-09-22 19:28:28 +02:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_ceuta = stringbetween(content_nacional, "### Ceuta", "### Extremadura")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Ceuta", get_channels_from_part(canales_autonomicos_ceuta)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_extremadura = stringbetween(content_nacional, "### Extremadura", "### Galicia")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Extremadura", get_channels_from_part(canales_autonomicos_extremadura)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_galicia = stringbetween(content_nacional, "### Galicia", "### Islas Baleares")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Galicia", get_channels_from_part(canales_autonomicos_galicia)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_islas_baleares = stringbetween(content_nacional, "### Islas Baleares", "### La Rioja")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Islas Baleares", get_channels_from_part(canales_autonomicos_islas_baleares)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_la_rioja = stringbetween(content_nacional, "### La Rioja", "### Madrid")
|
2019-01-07 22:45:12 +01:00
|
|
|
spain.add_ambit(Ambito("La Rioja", get_channels_from_part(canales_autonomicos_la_rioja)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_madrid = stringbetween(content_nacional, "### Madrid", "### Melilla")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Madrid", get_channels_from_part(canales_autonomicos_madrid)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_melilla = stringbetween(content_nacional, "### Melilla", "### Murcia")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Melilla", get_channels_from_part(canales_autonomicos_melilla)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_murcia = stringbetween(content_nacional, "### Murcia", "### Navarra")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Murcia", get_channels_from_part(canales_autonomicos_murcia)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_navarra = stringbetween(content_nacional, "### Navarra", "### País Vasco")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Navarra", get_channels_from_part(canales_autonomicos_navarra)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_pais_vasco = stringbetween(content_nacional, "### País Vasco", "### Valencia")
|
2019-01-07 22:45:12 +01:00
|
|
|
spain.add_ambit(Ambito("País Vasco", get_channels_from_part(canales_autonomicos_pais_vasco)))
|
2018-09-22 19:28:28 +02:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_autonomicos_valencia = stringbetween(content_nacional, "### Valencia", "")
|
2018-09-22 19:28:28 +02:00
|
|
|
spain.add_ambit(Ambito("Valencia", get_channels_from_part(canales_autonomicos_valencia)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_andalucia = stringbetween(content_local, "### Andalucía", "### Aragón")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Andalucía").add_channels(get_channels_from_part(canales_locales_andalucia))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_aragon = stringbetween(content_local, "### Aragón", "### Asturias")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Aragón").add_channels(get_channels_from_part(canales_locales_aragon))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_asturias = stringbetween(content_local, "### Asturias", "### Canarias")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Asturias").add_channels(get_channels_from_part(canales_locales_asturias))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_canarias = stringbetween(content_local, "### Canarias", "### Cantabria")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Canarias").add_channels(get_channels_from_part(canales_locales_canarias))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_cantabria = stringbetween(content_local, "### Cantabria", "### Castilla La-Mancha")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Cantabria").add_channels(get_channels_from_part(canales_locales_cantabria))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_castilla_mancha = stringbetween(content_local, "### Castilla La-Mancha", "### Castilla y León")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Castilla La-Mancha").add_channels(get_channels_from_part(canales_locales_castilla_mancha))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_castilla_leon = stringbetween(content_local, "### Castilla y León", "### Cataluña")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Castilla y León").add_channels(get_channels_from_part(canales_locales_castilla_leon))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_catalunya = stringbetween(content_local, "### Cataluña", "### Ceuta")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Cataluña").add_channels(get_channels_from_part(canales_locales_catalunya))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_ceuta = stringbetween(content_local, "### Ceuta", "### Extremadura")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Ceuta").add_channels(get_channels_from_part(canales_locales_ceuta))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_extremadura = stringbetween(content_local, "### Extremadura", "### Galicia")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Extremadura").add_channels(get_channels_from_part(canales_locales_extremadura))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_galicia = stringbetween(content_local, "### Galicia", "### Islas Baleares")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Galicia").add_channels(get_channels_from_part(canales_locales_galicia))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_islas_baleares = stringbetween(content_local, "### Islas Baleares", "### La Rioja")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Islas Baleares").add_channels(get_channels_from_part(canales_locales_islas_baleares))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_la_rioja = stringbetween(content_local, "### La Rioja", "### Madrid")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("La Rioja").add_channels(get_channels_from_part(canales_locales_la_rioja))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_madrid = stringbetween(content_local, "### Madrid", "### Melilla")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Madrid").add_channels(get_channels_from_part(canales_locales_madrid))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_melilla = stringbetween(content_local, "### Melilla", "### Murcia")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Melilla").add_channels(get_channels_from_part(canales_locales_melilla))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_murcia = stringbetween(content_local, "### Murcia", "### Navarra")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Murcia").add_channels(get_channels_from_part(canales_locales_murcia))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_navarra = stringbetween(content_local, "### Navarra", "### País Vasco")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Navarra").add_channels(get_channels_from_part(canales_locales_navarra))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_pais_vasco = stringbetween(content_local, "### País Vasco", "### Valencia")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("País Vasco").add_channels(get_channels_from_part(canales_locales_pais_vasco))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_locales_valencia = stringbetween(content_local, "### Valencia", "")
|
2019-01-07 23:45:27 +01:00
|
|
|
spain.get_ambit("Valencia").add_channels(get_channels_from_part(canales_locales_valencia))
|
2019-01-07 22:45:12 +01:00
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_internacionales = stringbetween(content, "## Internacionales", "## Andorra")
|
2018-11-04 21:59:53 +01:00
|
|
|
international.add_ambit(Ambito("Internacional", get_channels_from_part(canales_internacionales)))
|
|
|
|
|
2019-01-14 22:27:53 +01:00
|
|
|
canales_andorra = stringbetween(content, "## Andorra", "")
|
2019-01-08 15:57:44 +01:00
|
|
|
andorra.add_ambit(Ambito("Andorra", get_channels_from_part(canales_andorra)))
|
|
|
|
|
2018-09-22 19:28:28 +02:00
|
|
|
# Save data to JSON file
|
2018-09-23 13:44:01 +02:00
|
|
|
json_file = open('./public/output/channels.json', "w+")
|
2018-11-04 21:59:53 +01:00
|
|
|
json_file.write("[")
|
2019-01-08 15:47:06 +01:00
|
|
|
json_file.write(json.dumps(get_license_info()))
|
|
|
|
json_file.write(", ")
|
2018-09-22 19:28:28 +02:00
|
|
|
json_file.write(json.dumps(spain.to_json()))
|
2018-11-04 21:59:53 +01:00
|
|
|
json_file.write(", ")
|
|
|
|
json_file.write(json.dumps(international.to_json()))
|
2019-01-08 15:57:44 +01:00
|
|
|
json_file.write(", ")
|
|
|
|
json_file.write(json.dumps(andorra.to_json()))
|
2018-11-04 21:59:53 +01:00
|
|
|
json_file.write("]")
|
2018-09-22 19:28:28 +02:00
|
|
|
json_file.close()
|
|
|
|
|
|
|
|
# Save data to M3U8 file
|
2018-09-23 13:44:01 +02:00
|
|
|
text_file = open('./public/output/channels.m3u8', "w+")
|
2018-09-22 19:28:28 +02:00
|
|
|
text_file.write("#EXTM3U" + "\n")
|
|
|
|
text_file.write("# @LaQuay https://github.com/LaQuay/TDTChannels" + "\n")
|
|
|
|
text_file.write(spain.to_m3u8())
|
2018-11-04 21:59:53 +01:00
|
|
|
text_file.write(international.to_m3u8())
|
2018-09-22 19:28:28 +02:00
|
|
|
text_file.close()
|
|
|
|
|
|
|
|
print("JSON + M3U8 Updated")
|