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 2 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
20 changes: 20 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@
from flowlauncher import FlowLauncher
from yt_dlp import YoutubeDL

from datetime import datetime, timedelta
CHECK_INTERVAL_DAYS = 3
LAST_DOWNLOAD_FILE = os.path.join(parent_folder_path, "last_download.txt")

def download_yt_dlp():
os.system("yt-dlp --update")


def check_and_download_yt_dlp():
if os.path.exists(LAST_DOWNLOAD_FILE):
with open(LAST_DOWNLOAD_FILE, "r") as file:
last_download_date = datetime.strptime(file.read().strip(), "%Y-%m-%d")
if datetime.now() - last_download_date < timedelta(days=CHECK_INTERVAL_DAYS):
return

download_yt_dlp()
with open(LAST_DOWNLOAD_FILE, "w") as file:
file.write(datetime.now().strftime("%Y-%m-%d"))


# Custom YoutubeDL class to exception handling
class CustomYoutubeDL(YoutubeDL):
Expand Down Expand Up @@ -130,4 +149,5 @@ def download(self, url, format_id):


if __name__ == "__main__":
check_and_download_yt_dlp()
AnyVideo()