Download all images from a gallery

Found an interesting gallery online or added some new images to FembotWiki? Post photo-manipulations, artwork, or other visual media here.
Post Reply
User avatar
Chemik
Posts: 191
Joined: Sat Mar 12, 2005 8:37 pm
Technosexuality: Built and Transformation
Identification: Human
Gender: Male
Contact:

Download all images from a gallery

Post by Chemik » Sun Jul 08, 2018 2:13 pm

Hi folks,

I just want to share a simple BASH script to download all images from a specific gallery, or at least get a list of full-size image URLs into a single file:

Code: Select all

#!/bin/bash

# get FembotWiki image URLs and optionally download the images

scr_name=$(basename "$0")

helpmsg () {
	cat <<-EOF
		$scr_name [-h] [-u gallery URL] [-d image dir] [-s]

		save image URLs and optionally download the images from a wiki URL
		if image dir exists and contains the images, already downloaded ones are skipped

		-h	print this help
		-u	gallery URL
		-d	a dir to save links and images
		-s	download the images
	EOF
	exit 0
}

(($# == 0)) && helpmsg

while getopts ":hu:d:s" opt; do
	case "$opt" in
		h) helpmsg; exit 0 ;;
		u) gallery_url=$OPTARG ;;
		d) image_dir=$OPTARG ;;
		s) download_images=yes ;;
		\?) echo "invalid option: -$OPTARG"; exit 1 ;;
		:) echo "-$OPTARG needs an argument"; exit 1 ;;
	esac
done

[[ -z $gallery_url ]] && { echo "no gallery URL given"; exit 1; }

base_url=${gallery_url##http*://}
base_url=${base_url%%/*}

if [[ -z $image_dir ]]; then
	image_dir=$(mktemp -d -p . -t linksXXX)
else
	[[ -d $image_dir ]] || mkdir -p "$image_dir"
fi

# image URLs
image_urls_file=$image_dir/links.html
echo "image URLs will be saved in the $image_urls_file file"
if [[ ! -f $image_urls_file ]]; then
	wget -q --spider -r "$gallery_url" -O "$image_urls_file"
	sed -i -n "s#.*src=\"\(/images\)\(/thumb\)\([^\.]*\)\.\([^/]*\)/.*#$base_url\1\3.\4#p" "$image_urls_file"
fi

# image files
if [[ -n $download_images ]]; then
	echo "images will be saved in the $image_dir dir"
	wget -c --content-disposition -i "$image_urls_file" -P "$image_dir"
fi
E.g. to download the Liar's gallery image URLs into a file:

Code: Select all

wiki_gallery_download -u http://www.fembotwiki.com/index.php?title=The_Liar
Or to download the second book of the Uncom's Revolution:

Code: Select all

wiki_gallery_download -u http://www.fembotwiki.com/index.php?title=The_Revolution_-_Book_Two_-_Ongoing -s
Hope it works for you, Linux users!

User avatar
Robotman
Posts: 7958
Joined: Tue May 13, 2003 7:01 pm
Technosexuality: Built
Identification: Human
Gender: Male
Contact:

Re: Download all images from a gallery

Post by Robotman » Sun Jul 08, 2018 2:25 pm

Nice! Thanks. :)

Toastdroid
Posts: 100
Joined: Mon Mar 12, 2018 6:48 pm
Technosexuality: Built
Identification: Human
Gender: Male
Contact:

Re: Download all images from a gallery

Post by Toastdroid » Mon Jul 09, 2018 5:04 pm

Got any instructions for how to run this? I know it's for linux, but Windows 10 can apparently run these through WSL

User avatar
Chemik
Posts: 191
Joined: Sat Mar 12, 2005 8:37 pm
Technosexuality: Built and Transformation
Identification: Human
Gender: Male
Contact:

Re: Download all images from a gallery

Post by Chemik » Mon Jul 09, 2018 6:46 pm

Toastdroid wrote:Got any instructions for how to run this? I know it's for linux, but Windows 10 can apparently run these through WSL
I suppose the WSL you mentioned works pretty much like BASH shell in Linux (however, it's just my assumption, I've got no access to any Windows machine).

If it's so, you just need to save a script as, say, wiki_gallery_download, then make it executable

Code: Select all

chmod +x wiki_gallery_download
and then execute it, e.g.

Code: Select all

./wiki_gallery_download -s -u http://fembotwiki.com/index.php?title=Sexdroids_in_Space
"./" is necessary if the script is in the current directory and not in PATH. You might need to install wget if it's not available by default.

YajuShinki
Posts: 8
Joined: Sun Jun 23, 2019 7:32 pm
Technosexuality: Built and Transformation
Identification: Android
Gender: Male
Contact:

Re: Download all images from a gallery

Post by YajuShinki » Thu Aug 29, 2019 3:34 pm

I'm getting an error:

Code: Select all

main@YSK-Laptop:~/fbwarchive$ ./fbwarchive.sh -u http://www.fembotwiki.com/index.php?title=Xeran
./fbwarchive.sh: line 58: warning: here-document at line 8 delimited by end-of-file (wanted `EOF')
./fbwarchive.sh: line 59: syntax error: unexpected end of file
Is there a fix for this or am I just doing something wrong?

Post Reply
Users browsing this forum: No registered users and 2 guests