Skip to content
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

Add automatic yt-dlp update check #1

Merged
merged 6 commits into from
Aug 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Date: 2024-07-28

import sys, os, re
from datetime import datetime, timedelta

parent_folder_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(parent_folder_path)
Expand All @@ -13,6 +14,9 @@
from flowlauncher import FlowLauncher
from yt_dlp import YoutubeDL

DOWNLOAD_PATH = os.path.join(parent_folder_path, "yt-dlp.exe")
CHECK_INTERVAL_DAYS = 10


# Custom YoutubeDL class to exception handling
class CustomYoutubeDL(YoutubeDL):
Expand Down Expand Up @@ -125,7 +129,13 @@ def query(self, query):
return output

def download(self, url, format_id):
command = f"yt-dlp -f {format_id}+ba {url} -P ~/Downloads/AnyDownloader --windows-filenames --quiet --progress --no-mtime --force-overwrites --no-part"
# Check if yt-dlp.exe needs to be updated
last_modified_time = datetime.fromtimestamp(os.path.getmtime(DOWNLOAD_PATH))
if datetime.now() - last_modified_time >= timedelta(days=CHECK_INTERVAL_DAYS):
command = f"yt-dlp -f {format_id}+ba {url} -P ~/Downloads/AnyDownloader -U --windows-filenames --quiet --progress --no-mtime --force-overwrites --no-part"
else:
command = f"yt-dlp -f {format_id}+ba {url} -P ~/Downloads/AnyDownloader --windows-filenames --quiet --progress --no-mtime --force-overwrites --no-part"

os.system(command)


Expand Down