Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions usr/lib/hypnotix/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import re
import threading
from email.utils import formatdate

import requests
from gi.repository import GLib, GObject
Expand All @@ -12,6 +13,7 @@
SERIES = re.compile(r"(?P<series>.*?) S(?P<season>.\d{1,2}).*E(?P<episode>.\d{1,2}.*)$", re.IGNORECASE)

PROVIDERS_PATH = os.path.join(GLib.get_user_cache_dir(), "hypnotix", "providers")
EPG_PATH = os.path.join(GLib.get_user_cache_dir(), "hypnotix", "epg")

TV_GROUP, MOVIES_GROUP, SERIES_GROUP = range(3)

Expand Down Expand Up @@ -73,7 +75,7 @@
self.series = []


class Serie:

Check failure on line 78 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

Serie ==> Series
def __init__(self, name):
self.name = name
self.logo = None
Expand All @@ -98,19 +100,27 @@
self.group_title = None
self.title = None
self.url = None
self.tvg_id = None
self.tvg_name = None
self.xmltv_id = None
match = EXTINF.fullmatch(info)
if match is not None:
res = match.groupdict()
if 'params' in res:
params = dict(PARAMS.findall(res['params']))
if "tvg-id" in params and params['tvg-id'].strip() != "":
self.tvg_id = params['tvg-id'].strip()
if "tvg-name" in params and params['tvg-name'].strip() != "":
self.name = params['tvg-name'].strip()
self.tvg_name = self.name
if "tvg-logo" in params and params['tvg-logo'].strip() != "":
self.logo = params['tvg-logo'].strip()
if "group-title" in params and params['group-title'].strip() != "":
self.group_title = params['group-title'].strip().replace(";", " ").replace(" ", " ")
if 'title' in res:
self.title = res['title']
self.title = res['title'].strip()
if self.title is None and "," in info:
self.title = info.split(",")[-1].strip()
if self.name is None and "," in info:
self.name = info.split(",")[-1].strip()
if self.logo is not None:
Expand All @@ -134,6 +144,7 @@
class Manager:
def __init__(self, settings):
os.system("mkdir -p '%s'" % PROVIDERS_PATH)
os.system("mkdir -p '%s'" % EPG_PATH)
self.verbose = False
self.settings = settings

Expand Down Expand Up @@ -167,11 +178,19 @@
'User-Agent': self.settings.get_string("user-agent"),
'Referer': self.settings.get_string("http-referer")
}

if os.path.exists(provider.path):
mtime = os.path.getmtime(provider.path)
headers['If-Modified-Since'] = formatdate(mtime, usegmt=True)

try:
response = requests.get(provider.url, headers=headers, timeout=(5, 120), stream=True)

# If there is an answer from the remote server
if response.status_code == 200:
if response.status_code == 304:
print("HTTP 304 Not Modified: Using cached playlist.")
ret_code = True
elif response.status_code == 200:
# Set downloaded size
downloaded_bytes = 0
# Get total playlist byte size
Expand All @@ -196,7 +215,7 @@
print("The file size is incorrect, deleting")
os.remove(provider.path)
else:
# Set the datatime when it was last retreived

Check failure on line 218 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

retreived ==> retrieved
# self.settings.set_
ret_code = True
else:
Expand Down Expand Up @@ -250,19 +269,19 @@
channel.url = line
self.debug(" --> URL found: ", line)

serie = None

Check failure on line 272 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

serie ==> series
f = SERIES.fullmatch(channel.name)
if f is not None:
res = f.groupdict()
series_name = res['series']
if series_name in series.keys():
serie = series[series_name]

Check failure on line 278 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

serie ==> series
else:
serie = Serie(series_name)

Check failure on line 280 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

Serie ==> Series

Check failure on line 280 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

serie ==> series
# todo put in group
provider.series.append(serie)

Check failure on line 282 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

serie ==> series
series[series_name] = serie

Check failure on line 283 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

serie ==> series
serie.logo = channel.logo

Check failure on line 284 in usr/lib/hypnotix/common.py

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22.3-amd64, Mint 22, true) / Mint 22

serie ==> series
serie.logo_path = channel.logo_path
season_name = res['season']
if season_name in serie.seasons.keys():
Expand Down Expand Up @@ -293,6 +312,13 @@
else:
provider.channels.append(channel)

def load_epg(self, provider, refresh=False):
if getattr(provider, "epg", None):
from epg import EPGManager
epg_mgr = EPGManager(user_agent=self.settings.get_string("user-agent"))
epg_mgr.load_epg_for_provider(provider, refresh=refresh)
provider.epg_manager = epg_mgr

def load_favorites(self):
favorites = []
with open(FAVORITES_PATH, 'r', encoding="utf-8", errors="ignore") as f:
Expand Down
Loading
Loading