Skip to content

Instantly share code, notes, and snippets.

@smaeul
Created September 2, 2015 06:39
Show Gist options
  • Save smaeul/ab49dec49b0fa5e5eb45 to your computer and use it in GitHub Desktop.
Save smaeul/ab49dec49b0fa5e5eb45 to your computer and use it in GitHub Desktop.
Simple bash script to download the full-resolution wallpapers from the Bing gallery (https://www.bing.com/gallery/)
#!/bin/bash
ORIGDIR=$PWD
TEMPDIR=$(mktemp -d)
DESTDIR=~/Pictures/Bing
# JavaScript source:
# function d(a) {
# var b, c, d, e = f.length, g = 0;
# for (b = 0, c = a.length; c > b; b++)
# g = (g << 5) - g + a.charCodeAt(b), g &= g;
# return d = Math.abs(g) % e, f[d] + a;
# }
# var f = ["//az608707.vo.msecnd.net/files/", "//az619519.vo.msecnd.net/files/", "//az619822.vo.msecnd.net/files/"];
#
# usage: fullurl <imgfn>
fullurl() {
python2 <<EOF
dombase = ["//az608707.vo.msecnd.net/files/", "//az619519.vo.msecnd.net/files/", "//az619822.vo.msecnd.net/files/"]
imgfn = "$1"
index = 0
for char in list(imgfn):
index = (index << 5) - index + ord(char)
index &= index;
print "http:" + dombase[abs(index) % len(dombase)] + imgfn
EOF
}
mkdir -p $DESTDIR
pushd $TEMPDIR
mkdir info
wget 'https://www.bing.com/gallery/home/browsedata?z=0' -O imagelist
cat imagelist | cut -d] -f3 | cut -d[ -f2 | tr -d '"' | sed 's/,/\n/g' > imageids
for id in $(head -n4 imageids)
do
wget "https://www.bing.com/gallery/home/imagedetails/${id}?z=0" -O info/${id}
imgfn=$(cat info/${id} | sed 's/,/\n/g' | tr -d '"' | grep ^wpFullFilename | cut -d: -f2)
wget "$(fullurl $imgfn)" -O $DESTDIR/$imgfn
done
popd
rm -r $TEMPDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment