Skip to content

Commit

Permalink
fix yt link double check on edit (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
DYefremov committed Mar 25, 2023
1 parent b8cac72 commit a32bf23
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/ui/iptv.glade
Expand Up @@ -1082,6 +1082,7 @@ Author: Dmitriy Yefremov
<property name="primary_icon_name">document-edit-symbolic</property>
<property name="secondary_icon_tooltip_text" translatable="yes">Link to YouTube resource.</property>
<signal name="changed" handler="on_url_changed" swapped="no"/>
<signal name="paste_clipboard" handler="on_url_paste" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
Expand Down
13 changes: 9 additions & 4 deletions app/ui/iptv.py
Expand Up @@ -81,6 +81,7 @@ def __init__(self, app, view, bouquet=None, service=None, action=Action.ADD):
handlers = {"on_response": self.on_response,
"on_entry_changed": self.on_entry_changed,
"on_url_changed": self.on_url_changed,
"on_url_paste": self.on_url_paste,
"on_save": self.on_save,
"on_stream_type_changed": self.on_stream_type_changed,
"on_yt_quality_changed": self.on_yt_quality_changed,
Expand All @@ -93,6 +94,7 @@ def __init__(self, app, view, bouquet=None, service=None, action=Action.ADD):
self._bouquet = bouquet
self._yt_links = None
self._yt_dl = None
self._inserted_url = False

builder = get_builder(_UI_PATH, handlers, use_str=True,
objects=("iptv_dialog", "stream_type_liststore", "yt_quality_liststore"))
Expand All @@ -117,7 +119,7 @@ def __init__(self, app, view, bouquet=None, service=None, action=Action.ADD):
self._message_label = builder.get_object("info_bar_message_label")
self._yt_quality_box = builder.get_object("yt_iptv_quality_combobox")
self._model, self._paths = view.get_selection().get_selected_rows()
# style
# Style.
self._style_provider = Gtk.CssProvider()
self._style_provider.load_from_path(UI_RESOURCES_PATH + "style.css")
self._digit_elems = (self._srv_id_entry, self._srv_type_entry, self._sid_entry, self._tr_id_entry,
Expand Down Expand Up @@ -194,7 +196,7 @@ def init_enigma2_data(self, fav_id):
elif stream_type is StreamType.E_SERVICE_HLS:
self._stream_type_combobox.set_active(5)
except ValueError:
self.show_info_message("Unknown stream type {}".format(s_type), Gtk.MessageType.ERROR)
self.show_info_message(f"Unknown stream type {s_type}", Gtk.MessageType.ERROR)

self._srv_id_entry.set_text(data[1])
self._srv_type_entry.set_text(str(int(data[2], 16)))
Expand All @@ -212,7 +214,6 @@ def init_neutrino_data(self, fav_id):

def update_reference_entry(self):
if self._s_type is SettingsType.ENIGMA_2 and is_data_correct(self._digit_elems):
self.on_url_changed(self._url_entry)
self._reference_entry.set_text(_ENIGMA2_REFERENCE.format(self.get_type(),
self._srv_id_entry.get_text(),
int(self._srv_type_entry.get_text()),
Expand Down Expand Up @@ -242,16 +243,20 @@ def on_url_changed(self, entry):
if yt_id:
entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, get_yt_icon("youtube", 32))
text = "Found a link to the YouTube resource!\nTry to get a direct link to the video?"
if show_dialog(DialogType.QUESTION, self._dialog, text=text) == Gtk.ResponseType.OK:
if self._inserted_url and show_dialog(DialogType.QUESTION, self._dialog, text=text) == Gtk.ResponseType.OK:
entry.set_sensitive(False)
gen = self.set_yt_url(entry, yt_id)
GLib.idle_add(lambda: next(gen, False), priority=GLib.PRIORITY_LOW)
self._inserted_url = False
elif YouTube.is_yt_video_link(url_str):
entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.SECONDARY, get_yt_icon("youtube", 32))
else:
entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY, None)
self._yt_quality_box.set_visible(False)

def on_url_paste(self, entry):
self._inserted_url = True

def set_yt_url(self, entry, video_id):
try:
if not self._yt_dl:
Expand Down

0 comments on commit a32bf23

Please sign in to comment.