From 752d47948eed459c2ccf2f6a5181d799b5e5490f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Thu, 11 Jul 2024 18:32:35 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(bin):=20add=20a=20new=20servic?= =?UTF-8?q?e=20and=20bin:=20downloadMedia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit using gallery-dl to download images and videos from some websites --- .config/systemd/user/downloadMedia.service | 10 +++ .config/systemd/user/downloadMedia.timer | 10 +++ .local/bin/downloadMedia | 87 ++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 .config/systemd/user/downloadMedia.service create mode 100644 .config/systemd/user/downloadMedia.timer create mode 100755 .local/bin/downloadMedia diff --git a/.config/systemd/user/downloadMedia.service b/.config/systemd/user/downloadMedia.service new file mode 100644 index 00000000..e3eb2312 --- /dev/null +++ b/.config/systemd/user/downloadMedia.service @@ -0,0 +1,10 @@ +[Unit] +Description=Download Media +After=network.target + +[Service] +Type=simple +ExecStart=/home/matt/.local/bin/downloadMedia + +[Install] +WantedBy=default.target diff --git a/.config/systemd/user/downloadMedia.timer b/.config/systemd/user/downloadMedia.timer new file mode 100644 index 00000000..d6647e1c --- /dev/null +++ b/.config/systemd/user/downloadMedia.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Run Media Downloader Daily + +[Timer] +OnCalendar=*-*-* 17:00:00 +Persistent=true +Unit=downloadMedia.service + +[Install] +WantedBy=timers.target diff --git a/.local/bin/downloadMedia b/.local/bin/downloadMedia new file mode 100755 index 00000000..8441fb7a --- /dev/null +++ b/.local/bin/downloadMedia @@ -0,0 +1,87 @@ +#!/bin/bash + +image_folder="$HOME/Images/" +video_folder="$HOME/Videos/" + +# Utils +notify() { + notify-send "Media Download" "$1" -i ~/.local/share/icons/Catppuccin-SE/64x64/mimetypes/application-x-partial-download.svg --app-name=gallery-dl +} + +notify_error() { + notify-send "Media Download" "$1" -u=critical -i ~/.local/share/icons/Catppuccin-SE/64x64/mimetypes/application-x-partial-download.svg --app-name=gallery-dl +} + +download_images() { + gallery-dl -d "$image_folder" --download-archive "$image_folder/{$1}/archive.sqlite3" "$2" --filter "$3" +} + +download_videos() { + gallery-dl -d "$video_folder" --download-archive "$video_folder/{$1}/archive.sqlite3" "$2" --filter "$3" +} + +# Download Sites +download_pinterest() { + download_images "pinterest" "$1" "extension not in ('mp4', 'gif')" + download_videos "pinterest" "$1" "extension in ('mp4', 'gif')" + notify "Pinterest ($1) Complete" +} + +download_pixiv() { + download_images "pixiv" "$1" "extension not in ('mp4', 'gif')" + notify "Pixiv ($1) Complete" +} + +download_twitter() { + download_images "twitter" "$1" "extension not in ('mp4', 'gif')" + download_videos "twitter" "$1" "extension in ('mp4', 'gif')" + notify "Twitter ($1) Complete" +} + +download_reddit() { + download_images "reddit" "$1" "extension not in ('mp4')" + download_videos "reddit" "$1" "extension in ('mp4')" + notify "Reddit ($1) Complete" +} + +download_unknown_site() { + download_images "$1" "extension not in ('mp4', 'gif')" + download_videos "$1" "extension in ('mp4', 'gif')" + notify "$1 Complete" +} + +if ! command -v gallery-dl &>/dev/null; then + notify_error "gallery-dl is not installed" + exit 1 +fi + +url_file="$HOME/.config/gallery-dl/urls.txt" + +if [ ! -f "$url_file" ]; then + notify_error "URl file does not exist" + exit 1 +fi + +notify "Started Download..." + +while IFS= read -r url; do + case "$url" in + *pinterest.com*) + download_pinterest "$url" + ;; + *pixiv.net*) + download_pixiv "$url" + ;; + *x.com*) + download_twitter "$url" + ;; + *reddit.com*) + download_reddit "$url" + ;; + *) + download_unknown_site "$url" + ;; + esac +done <"$url_file" + +notify "Media Download Complete"