Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.5.0 #44

Merged
merged 2 commits into from
Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
[![Build Status](https://travis-ci.org/thejandroman/bing-wallpaper.svg?branch=travis)](https://travis-ci.org/thejandroman/bing-wallpaper)

Bing Wallpaper for Mac and Ubuntu
=================================

Expand All @@ -12,6 +10,7 @@ The script was tested on:

- Mac OS X 10.8 - 10.12
- Ubuntu 12.04 - 16.04
- Arch 2022.01.01

How to use?
-----------
Expand All @@ -38,7 +37,8 @@ Options:
Will be created if it does not exist.
[default: $HOME/Pictures/bing-wallpapers/]
-r --resolution <resolution> The resolution of the image to retrieve.
Supported resolutions: 1920x1200 1920x1080 800x480 400x240
Supported resolutions:
UHD 1920x1200 1920x1080 800x480 400x240
-w --set-wallpaper Set downloaded picture as wallpaper (Only mac support for now).
-h --help Show this screen.
--version Show version.
Expand Down
48 changes: 21 additions & 27 deletions bing-wallpaper.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env bash
# shellcheck disable=SC1117

readonly SCRIPT=$(basename "$0")
readonly VERSION='0.4.0'
readonly RESOLUTIONS=(1920x1200 1920x1080 800x480 400x240)
SCRIPT=$(basename "$0")
readonly SCRIPT
VERSION='0.5.0'
readonly VERSION
RESOLUTIONS=(UHD 1920x1200 1920x1080 800x480 400x240)
readonly RESOLUTIONS

usage() {
cat <<EOF
Expand All @@ -24,7 +27,8 @@ Options:
Will be created if it does not exist.
[default: $HOME/Pictures/bing-wallpapers/]
-r --resolution <resolution> The resolution of the image to retrieve.
Supported resolutions: ${RESOLUTIONS[*]}
Supported resolutions:
${RESOLUTIONS[*]}
-w --set-wallpaper Set downloaded picture as wallpaper (Only mac support for now).
-h --help Show this screen.
--version Show version.
Expand All @@ -37,17 +41,12 @@ print_message() {
fi
}

transform_urls() {
sed -e "s/\\\//g" | \
sed -e "s/[[:digit:]]\{1,\}x[[:digit:]]\{1,\}/$RESOLUTION/" | \
tr "\n" " "
}

# Defaults
PICTURE_DIR="$HOME/Pictures/bing-wallpapers/"
RESOLUTION="1920x1080"

# Option parsing
BOOST=1
while [[ $# -gt 0 ]]; do
key="$1"

Expand All @@ -71,7 +70,7 @@ while [[ $# -gt 0 ]]; do
SSL=true
;;
-b|--boost)
BOOST=$(($2-1))
BOOST=$(($2))
shift
;;
-q|--quiet)
Expand Down Expand Up @@ -104,29 +103,24 @@ done
# Create picture directory if it doesn't already exist
mkdir -p "${PICTURE_DIR}"

# Parse bing.com and acquire picture URL(s)
read -ra urls < <(curl -sL $PROTO://www.bing.com | \
grep -Eo "url\(.*?\)" | \
sed -e "s/url(\([^']*\)).*/http:\/\/bing.com\1/" | \
transform_urls)

if [ -n "$BOOST" ]; then
read -ra archiveUrls < <(curl -sL "$PROTO://www.bing.com/HPImageArchive.aspx?format=js&n=$BOOST" | \
grep -Eo "url\(.*?\)" | \
sed -e "s/url(\([^']*\)).*/http:\/\/bing.com\1/" | \
transform_urls)
urls=( "${urls[@]}" "${archiveUrls[@]}" )
fi
read -ra urls < <(curl -sL "$PROTO://www.bing.com/HPImageArchive.aspx?format=js&n=$BOOST" | \
# Extract the image urls from the JSON response
grep -Po '(?<=url":").*?(?=")' | \
# Set the image resolution
sed -e "s/[[:digit:]]\{1,\}x[[:digit:]]\{1,\}/$RESOLUTION/" | \
# FQDN the image urls
sed -e "s/\(.*\)/${PROTO}\:\/\/www.bing.com\1/" | \
tr "\n" " ")

for p in "${urls[@]}"; do
for pic in "${urls[@]}"; do
if [ -z "$FILENAME" ]; then
filename=$(echo "$p" | sed -e 's/.*[?&;]id=\([^&]*\).*/\1/' | grep -oe '[^\.]*\.[^\.]*$')
filename=$(echo "$pic" | sed -e 's/.*[?&;]id=\([^&]*\).*/\1/' | grep -oe '[^\.]*\.[^\.]*$')
else
filename="$FILENAME"
fi
if [ -n "$FORCE" ] || [ ! -f "$PICTURE_DIR/$filename" ]; then
print_message "Downloading: $filename..."
curl $CURL_QUIET -Lo "$PICTURE_DIR/$filename" "$p"
curl $CURL_QUIET -Lo "$PICTURE_DIR/$filename" "$pic"
else
print_message "Skipping: $filename..."
fi
Expand Down
40 changes: 0 additions & 40 deletions contributing.json

This file was deleted.