-
Notifications
You must be signed in to change notification settings - Fork 3
[FEAT] Automatic update logic for yt-dlp pip package #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
9dfa15f
e4ddc42
14315ce
0805300
8c2ffa3
6f108b3
3b326e2
c222958
4b07d98
53e7657
8ec4fd9
4c0dc57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,8 +1,12 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import re | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import zipfile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from datetime import datetime, timedelta | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PLUGIN_ROOT = os.path.dirname(os.path.abspath(__file__)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| LIB_PATH = os.path.abspath(os.path.join(PLUGIN_ROOT, "..", "lib")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FFMPEG_SETUP_LOCK = os.path.join(PLUGIN_ROOT, "ffmpeg_setup.lock") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| URL_REGEX = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "((http|https)://)(www.)?" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -280,3 +284,74 @@ def extract_ffmpeg(): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return False, binaries_reason | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return True, None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def check_ytdlp_update_needed(check_interval_days=5): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Check if yt-dlp library update is needed based on the last update timestamp. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| check_interval_days (int): Number of days between update checks. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bool: True if update is needed, False otherwise. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Path to yt-dlp package in lib folder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| lib_ytdlp_path = os.path.join(LIB_PATH, "yt_dlp") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_marker = os.path.join(LIB_PATH, ".ytdlp_last_update") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # If yt-dlp doesn't exist in lib, update is needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not os.path.exists(lib_ytdlp_path): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Check the update marker file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if os.path.exists(update_marker): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| last_update = datetime.fromtimestamp(os.path.getmtime(update_marker)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if datetime.now() - last_update < timedelta(days=check_interval_days): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| except Exception: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
z1nc0r3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # If we can't read the marker, assume update is needed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
304
to
317
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # If yt-dlp doesn't exist in lib, update is needed | |
| if not os.path.exists(lib_ytdlp_path): | |
| return True | |
| # Check the update marker file | |
| if os.path.exists(update_marker): | |
| try: | |
| last_update = datetime.fromtimestamp(os.path.getmtime(update_marker)) | |
| if datetime.now() - last_update < timedelta(days=check_interval_days): | |
| return False | |
| except Exception: | |
| pass | |
| # Check the update marker file first | |
| if os.path.exists(update_marker): | |
| try: | |
| last_update = datetime.fromtimestamp(os.path.getmtime(update_marker)) | |
| # If the last update is within the allowed interval and the library exists, | |
| # no update is needed. | |
| if datetime.now() - last_update < timedelta(days=check_interval_days): | |
| if os.path.exists(lib_ytdlp_path): | |
| return False | |
| # If the marker is fresh but the library is missing, treat as needing update. | |
| except Exception: | |
| # Any issue reading/parsing the marker should fall through to requiring an update. | |
| pass | |
| # If there is no marker, or it's stale/invalid, or the library is missing, | |
| # trigger an update so we can refresh the bundled yt-dlp and create/update the marker. |
z1nc0r3 marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the lib folder is in sys.path (as seen in run.py), installing yt-dlp with --target to the lib folder can create version conflicts. Since sys.path has lib before the system site-packages, the updated version in lib will take precedence. However, if yt-dlp is already installed system-wide (as indicated by requirements.txt), you could end up with duplicate installations. Additionally, --target doesn't handle dependencies the same way as normal pip install, which could lead to missing or conflicting dependency versions. Consider using pip install --upgrade without --target to upgrade the system installation, or ensure the lib folder is the only source of yt-dlp packages.
Uh oh!
There was an error while loading. Please reload this page.