diff options
| author | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-24 20:35:27 +0900 |
|---|---|---|
| committer | TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> | 2025-01-24 20:35:27 +0900 |
| commit | c80a54e42b52ce297f0f2f71af23c562832025c7 (patch) | |
| tree | dcce8bb977a770f473325d48f6f70b21d9818a40 /ar/.local/bin/cron/mediaup | |
init
Diffstat (limited to 'ar/.local/bin/cron/mediaup')
| -rwxr-xr-x | ar/.local/bin/cron/mediaup | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/ar/.local/bin/cron/mediaup b/ar/.local/bin/cron/mediaup new file mode 100755 index 0000000..85935a2 --- /dev/null +++ b/ar/.local/bin/cron/mediaup @@ -0,0 +1,34 @@ +#!/bin/sh + +timestamp_file="${HOME}/.cache/ytdlpupdate" +current_time=$(date +%s) + +# Create cache directory if it doesn't exist +mkdir -p "${HOME}/.cache" + +# Check if the timestamp file exists and is less than 24 hours old +if [ -f "$timestamp_file" ] && [ "$(cat "$timestamp_file")" -gt "$((current_time - 86400))" ]; then + exit 0 +fi + +# Check if pipx is available, install if not +if ! command -v pipx >/dev/null 2>&1; then + python3 -m pip install --user pipx || exit 1 + python3 -m pipx ensurepath || exit 1 + if [ -f "${ZDOTDIR:-${HOME}/.config/zsh}/.zshrc" ]; then + # shellcheck source=${ZDOTDIR:-${HOME}/.config/zsh}/.zshrc + . "${ZDOTDIR:-${HOME}/.config/zsh}/.zshrc" + elif [ -f "${HOME}/.zshrc" ]; then + # shellcheck source=${HOME}/.zshrc + . "${HOME}/.zshrc" + fi +fi + +# Check if yt-dlp is installed via pipx, install or upgrade it +if ! pipx list | grep -q yt-dlp; then + pipx install yt-dlp || exit 1 +else + pipx upgrade yt-dlp || exit 1 +fi + +echo "$current_time" >"$timestamp_file" |
