Skip to content
3 changes: 3 additions & 0 deletions usr/lib/hypnotix/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
self.series = []


class Serie:

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

View workflow job for this annotation

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

Serie ==> Series
def __init__(self, name):
self.name = name
self.logo = None
Expand All @@ -98,11 +98,14 @@
self.group_title = None
self.title = None
self.url = None
self.lcn = 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-lcn" in params and params['tvg-lcn'].strip() != "":
self.lcn = params['tvg-lcn'].strip()
if "tvg-name" in params and params['tvg-name'].strip() != "":
self.name = params['tvg-name'].strip()
if "tvg-logo" in params and params['tvg-logo'].strip() != "":
Expand Down Expand Up @@ -196,7 +199,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 202 in usr/lib/hypnotix/common.py

View workflow job for this annotation

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

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

serie = None

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

View workflow job for this annotation

GitHub Actions / build / build (mint22, linuxmintd/mint22-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 262 in usr/lib/hypnotix/common.py

View workflow job for this annotation

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

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

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

View workflow job for this annotation

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

Serie ==> Series

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

View workflow job for this annotation

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

serie ==> series
# todo put in group
provider.series.append(serie)
series[series_name] = serie
Expand Down
99 changes: 89 additions & 10 deletions usr/lib/hypnotix/hypnotix.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,15 @@ def show_channels(self, channels, favorites=False):
self.download_channel_logos(logos_to_refresh)
else:
self.sidebar.hide()

self.update_hchannels()
self.chan_lcn_buf = 0
self.timeoutID = 0
try:
self.active_channel = self.hchannels[0].channel
except:
pass
self.prev_channel = None

def show_vod(self, items):
logos_to_refresh = []
Expand Down Expand Up @@ -713,6 +722,9 @@ def on_search_bar(self, widget):
self.latest_search_bar_text = search_bar_text
self.search_bar.set_sensitive(False)
GLib.timeout_add_seconds(0.1, self.on_search)

def update_hchannels(self):
self.hchannels = [c for c in self.channels_listbox.get_children() if unidecode(self.search_bar.get_text()).lower() in c.channel.name.lower()]

def on_search(self):
self.visible_search_results = 0
Expand All @@ -728,6 +740,7 @@ def on_search(self):
self.search_bar.set_sensitive(True)
self.search_bar.grab_focus_without_selecting()
self.navigate_to("channels_page")
self.update_hchannels()

def init_channels_listbox(self):
self.latest_search_bar_text = None
Expand Down Expand Up @@ -859,18 +872,29 @@ def on_favorite_button_toggled(self, widget):
self.manager.save_favorites(self.favorite_data)

def on_channel_activated(self, box, widget):
self.prev_channel = self.active_channel
self.active_channel = widget.channel
self.play_async(self.active_channel)

def on_prev_channel(self):
if self.stack.get_visible_child_name() == "channels_page":
self.channels_listbox.do_move_cursor(self.channels_listbox, Gtk.MovementStep.DISPLAY_LINES, -1)
self.channels_listbox.do_activate_cursor_row(self.channels_listbox)
idx = self.channels_listbox_selected_index()
step = -1 if idx != 0 else (len(self.hchannels) - 1)
self.channels_listbox_activate_row(step)

def on_next_channel(self):
if self.stack.get_visible_child_name() == "channels_page":
self.channels_listbox.do_move_cursor(self.channels_listbox, Gtk.MovementStep.DISPLAY_LINES, 1)
self.channels_listbox.do_activate_cursor_row(self.channels_listbox)
idx = self.channels_listbox_selected_index()
step = 1 if idx != (len(self.hchannels) - 1) else (1 - len(self.hchannels))
self.channels_listbox_activate_row(step)

def channels_listbox_selected_index(self):
channel = [c for c in self.hchannels if c.channel.name == self.active_channel.name][0]
return self.hchannels.index(channel)

def channels_listbox_activate_row(self, step):
self.channels_listbox.do_move_cursor(self.channels_listbox, Gtk.MovementStep.DISPLAY_LINES, step)
self.channels_listbox.do_activate_cursor_row(self.channels_listbox)

@async_function
def play_async(self, channel):
Expand Down Expand Up @@ -1452,6 +1476,11 @@ def on_menu_quit(self, widget):
def on_key_press_event(self, widget, event):
if isinstance(widget.get_focus(), Gtk.Entry):
return False
try:
widgetType = widget.get_focus().get_name()
except: # we can pretend the channel widget is focused
widgetType = "ChannelWidget"
channel_focused = self.fullscreen or "ChannelWidget" in widgetType
# Get any active, but not pressed modifiers, like CapsLock and NumLock
persistant_modifiers = Gtk.accelerator_get_default_mod_mask()

Expand All @@ -1460,6 +1489,11 @@ def on_key_press_event(self, widget, event):
# Bool of Control or Shift modifier states
ctrl = modifier == Gdk.ModifierType.CONTROL_MASK
shift = modifier == Gdk.ModifierType.SHIFT_MASK

def activate_hchannel(chan):
idx = self.channels_listbox_selected_index()
step = self.hchannels.index(chan) - idx
self.channels_listbox_activate_row(step)

if ctrl and event.keyval == Gdk.KEY_r:
self.reload(page=None, refresh=True)
Expand All @@ -1486,12 +1520,57 @@ def on_key_press_event(self, widget, event):
elif event.keyval == Gdk.KEY_Down:
self.on_next_channel()
return True
elif not event.keyval in [Gdk.KEY_F1, Gdk.KEY_F2]:
try:
self.mpv.command("keypress", Gdk.keyval_name(event.keyval))
except:
pass
return True
elif event.keyval == Gdk.KEY_Home:
if channel_focused:
chan = [c for c in self.hchannels if c.channel == self.prev_channel][0]
activate_hchannel(chan)
return True
elif event.keyval == Gdk.KEY_Return:
if channel_focused:
try:
chan = [c for c in self.hchannels if c.channel.lcn == str(self.chan_lcn_buf)]

"""

If this branch will be merged with "epg", it's very easy to jump across channels using
their EPG numbers (without needing a lcn tag) just by adding the lines here below:


if (len(chan) == 0 and self.epg is not None):
epg_channel = [p.attrib["id"] for p in self.epg.findall("channel") if p.attrib["id"].split()[-1] == str(self.chan_lcn_buf)][0]
chan = [c for c in self.hchannels if chan_match(c.channel.name, epg_channel)]

"""

activate_hchannel(chan[0])
finally:
self.chan_lcn_buf = 0
return True
else:
self.chan_lcn_buf = 0
else:
if channel_focused and not event.keyval in [Gdk.KEY_F1, Gdk.KEY_F2]:
try:
self.chan_lcn_buf = self.chan_lcn_buf * 10 + int(chr(event.keyval))
timeout = 1500
self.mpv.command("show-text", str(self.chan_lcn_buf) + "-", timeout)

def reset_chan_lcn_buf():
self.chan_lcn_buf = 0
return False

if (self.timeoutID != 0):
GLib.source_remove(self.timeoutID)
self.timeoutID = 0

self.timeoutID = GLib.timeout_add(timeout, reset_chan_lcn_buf)
except:
self.chan_lcn_buf = 0
try:
self.mpv.command("keypress", Gdk.keyval_name(event.keyval))
except:
pass
return True
# elif event.keyval == Gdk.KEY_Up:
# # Up of in the list
# pass
Expand Down
Loading