From fc6034def178dd4f02455813e47b1910f394d9ad Mon Sep 17 00:00:00 2001 From: Jandrolo Date: Tue, 18 Jan 2022 15:54:32 -0400 Subject: [PATCH 1/2] Update and simplify script After moving to Arch I decided to give this forgotten script a try. It didn't work. It was also very complicated. URL parsing from JSON is a crazy thing to try to do in a bash script. I don't have a Mac to test these changes on but hopefully everything still works. There were a number of overlapping PRs over the years that made it into this revision. I've tried to add credit to the original PRs where applicable. Summary of changes: 1. Merge latest and boost code paths (From @Lyncredible in #39) 2. Use https for all requests if -s (From @Lyncredible in #39) 3. Update URL patterns (From @Lyncredible in #39, @microdog in #36, @nitrogear in #23) 4. Add UHD support (fixes #43) 5. Remove contributing.json as it wasn't used anymore --- README.md | 6 +++--- bing-wallpaper.sh | 43 +++++++++++++++++-------------------------- contributing.json | 40 ---------------------------------------- 3 files changed, 20 insertions(+), 69 deletions(-) delete mode 100644 contributing.json diff --git a/README.md b/README.md index a4a16c7..ae7111a 100644 --- a/README.md +++ b/README.md @@ -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 ================================= @@ -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? ----------- @@ -38,7 +37,8 @@ Options: Will be created if it does not exist. [default: $HOME/Pictures/bing-wallpapers/] -r --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. diff --git a/bing-wallpaper.sh b/bing-wallpaper.sh index f352efc..b3d45b1 100755 --- a/bing-wallpaper.sh +++ b/bing-wallpaper.sh @@ -2,8 +2,8 @@ # shellcheck disable=SC1117 readonly SCRIPT=$(basename "$0") -readonly VERSION='0.4.0' -readonly RESOLUTIONS=(1920x1200 1920x1080 800x480 400x240) +readonly VERSION='0.5.0' +readonly RESOLUTIONS=(UHD 1920x1200 1920x1080 800x480 400x240) usage() { cat < 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. @@ -37,17 +38,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" @@ -71,7 +67,7 @@ while [[ $# -gt 0 ]]; do SSL=true ;; -b|--boost) - BOOST=$(($2-1)) + BOOST=$(($2)) shift ;; -q|--quiet) @@ -104,29 +100,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 diff --git a/contributing.json b/contributing.json deleted file mode 100644 index 32b3ddf..0000000 --- a/contributing.json +++ /dev/null @@ -1,40 +0,0 @@ -// https://gitmagic.io/rules -{ - "commit": { - "subject_cannot_be_empty": true, - "subject_must_be_longer_than": 4, - "subject_must_be_shorter_than": 101, - "subject_lines_must_be_shorter_than": 51, - "subject_must_be_single_line": true, - "subject_must_be_in_tense": "imperative", - "subject_must_start_with_case": "lower", - "subject_must_not_end_with_dot": true, - - "body_lines_must_be_shorter_than": 73 - }, - "pull_request": { - "subject_cannot_be_empty": true, - "subject_must_be_longer_than": 4, - "subject_must_be_shorter_than": 101, - "subject_must_be_in_tense": "imperative", - "subject_must_start_with_case": "upper", - "subject_must_not_end_with_dot": true, - - "body_cannot_be_empty": true, - "body_must_include_verification_steps": true, - "body_must_include_screenshot": ["html", "css"] - }, - "issue": { - "subject_cannot_be_empty": true, - "subject_must_be_longer_than": 4, - "subject_must_be_shorter_than": 101, - "subject_must_be_in_tense": "imperative", - "subject_must_start_with_case": "upper", - "subject_must_not_end_with_dot": true, - - "body_cannot_be_empty": true, - "body_must_include_reproduction_steps": ["bug"], - - "label_must_be_set": true - } -} From cc7f39cbbf0af49cf03b6476b185ec3d682eb360 Mon Sep 17 00:00:00 2001 From: Jandrolo Date: Tue, 18 Jan 2022 16:14:01 -0400 Subject: [PATCH 2/2] Fix shellcheck sc2155 error https://github.com/koalaman/shellcheck/wiki/SC2155#problematic-code-in-the-case-of-readonly --- bing-wallpaper.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bing-wallpaper.sh b/bing-wallpaper.sh index b3d45b1..8e50708 100755 --- a/bing-wallpaper.sh +++ b/bing-wallpaper.sh @@ -1,9 +1,12 @@ #!/usr/bin/env bash # shellcheck disable=SC1117 -readonly SCRIPT=$(basename "$0") -readonly VERSION='0.5.0' -readonly RESOLUTIONS=(UHD 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 <