Skip to content

Commit

Permalink
Revamp mtg-wallpapers
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorgalvao committed May 6, 2020
1 parent 9391d4a commit 9cdc399
Show file tree
Hide file tree
Showing 10 changed files with 158 additions and 182 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Spoof the MAC address
### makeicns
Make an icns file from a png

### mtgwallpaper
### mtg-wallpapers
Download Magic: The Gathering wallpapers

### pinboardbackup
Expand Down
30 changes: 30 additions & 0 deletions manpages/mtg-wallpapers.1
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)
24 changes: 24 additions & 0 deletions manpages/mtg-wallpapers.md
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)
37 changes: 0 additions & 37 deletions manpages/mtgwallpaper.1

This file was deleted.

29 changes: 0 additions & 29 deletions manpages/mtgwallpaper.md

This file was deleted.

8 changes: 6 additions & 2 deletions manpages/progressbar.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "PROGRESSBAR" "1" "May 2017" "Vítor Galvão" "progressbar"
.TH "PROGRESSBAR" "1" "May 2020" "Vítor Galvão" "progressbar"
.
.SH "NAME"
\fBprogressbar\fR \- overlay a progress bar on videos and gifs
Expand Down Expand Up @@ -38,8 +38,12 @@ Delay between each frame, in seconds\. Ignored when input is a video\. Default:
File to output to\. Give it a \.mov extension to save as a video, or any other to save as gif\. Default: \fBoutput\.gif\fR in the current directory\.
.
.TP
\fB\-g\fR, \fB\-\-gifski\fR
Use \fBgifski\fR for the conversion\.
.
.TP
\fB\-h, \-\-help\fR
Show help\.
.
.SH "AUTHORS"
Vítor Galvão (vitorgalvao\.com)
Vítor Galvão (https://vitorgalvao\.com)
2 changes: 1 addition & 1 deletion manpages/progressbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ Show help.

## AUTHORS

Vítor Galvão (vitorgalvao.com)
Vítor Galvão (https://vitorgalvao.com)
94 changes: 94 additions & 0 deletions mtg-wallpapers
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
111 changes: 0 additions & 111 deletions mtgwallpaper

This file was deleted.

3 changes: 2 additions & 1 deletion upload-file
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ function ascii_basename {
}

function is_string_in_array {
local string="${1}"
local -r string="${1}"

for value in "${@:2}"; do
[[ "${string}" == "${value}" ]] && return 0
done

return 1
}

Expand Down

0 comments on commit 9cdc399

Please sign in to comment.