Skip to content

Commit

Permalink
Lint changes (#251)
Browse files Browse the repository at this point in the history
* statement ends with a semicolon
* ambiguous variable name
* local variable _fmt is assigned to but never used
* local variable e is assigned to but never used
* statement ends with a semicolon
* over-indented
* local variable cval is assigned to but never used
* local variable ex is assigned to but never used
* over-indented
* 'gi.repository.XApp' imported but unused
* comparison to None should be 'if cond is None:'
* comparison to None should be 'if cond is not None:'
* test for membership should be 'not in'
* do not use bare 'except'
* local variable shift is assigned to but never used
* comparison to False/True should be 'if cond is False/True:'
* do not use bare 'except'
* local variable dt is assigned to but never used
* local variable season_key is assigned to but never used
* local variable e is assigned to but never used
* "self" is not defined
* XApp is needed
* unused variables are back, unwanted formatting
  • Loading branch information
brccabral committed Feb 6, 2023
1 parent 059cc04 commit 217b971
Show file tree
Hide file tree
Showing 4 changed files with 390 additions and 302 deletions.
53 changes: 31 additions & 22 deletions usr/lib/hypnotix/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,29 @@ def wrapper(*args, **kwargs):
thread.daemon = True
thread.start()
return thread

return wrapper


# Used as a decorator to run things in the main loop, from another thread
def idle_function(func):
def wrapper(*args):
GObject.idle_add(func, *args)

return wrapper


def slugify(string):
"""
Normalizes string, converts to lowercase, removes non-alpha characters,
and converts spaces to hyphens.
"""
return "".join(x.lower() for x in string if x.isalnum())

class Provider():

class Provider:
def __init__(self, name, provider_info):
if provider_info != None:
if provider_info is not None:
self.name, self.type_id, self.url, self.username, self.password, self.epg = provider_info.split(":::")
else:
self.name = name
Expand All @@ -56,7 +61,8 @@ def __init__(self, name, provider_info):
def get_info(self):
return "%s:::%s:::%s:::%s:::%s:::%s" % (self.name, self.type_id, self.url, self.username, self.password, self.epg)

class Group():

class Group:
def __init__(self, name):
if "VOD" in name.split():
self.group_type = MOVIES_GROUP
Expand All @@ -68,20 +74,23 @@ def __init__(self, name):
self.channels = []
self.series = []

class Serie():

class Serie:
def __init__(self, name):
self.name = name
self.logo = None
self.logo_path = None
self.seasons = {}
self.episodes = []

class Season():

class Season:
def __init__(self, name):
self.name = name
self.episodes = {}

class Channel():

class Channel:
def __init__(self, provider, info):
self.info = info
self.id = None
Expand All @@ -92,7 +101,7 @@ def __init__(self, provider, info):
self.title = None
self.url = None
match = EXTINF.fullmatch(info)
if match != None:
if match is not None:
res = match.groupdict()
if 'params' in res:
params = dict(PARAMS.findall(res['params']))
Expand All @@ -104,9 +113,9 @@ def __init__(self, provider, info):
self.group_title = params['group-title'].strip().replace(";", " ").replace(" ", " ")
if 'title' in res:
self.title = res['title']
if self.name == None and "," in info:
if self.name is None and "," in info:
self.name = info.split(",")[-1].strip()
if self.logo != None:
if self.logo is not None:
if self.logo.startswith("file:https://"):
self.logo_path = self.logo[7:]
else:
Expand All @@ -119,8 +128,8 @@ def __init__(self, provider, info):
ext = ".jpg"
self.logo_path = os.path.join(PROVIDERS_PATH, "%s-%s%s" % (slugify(provider.name), slugify(self.name), ext))

class Manager():

class Manager:
def __init__(self, settings):
os.system("mkdir -p '%s'" % PROVIDERS_PATH)
self.verbose = False
Expand Down Expand Up @@ -166,12 +175,12 @@ def get_playlist(self, provider, refresh=False) -> bool:
# Get total playlist byte size
total_content_size = int(response.headers.get('content-length', 15))
# Set stream blocks
block_bytes = int(4*1024*1024) # 4 MB
block_bytes = int(4 * 1024 * 1024) # 4 MB

response.encoding = response.apparent_encoding
#try:
# try:
# source = response.content.decode("UTF-8")
#except UnicodeDecodeError as e:
# except UnicodeDecodeError as e:
# source = response.content.decode("latin1")
with open(provider.path, "w") as file:
# Grab data by block_bytes
Expand Down Expand Up @@ -201,7 +210,7 @@ def check_playlist(self, provider):
if os.path.exists(provider.path):
with open(provider.path, "r") as file:
content = file.read()
if ("#EXTM3U" in content and "#EXTINF" in content):
if "#EXTM3U" in content and "#EXTINF" in content:
legit = True
self.debug("Content looks legit: %s" % provider.name)
else:
Expand All @@ -224,29 +233,29 @@ def load_channels(self, provider):
continue
if ":https://" in line and not (line.startswith("#")):
self.debug(" ", line)
if channel == None:
if channel is None:
self.debug(" --> channel is None")
continue
if channel.url != None:
if channel.url is not None:
# We already found the URL, skip the line
self.debug(" --> channel URL was already found")
continue
if channel.name == None or "***" in channel.name:
if channel.name is None or "***" in channel.name:
self.debug(" --> channel name is None")
continue
channel.url = line
self.debug(" --> URL found: ", line)

serie = None
f = SERIES.fullmatch(channel.name)
if f != None:
if f is not None:
res = f.groupdict()
series_name = res['series']
if series_name in series.keys():
serie = series[series_name]
else:
serie = Serie(series_name)
#todo put in group
# todo put in group
provider.series.append(serie)
series[series_name] = serie
serie.logo = channel.logo
Expand All @@ -262,15 +271,15 @@ def load_channels(self, provider):
season.episodes[episode_name] = channel
serie.episodes.append(channel)

if channel.group_title != None and channel.group_title.strip() != "":
if group == None or group.name != channel.group_title:
if channel.group_title is not None and channel.group_title.strip() != "":
if group is None or group.name != channel.group_title:
if channel.group_title in groups.keys():
group = groups[channel.group_title]
else:
group = Group(channel.group_title)
provider.groups.append(group)
groups[channel.group_title] = group
if serie != None and serie not in group.series:
if serie is not None and serie not in group.series:
group.series.append(serie)
group.channels.append(channel)
if group.group_type == TV_GROUP:
Expand Down
Loading

0 comments on commit 217b971

Please sign in to comment.