-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9391d4a
commit 9cdc399
Showing
10 changed files
with
158 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
.\" generated with Ronn/v0.7.3 | ||
.\" http://github.com/rtomayko/ronn/tree/0.7.3 | ||
. | ||
.TH "MTG\-WALLPAPERS" "1" "May 2020" "Vítor Galvão" "mtg-wallpapers" | ||
. | ||
.SH "NAME" | ||
\fBmtg\-wallpapers\fR \- Download Magic: The Gathering wallpapers | ||
. | ||
.SH "SYNOPSIS" | ||
\fBmtg\-wallpapers [options]\fR | ||
. | ||
.SH "DESCRIPTION" | ||
Download the latest official Magic: The Gathering wallpapers\. | ||
. | ||
.SH "OPTIONS" | ||
. | ||
.TP | ||
\fB\-d, \-\-directory\fR | ||
Directory to save wallpapers to\. Defaults to the current one\. | ||
. | ||
.TP | ||
\fB\-s, \-\-size\fR | ||
Wallpaper download size\. See \fB\-\-help\fR for valid options\. | ||
. | ||
.TP | ||
\fB\-h, \-\-help\fR | ||
Show help\. | ||
. | ||
.SH "AUTHORS" | ||
Vítor Galvão (https://vitorgalvao\.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# mtg-wallpapers(1) - Download Magic: The Gathering wallpapers | ||
|
||
## SYNOPSIS | ||
|
||
`mtg-wallpapers [options]` | ||
|
||
## DESCRIPTION | ||
|
||
Download the latest official Magic: The Gathering wallpapers. | ||
|
||
## OPTIONS | ||
|
||
* `-d, --directory`: | ||
Directory to save wallpapers to. Defaults to the current one. | ||
|
||
* `-s, --size`: | ||
Wallpaper download size. See `--help` for valid options. | ||
|
||
* `-h, --help`: | ||
Show help. | ||
|
||
## AUTHORS | ||
|
||
Vítor Galvão (https://vitorgalvao.com) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,4 @@ Show help. | |
|
||
## AUTHORS | ||
|
||
Vítor Galvão (vitorgalvao.com) | ||
Vítor Galvão (https://vitorgalvao.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
|
||
readonly program="$(basename "${0}")" | ||
readonly valid_sizes=('2560x1600' '1920x1080' '1280x960' 'iphone' 'tablet' 'facebook') | ||
readonly default_size="${valid_sizes[0]}" | ||
|
||
function is_string_in_array { | ||
local string="${1}" | ||
|
||
for value in "${@:2}"; do | ||
[[ "${string}" == "${value}" ]] && return 0 | ||
done | ||
|
||
return 1 | ||
} | ||
|
||
function usage { | ||
echo " | ||
Download Magic: The Gathering wallpapers. | ||
Usage: | ||
${program} [options] | ||
Options: | ||
-d, --directory Directory to save wallpapers to. Defaults to the current one. | ||
-s, --size Wallpaper download size. Must be one of: ${valid_sizes[*]}. Defaults to ${default_size}. | ||
-h, --help Show this help. | ||
" | sed -E 's/^ {4}//' | ||
} | ||
|
||
# Options | ||
args=() | ||
while [[ "${1}" ]]; do | ||
case "${1}" in | ||
-h | --help) | ||
usage | ||
exit 0 | ||
;; | ||
-d | --directory) | ||
readonly given_directory="${2}" | ||
shift | ||
;; | ||
-s | --size) | ||
readonly given_wallpaper_size="${2}" | ||
shift | ||
;; | ||
--) | ||
shift | ||
args+=("${@}") | ||
break | ||
;; | ||
-*) | ||
echo "Unrecognised option: ${1}" | ||
exit 1 | ||
;; | ||
*) | ||
args+=("${1}") | ||
;; | ||
esac | ||
shift | ||
done | ||
set -- "${args[@]}" | ||
|
||
# Set wallpaper size to download | ||
readonly wallpaper_size="$( | ||
if [[ -n "${given_wallpaper_size}" ]]; then | ||
echo -n "${given_wallpaper_size}" | ||
else | ||
echo -n "${default_size}" | ||
fi | ||
)" | ||
|
||
# Abort if wallpaper size is invalid | ||
if ! is_string_in_array "${wallpaper_size}" "${valid_sizes[@]}"; then | ||
echo "Wallpaper size needs to be one of: ${valid_sizes[*]}" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Move to download directory | ||
if [[ -n "${given_directory}" && ! -d "${given_directory}" ]]; then | ||
echo "${given_directory} is not a valid directory." >&2 | ||
exit 1 | ||
fi | ||
|
||
cd "${given_directory}" || exit 1 | ||
|
||
# Download wallpapers | ||
readonly wallpaper_urls="$(curl --silent 'https://magic.wizards.com/en/articles/media/wallpapers' | grep "download.*${wallpaper_size}" | sed -E 's/.*href="([^"]*).*/\1/')" | ||
|
||
# Download new wallpapers | ||
for wallpaper_url in ${wallpaper_urls}; do | ||
echo Downloading "$(basename "${wallpaper_url}")…" | ||
curl --silent --remote-name "${wallpaper_url}" | ||
done |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters