#!/bin/bash # set -e ### REQUIREMENTS # gallery-dl # yt-dlp # mloader (pip or AUR) file_browser="thunar" LINK="$1" DIRFLAG="$2" # 0 = do nothing, 1 = store location in dirlist, 2 = open dirlist, 3 = 2+1 TYPE="" # everything below this comment is horrible [[ "$LINK" == "2" ]] && DIRFLAG=2 && LINK="show_files" [[ ! "$DIRFLAG" =~ ^[0-3]$ ]] && DIRFLAG=3 [[ -z "$LINK" || -z "$DIRFLAG" ]] && echo "ERROR: NOT ENOUGH ARGUMENTS" && exit 1 declare -A TYPES=( ["weebcentral\.com"]="manga" ["mangadex\.org"]="manga" ["youtube\.com\/@.*\/videos"]="yt_playlist" ["youtube\.com\/playlist\?list"]="yt_playlist" ["youtube\.com"]="yt_clip" ["pixiv\.net"]="art" ["skeb\.jp"]="art" ["(danbooru\.)?donmai\.us"]="art" ["deviantart\.com"]="art" ["kemono\.su"]="art" ["twitter\.com"]="art" ["x\.com"]="art" ["bsky\.app"]="art" ["baraag\.net"]="art" ["nhentai\.net"]="ecchi" ["e.hentai\.org"]="ecchi" ) declare -A LOCATIONS=( ["show_files"]="show_files" ["manga"]="$HOME/Downloads/Read or Die" ["art"]="$HOME/Tempsktop/gallery-dl" ["yt_clip"]="$HOME/Downloads/yt-dlp" ["yt_playlist"]="$HOME/Downloads/yt-dlp" ["ecchi"]="$HOME/Tempsktop/gallery-dl") if [[ "$LINK" == "show_files" ]]; then TYPE="$LINK" else longest_match="" for expr in "${!TYPES[@]}"; do [[ $LINK =~ ^http(s)?\:\/\/(www\.)?${expr}.*$ && ${#expr} -gt ${#longest_match} ]] && longest_match="$expr" && TYPE="${TYPES[$longest_match]}" done fi [[ -z "$TYPE" ]] && echo "ERROR: LINK NOT PROPERLY PARSED" && exit 1 LOCATION="${LOCATIONS[$TYPE]}" echo "LINK : $LINK, TYPE: $TYPE, LOCATION: $LOCATION" case "$TYPE" in "manga") MANGA="$( gallery-dl `curl -Ls -o /dev/null -w %{url_effective} $LINK` --destination "$LOCATION" --ugoira-conv 2>&1 )" # echo $? # echo $MANGA if [[ $? -ne 0 ]]; then MANGA_URL="$( echo $MANGA | grep -o -E "https://mangaplus\.shueisha\.co\.jp/viewer/[0-9]+" )" echo $MANGA_URL [[ -n "$MANGA_URL" ]] && mloader --out "$LOCATION/mangaplus" --raw --chapter-title --chapter-subdir `curl -Ls -o /dev/null -w %{url_effective} $MANGA_URL` fi ;; "art") # gallery-dl `curl -Ls -o /dev/null -w %{url_effective} $LINK` --directory "$LOCATION" --ugoira-conv gallery-dl `curl -Ls -o /dev/null -w %{url_effective} $LINK` --directory "$LOCATION" --ugoira-conv -o extractor.twitter.tweet-endpoint=restid -o extractor.twitter.conversations=false ;; "yt_clip") yt-dlp `curl -Ls -o /dev/null -w %{url_effective} $LINK` --paths "$LOCATION" --no-playlist ;; "yt_playlist") title="$(yt-dlp `curl -Ls -o /dev/null -w %{url_effective} $LINK` --skip-download --flat-playlist --dump-single-json --no-warnings | jq -r .title)" mkdir -p ${LOCATION}/${title} || { echo "ERROR: FAILED TO CREATE PLAYLIST SUBFOLDER" ; exit -1 ; } yt-dlp `curl -Ls -o /dev/null -w %{url_effective} $LINK` --paths "${LOCATION}/${title}" -o "%(playlist_index)s. %(title)s.%(ext)s" ;; "ecchi") # gallery-dl `curl -Ls -o /dev/null -w %{url_effective} $LINK` --destination "$LOCATION" gallery-dl `curl -Ls -o /dev/null -w %{url_effective} $LINK` --destination "$LOCATION" -o extractor.twitter.tweet-endpoint=restid -o extractor.twitter.conversations=false for file in ${LOCATION}/nhentai/*/*webp; do newfile="${file//nhentai_*_0/}" ; newfile="${newfile%%webp}png" ; magick "$file" "$newfile" && rm -f "$file" ; done for file in ${LOCATION}/exhentai/*/*webp; do newfile="${file//[0-9][0-9][0-9][0-9][0-9][0-9][0-9]_*_*_/}" ; newfile="${newfile%%webp}png" ; magick "$file" "$newfile" && rm -f "$file" ; done ;; "show_files") ;; *) echo -n "ERROR: UNKNOWN TYPE" exit 1 ;; esac [[ "$DIRFLAG" -eq 0 ]] && exit [[ "$DIRFLAG" -eq 1 || "$DIRFLAG" -eq 3 ]] && echo "$LOCATION" >> "/tmp/dirlist.txt" if [[ "$DIRFLAG" -eq 2 || "$DIRFLAG" -eq 3 ]]; then dirs=$( cat "/tmp/dirlist.txt" | sort | uniq ) # "$file_browser" IFS=$'\n' for dir in $dirs; do "$file_browser" "$dir" # wid=( $( xdotool search --desktop $( xdotool get_desktop ) --class "$file_browser" ) ) # lastwid=${wid[*]: -1} # [[ -n "$lastwid" ]] && xdotool windowactivate --sync "$lastwid" key ctrl+t ctrl+l && xdotool type -delay 0 "$dir" && xdotool key Return || echo "ERROR: UNABLE TO OPEN FILE BROWSER" done unset IFS rm -f "/tmp/dirlist.txt" fi