Skip to content

Commit

Permalink
yt-dlp: Add the ability to switch to a local version and update it
Browse files Browse the repository at this point in the history
  • Loading branch information
clefebvre committed Oct 11, 2023
1 parent 94820d2 commit 1ceccf0
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 1 deletion.
10 changes: 10 additions & 0 deletions usr/bin/hypnotix
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
#!/bin/sh

mkdir -p ~/.cache/hypnotix/yt-dlp
if [ $(gsettings get org.x.hypnotix use-local-ytdlp) = true ]
then
echo "Local version of yt-dlp selected."
export PATH="~/.cache/hypnotix/yt-dlp":${PATH}
else
echo "System version of yt-dlp selected."
fi

/usr/lib/hypnotix/hypnotix.py &
30 changes: 29 additions & 1 deletion usr/lib/hypnotix/hypnotix.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
import traceback
import warnings
import subprocess
from functools import partial
from pathlib import Path

Expand Down Expand Up @@ -246,6 +247,10 @@ def __init__(self, application):
"referer_entry",
"mpv_entry",
"mpv_link",
"ytdlp_local_switch",
"ytdlp_system_version_label",
"ytdlp_local_version_label",
"ytdlp_update_button",
"mpv_stack",
"spinner",
"info_window_close_button",
Expand Down Expand Up @@ -317,6 +322,14 @@ def __init__(self, application):
self.bind_setting_widget("http-referer", self.referer_entry)
self.bind_setting_widget("mpv-options", self.mpv_entry)

# ytdlp
self.ytdlp_local_switch.set_active(self.settings.get_boolean("use-local-ytdlp"))
self.ytdlp_local_switch.connect("notify::active", self.on_ytdlp_local_switch_activated)
self.ytdlp_system_version_label.set_text(subprocess.getoutput("/usr/bin/yt-dlp --version"))
if os.path.exists(os.path.expanduser("~/.cache/hypnotix/yt-dlp/yt-dlp")):
self.ytdlp_local_version_label.set_text(subprocess.getoutput("~/.cache/hypnotix/yt-dlp/yt-dlp --version"))
self.ytdlp_update_button.connect("clicked", self.update_ytdlp)

# Dark mode manager
# keep a reference to it (otherwise it gets randomly garbage collected)
self.dark_mode_manager = XApp.DarkModeManager.new(prefer_dark_mode=True)
Expand Down Expand Up @@ -606,11 +619,26 @@ def on_vod_series_button_clicked(self, widget, serie):

def bind_setting_widget(self, key, widget):
widget.set_text(self.settings.get_string(key))
widget.connect("changed", self.on_entry_changed, key)
widget.connect("changed", self.on_entry_changed, key)

def on_entry_changed(self, widget, key):
self.settings.set_string(key, widget.get_text())

def on_ytdlp_local_switch_activated(self, widget, data=None):
self.settings.set_boolean("use-local-ytdlp", widget.get_active())
if widget.get_active():
self.update_ytdlp()

def update_ytdlp(self, widget=None):
path = os.path.expanduser("~/.cache/hypnotix/yt-dlp")
os.chdir(path)
if os.path.exists("yt-dlp"):
subprocess.getoutput("./yt-dlp --update")
else:
subprocess.getoutput("wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp")
subprocess.getoutput("chmod a+rx ./yt-dlp")
self.ytdlp_local_version_label.set_text(subprocess.getoutput("~/.cache/hypnotix/yt-dlp/yt-dlp --version"))

@async_function
def download_channel_logos(self, logos_to_refresh):
headers = {
Expand Down
5 changes: 5 additions & 0 deletions usr/share/glib-2.0/schemas/org.x.hypnotix.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@
<summary>Format: name:::type:::url(or path):::username:::password:::epg</summary>
<description></description>
</key>
<key type="b" name="use-local-ytdlp">
<default>false</default>
<summary></summary>
<description></description>
</key>
</schema>
</schemalist>
170 changes: 170 additions & 0 deletions usr/share/hypnotix/hypnotix.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,176 @@
<property name="position">1</property>
</packing>
</child>
<child>
<!-- n-columns=4 n-rows=7 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">start</property>
<property name="margin-top">20</property>
<property name="margin-bottom">20</property>
<property name="row-spacing">12</property>
<property name="column-spacing">12</property>
<child>
<object class="GtkLabel" id="ytdlp_system_version_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="label" translatable="yes">System version:</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">If Youtube channels stop working you can switch to a local version of yt-dlp and update it using the button above.</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
<property name="width">4</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="valign">center</property>
<property name="label" translatable="yes">Local version:</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ytdlp_update_button">
<property name="label" translatable="yes">Update from github.com/yt-dlp</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">2</property>
<property name="width">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="ytdlp_local_version_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Restart Hypnotix for changes to take effect.</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
<property name="width">4</property>
</packing>
</child>
<child>
<object class="GtkSwitch" id="ytdlp_local_switch">
<property name="visible">True</property>
<property name="can-focus">True</property>
</object>
<packing>
<property name="left-attach">3</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Use local version</property>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="title" translatable="yes">Youtube</property>
<property name="icon-name">tv-symbolic</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
Expand Down

0 comments on commit 1ceccf0

Please sign in to comment.