#!/bin/bash # TODO, warning! This script is horrible and insecure with background jobs show_help() { # echo "Usage: `basename $0` [--no-abort-on-found] [--parallel] [--custom-grep-search|-c ]" echo "Usage: $(basename $0) [--custom-grep-search|-c ]" echo "Options:" echo " --no-abort-on-found (optional) The script will not update each gallery download until it finds an already downloaded file." echo " --no-parallel (optional) The script will update the found URLs in sequence" echo " --custom-grep-search|-c (optional) Includes a string to filter the URLs." } should_abort_on_found=true parallel=true should_use_tmux=true custom_grep_search='' while [ "$#" -gt 0 ]; do case "$1" in --help | -h) show_help exit ;; --no-abort-on-found) should_abort_on_found=false shift ;; --no-parallel | -n) parallel=false shift ;; --custom-grep-search | -c) custom_grep_search="$2" shift 2 ;; *) shift ;; esac done gallery_dl_path=/mnt/e/home/documents/data-hoarding cd "$gallery_dl_path" todo_md_filepath='/mnt/e/home/clouds/google-drive/obsidian-vaults/notes/idk/furry/cool-artists.md' urls=($(grep -v "filter" -i "$todo_md_filepath" | grep -Eo "(mastodon:)?(http|https)://[a-zA-Z0-9.(/~@)?=_%:-]*")) if [ ! -z "$custom_grep_search" ]; then filtered_urls=() for url in "${urls[@]}"; do if [[ "$url" == *"$custom_grep_search"* ]]; then filtered_urls+=("$url") fi done urls=(${filtered_urls[@]}) # debug if false; then echo "Filtered URLs:" for url in ${filtered_urls[@]}; do echo " $url" done exit 0 fi fi # debug if false; then echo "URLs:" for url in ${urls[@]}; do echo " $url" done exit 0 fi gdl_command_base='gallery-dl' if $should_abort_on_found; then gdl_command_base+=' --abort 1' fi sleep 5 & commands_list=() for url in ${urls[@]}; do gdl_command="$gdl_command_base $url" # debug if false; then echo "Command:" echo " $gdl_command" fi if $should_use_tmux; then commands_list+=("$gdl_command") else eval $gdl_command fi done if ! $should_use_tmux; then exit 0 fi # debug if false; then commands_list=( "echo foo1" "echo foo2" "echo foo3" "echo foo4" "echo foo5" "echo foo6" "echo foo7" "echo foo8" "echo foo9" ) fi # debug if false; then echo "Commands:" for ((i = 0; i < ${#commands_list[@]}; i++)); do command_to_run="${commands_list[$i]}" echo " $command_to_run" done exit 0 fi if $should_use_tmux; then session_name="tmp_gdl-update-todo-$( uuidgen | sed 's/[-]//g' | head -c 10 echo )" tmux new-session -d -s $session_name current_window_num=0 current_panel_num=0 if $parallel; then for ((i = 0; i < ${#commands_list[@]}; i++)); do command_to_run="${commands_list[$i]}" if [ "$i" -eq 0 ] || [ $((i % 4)) -eq 0 ]; then if [ "$i" -ne 0 ]; then tmux new-window -t $session_name fi ((current_window_num++)) current_panel_num=1 tmux split-window -v -t $session_name tmux select-pane -t $session_name:$current_window_num.1 tmux split-window -h -t $session_name tmux select-pane -t $session_name:$current_window_num.3 tmux split-window -h -t $session_name fi tmux select-pane -t $session_name:$current_window_num.$current_panel_num tmux send-keys -t $session_name "$command_to_run" Enter ((current_panel_num++)) done else tmux send-keys -t $session_name 'for ((i = 0; i < ${#commands_list[@]}; i++)); do echo ${commands_list[$i]}; done' tmux send-keys -t $session_name 'for url in "${urls[@]}"; do echo $url; done' fi fi