From e2bce96d76ec37a5140b73739106c7ba78fb1e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Ole=20Hu=CC=88bner?= Date: Sun, 13 Apr 2025 02:02:11 +0200 Subject: [PATCH] feature(zsh_functions): instagram downloader --- .zsh_functions/insta.zsh | 68 ++++++++++++++++++++++++++++++++++++++++ .zshrc | 1 + 2 files changed, 69 insertions(+) create mode 100644 .zsh_functions/insta.zsh diff --git a/.zsh_functions/insta.zsh b/.zsh_functions/insta.zsh new file mode 100644 index 0000000..4eaa6a4 --- /dev/null +++ b/.zsh_functions/insta.zsh @@ -0,0 +1,68 @@ +function insta() { + local cwd=$(pwd) + + check_smb_mount() { + /sbin/mount | grep -q "$insta_mount_point" + } + + local stories_only=false + local user_list=() + + # Parse arguments + while [[ $# -gt 0 ]]; do + case "$1" in + --cron) + local random_wait=$((RANDOM % 1800)) + echo "--------------------------------------------" + echo "Waiting for $((random_wait / 60)) minutes..." + sleep $random_wait + stories_only=true + ;; + --stories) + stories_only=true + ;; + *) + user_list+=("$1") + ;; + esac + shift + done + + if [ ! -d "$insta_mount_point" ]; then + echo "Creating mount point directory..." + mkdir -p "$insta_mount_point" + fi + + if ! check_smb_mount; then + echo "Mounting SMB share..." + /sbin/mount_smbfs "smb://janolehuebner:$(pass sudo-lana)@$insta_share_on_nas" "$insta_mount_point" + fi + + if ! check_smb_mount; then + echo "Failed to mount SMB share. Exiting." + return 1 + fi + + cd "$insta_mount_point/$insta_path_on_nas" || return 1 + + # Use default users if no user was specified + if [[ ${#user_list[@]} -eq 0 ]]; then + user_list=("${insta_default_users[@]}") + fi + + # Build the instaloader command + local cmd=(uvx --with browser_cookie3 instaloader -b Safari -B "$insta_cookiefile" "${user_list[@]}" --fast-update) + + if $stories_only; then + cmd+=(--stories --no-profile-pic --no-posts) + else + cmd+=(--stories --reels) + fi + + "${cmd[@]}" + + echo "Unmounting SMB share..." + sleep 3 + /sbin/umount -f "$insta_mount_point" + cd "$cwd" +} diff --git a/.zshrc b/.zshrc index e3eb137..c7b3f52 100755 --- a/.zshrc +++ b/.zshrc @@ -25,6 +25,7 @@ done unset file unsetopt allexport +autosource insta autosource youtube autosource milan autosource nas