Skip to content

Commit

Permalink
feat: Better yt-dlp plugin management
Browse files Browse the repository at this point in the history
  • Loading branch information
nlogozzo committed Jan 28, 2025
1 parent 22e93d1 commit ad6b557
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 74 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Ensure both `vcpkg` and `cmake` are installed on your system before building.

A C++20 compiler is also required to build Parabolic.

**If building the GNOME version, `blueprint-compiler` must be installed from your system package manager as it is not available on `vcpkg`.**

### Configuring vcpkg
1. Set the `VCPKG_ROOT` environment variable to the path of your vcpkg installation's root directory.
#### Windows
Expand Down
2 changes: 1 addition & 1 deletion docs/po/parabolic.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2025-01-28 09:34-0500\n"
"POT-Creation-Date: 2025-01-28 10:18-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion inno/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{
[Files]
Source: "vc_redist.x64.exe"; DestDir: "{app}\deps"; AfterInstall: SetupVC
Source: "yt-dlp.exe"; DestDir: "{app}\Release"; Flags: ignoreversion
Source: "..\resources\chrome_cookies_unlock.py"; DestDir: "{app}\Release\yt-dlp-plugins\yt-dlp-ChromeCookieUnlock\yt_dlp_plugins\postprocessor"; Flags: ignoreversion
Source: "..\resources\yt-dlp-plugins\*"; DestDir: "{app}\Release\yt-dlp-plugins\"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "ffmpeg.exe"; DestDir: "{app}\Release"; Flags: ignoreversion
Source: "ffplay.exe"; DestDir: "{app}\Release"; Flags: ignoreversion
Source: "ffprobe.exe"; DestDir: "{app}\Release"; Flags: ignoreversion
Expand Down
3 changes: 2 additions & 1 deletion org.nickvision.tubeconverter.gnome/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if(NOT WIN32)
if(BLUEPRINT_COMPILER_EXECUTABLE)
add_custom_command(TARGET gnome_commands PRE_BUILD COMMAND "${BLUEPRINT_COMPILER_EXECUTABLE}" batch-compile "${CMAKE_CURRENT_BINARY_DIR}/ui" "${CMAKE_CURRENT_SOURCE_DIR}/blueprints" "${CMAKE_CURRENT_SOURCE_DIR}/blueprints/*.blp")
else()
message(ERROR "blueprint-compiler not found, UI will not be compiled")
message(FATAL_ERROR "blueprint-compiler not found, UI will not be compiled")
endif()

if(HAS_GETTEXT)
Expand All @@ -52,6 +52,7 @@ if(NOT WIN32)
configure_file("${CMAKE_SOURCE_DIR}/resources/linux/${PROJECT_NAME}.metainfo.xml.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.metainfo.xml" @ONLY)
configure_file("${CMAKE_SOURCE_DIR}/resources/linux/${PROJECT_NAME}.service.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.service" @ONLY)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
install(DIRECTORY "${CMAKE_SOURCE_DIR}/resources/yt-dlp-plugins/" DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/yt-dlp-plugins" FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.desktop" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
Expand Down
3 changes: 2 additions & 1 deletion org.nickvision.tubeconverter.qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ if(LINUX)
configure_file("${CMAKE_SOURCE_DIR}/resources/linux/${PROJECT_NAME}.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" @ONLY)
configure_file("${CMAKE_SOURCE_DIR}/resources/linux/${PROJECT_NAME}.metainfo.xml.in" "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.metainfo.xml" @ONLY)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/" DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
install(DIRECTORY "${CMAKE_SOURCE_DIR}/resources/yt-dlp-plugins/" DESTINATION "${CMAKE_INSTALL_FULL_SYSCONFDIR}/yt-dlp-plugins" FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_NAME}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}" PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.desktop" DESTINATION "${CMAKE_INSTALL_DATADIR}/applications")
Expand All @@ -93,4 +94,4 @@ if(LINUX)
else()
message(WARNING "update-desktop-database not found, desktop database will not be updated")
endif()
endif()
endif()
69 changes: 0 additions & 69 deletions resources/chrome_cookies_unlock.py

This file was deleted.

2 changes: 1 addition & 1 deletion resources/po/parabolic.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-28 09:34-0500\n"
"POT-Creation-Date: 2025-01-28 10:18-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
7 changes: 7 additions & 0 deletions resources/yt-dlp-plugins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# yt-dlp-plugins

Adapted from:

- https://github.com/seproDev/yt-dlp-ChromeCookieUnlock
- https://github.com/coletdjnz/yt-dlp-get-pot
- https://github.com/Brainicism/bgutil-ytdlp-pot-provider
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import os
import sys
import yt_dlp.cookies

if os.name == 'nt':
original_func = yt_dlp.cookies._open_database_copy

def unlock_chrome(database_path, tmpdir):
try:
return original_func(database_path, tmpdir)
except PermissionError:
unlock_cookies(database_path)
return original_func(database_path, tmpdir)

yt_dlp.cookies._open_database_copy = unlock_chrome


# Adapted from https://gist.github.com/csm10495/e89e660ffee0030e8ef410b793ad6a7e
# By Charles Machalow under the MIT License

from ctypes import windll, byref, create_unicode_buffer, pointer, WINFUNCTYPE
from ctypes.wintypes import DWORD, WCHAR, UINT

ERROR_SUCCESS = 0
ERROR_MORE_DATA = 234
RmForceShutdown = 1

@WINFUNCTYPE(None, UINT)
def callback(percent_complete: UINT) -> None:
pass

rstrtmgr = windll.LoadLibrary("Rstrtmgr")

def unlock_cookies(cookies_path):
session_handle = DWORD(0)
session_flags = DWORD(0)
session_key = (WCHAR * 256)()

result = DWORD(rstrtmgr.RmStartSession(byref(session_handle), session_flags, session_key)).value

if result != ERROR_SUCCESS:
raise RuntimeError(f"RmStartSession returned non-zero result: {result}")

try:
result = DWORD(rstrtmgr.RmRegisterResources(session_handle, 1, byref(pointer(create_unicode_buffer(cookies_path))), 0, None, 0, None)).value

if result != ERROR_SUCCESS:
raise RuntimeError(f"RmRegisterResources returned non-zero result: {result}")

proc_info_needed = DWORD(0)
proc_info = DWORD(0)
reboot_reasons = DWORD(0)

result = DWORD(rstrtmgr.RmGetList(session_handle, byref(proc_info_needed), byref(proc_info), None, byref(reboot_reasons))).value

if result not in (ERROR_SUCCESS, ERROR_MORE_DATA):
raise RuntimeError(f"RmGetList returned non-successful result: {result}")

if proc_info_needed.value:
result = DWORD(rstrtmgr.RmShutdown(session_handle, RmForceShutdown, callback)).value

if result != ERROR_SUCCESS:
raise RuntimeError(f"RmShutdown returned non-successful result: {result}")
finally:
result = DWORD(rstrtmgr.RmEndSession(session_handle)).value

if result != ERROR_SUCCESS:
raise RuntimeError(f"RmEndSession returned non-successful result: {result}")

0 comments on commit ad6b557

Please sign in to comment.