-
-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Better
yt-dlp
plugin management
- Loading branch information
Showing
9 changed files
with
84 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
68 changes: 68 additions & 0 deletions
68
...p-plugins/yt-dlp-ChromeCookieUnlock/yt_dlp_plugins/postprocessor/chrome_cookies_unlock.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |