From ce8cc6562aaf2ece984a74be3d877bc7958214e5 Mon Sep 17 00:00:00 2001
From: Jacobo Rodriguez <>
Date: Thu, 13 Jun 2019 12:10:42 +0200
Subject: [PATCH 1/6] New propostal for json file

---
 script/channel.py      | 16 ++++++++++------
 script/radio_script.py | 18 ++++++++----------
 script/tv_script.py    | 21 ++++++++++-----------
 script/utils.py        | 28 +++++++++++++++++++++-------
 4 files changed, 49 insertions(+), 34 deletions(-)
 mode change 100644 => 100755 script/tv_script.py
 mode change 100644 => 100755 script/utils.py

diff --git a/script/channel.py b/script/channel.py
index e53e0f40..683c079f 100644
--- a/script/channel.py
+++ b/script/channel.py
@@ -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
             }
diff --git a/script/radio_script.py b/script/radio_script.py
index 7759a4e9..90ea6bb5 100644
--- a/script/radio_script.py
+++ b/script/radio_script.py
@@ -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")
 
diff --git a/script/tv_script.py b/script/tv_script.py
old mode 100644
new mode 100755
index 485a0ee3..66626d59
--- a/script/tv_script.py
+++ b/script/tv_script.py
@@ -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(
diff --git a/script/utils.py b/script/utils.py
old mode 100644
new mode 100755
index ce73ae36..b4771055
--- a/script/utils.py
+++ b/script/utils.py
@@ -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

From c2c599133d268dbc2577c02e9a06b2bbd3f7f85a Mon Sep 17 00:00:00 2001
From: Jacobo Rodriguez <>
Date: Fri, 14 Jun 2019 06:21:59 +0200
Subject: [PATCH 2/6] Remove TYPE value

---
 script/channel.py | 4 +---
 script/utils.py   | 4 ++--
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/script/channel.py b/script/channel.py
index 683c079f..8ef29e58 100644
--- a/script/channel.py
+++ b/script/channel.py
@@ -1,6 +1,6 @@
 # TODO Create TVChannel and RadioChannel
 class Channel:
-    def __init__(self, name, web, resolution, logo, epg_id, extra_info, type):
+    def __init__(self, name, web, resolution, logo, epg_id, extra_info):
         self.name = name
         self.web = web
         self.resolution = resolution
@@ -8,7 +8,6 @@ class Channel:
         self.epg_id = epg_id
         self.options = []
         self.extra_info = extra_info
-        self.type = type
 
     def add_option(self, format, url, info):
         self.options.append(self.Web(format, url, info))
@@ -52,7 +51,6 @@ class Channel:
             "epg_id": self.epg_id,
             "options": self.__options_to_json__(),
             "extra_info": self.extra_info,
-            "type": self.type
         }
 
     def to_m3u8(self, ambit_name, option):
diff --git a/script/utils.py b/script/utils.py
index b4771055..5da21c1d 100755
--- a/script/utils.py
+++ b/script/utils.py
@@ -64,7 +64,7 @@ def get_tv_channels_from_part(text):
         else:
             item_extra_info = item_extra_info.split(",")
 
-        channel = Channel(item_name, item_web, item_resolution, item_logo, item_epg, item_extra_info, "Video")
+        channel = Channel(item_name, item_web, item_resolution, item_logo, item_epg, item_extra_info)
         item_options = item_options.split(" - ")
         if len(item_options) > 0 and item_options[0] != "-":
             for option in item_options:
@@ -109,7 +109,7 @@ def get_radio_channels_from_part(text):
         else:
             item_extra_info = item_extra_info.split(",")
 
-        channel = Channel(item_name, item_web, "", item_logo, "", item_extra_info, "Audio")
+        channel = Channel(item_name, item_web, "", item_logo, "", item_extra_info)
         item_options = item_options.split(" - ")
         if len(item_options) > 0 and item_options[0] != "-":
             for option in item_options:

From f088ceddd579f945123c44799c853fe7e10db0e8 Mon Sep 17 00:00:00 2001
From: Jacobo Rodriguez <>
Date: Fri, 14 Jun 2019 06:43:51 +0200
Subject: [PATCH 3/6] Send nulls instead of empty string to avoid stings logic

---
 script/utils.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/script/utils.py b/script/utils.py
index 5da21c1d..50ff77df 100755
--- a/script/utils.py
+++ b/script/utils.py
@@ -41,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"
@@ -52,11 +52,11 @@ 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:
@@ -95,13 +95,13 @@ 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:
@@ -109,7 +109,7 @@ def get_radio_channels_from_part(text):
         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:

From f6bc6ebf05d035f3f8466e0507d6ecaa5751ea25 Mon Sep 17 00:00:00 2001
From: Jacobo Rodriguez <>
Date: Fri, 14 Jun 2019 06:48:09 +0200
Subject: [PATCH 4/6] Missing field

---
 script/radio_script.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/script/radio_script.py b/script/radio_script.py
index 90ea6bb5..9838bb36 100644
--- a/script/radio_script.py
+++ b/script/radio_script.py
@@ -148,6 +148,7 @@ 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()],

From 8943750f18d72faf576064188703a4f59543bcd1 Mon Sep 17 00:00:00 2001
From: Jacobo Rodriguez <>
Date: Fri, 14 Jun 2019 06:52:10 +0200
Subject: [PATCH 5/6] Remove unnecessary coma

---
 script/channel.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/script/channel.py b/script/channel.py
index 8ef29e58..fcc2cb78 100644
--- a/script/channel.py
+++ b/script/channel.py
@@ -50,7 +50,7 @@ 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
         }
 
     def to_m3u8(self, ambit_name, option):

From 84818c1aa334e64e4234f48afd7c0fcf566115db Mon Sep 17 00:00:00 2001
From: Jacobo Rodriguez <>
Date: Fri, 14 Jun 2019 06:55:52 +0200
Subject: [PATCH 6/6] Update Authors file

---
 AUTHORS.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/AUTHORS.md b/AUTHORS.md
index c316fa37..1e4451b6 100644
--- a/AUTHORS.md
+++ b/AUTHORS.md
@@ -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)