Last active
January 1, 2016 11:29
-
-
Save tynn/8138735 to your computer and use it in GitHub Desktop.
Script to maintain a list of torrents from webpages using data-bt attributes to link to those.
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
#!/bin/sh | |
# 2013 CC0 http://creativecommons.org/publicdomain/zero/1.0/ | |
# Got a little annoyed by searching for game updates on HB webpage ... | |
[ $# -lt 2 ] && echo Usage: $(basename "$0") input-file output-dir && exit 1 | |
[ ! -f "$1" ] && ([ -t 0 ] || [ "$1" != - ]) && echo Invalid input-file \'$1\' && exit 1 | |
[ ! -d "$2" ] && ! mkdir -p "$2" && echo Invalid output-dir \'$2\' && exit 1 || out="$2" | |
bt=$(date +"%Y%m%d%H%M%S") && mkdir "$out/$bt" && bt="$bt/bt" | |
grep -m 1 'data-bt="' "$1" > /dev/null && S=\" || S=\' | |
grep -o "data-bt=$S.*://.*$S" "$1" | sed "s/^data-bt=\|$S//g" | sort | uniq > "$out/$bt" | |
[ x"$S" = x\" ] && sed -i "s/&/\&/g" "$out/$bt" | |
sed 's/\.torrent\?.*$/.torrent/' "$out/$bt" > "$out/$bt.urls" | |
btlu=0-latest.urls && [ -f "$out/$btlu" ] || touch "$out/$btlu" | |
diff --old-line-format '%L' --new-line-format '' --unchanged-line-format '' "$out/$btlu" "$out/$bt.urls" > "$out/$bt.removed" | |
diff --old-line-format '' --new-line-format '%L' --unchanged-line-format '' "$out/$btlu" "$out/$bt.urls" > "$out/$bt.added" | |
grep -f "$out/$bt.added" "$out/$bt" | wget -P "$out" -o "$out/$bt.log" -i - | |
ln -sf "$bt.urls" "$out/$btlu" | |
rename -f 's/\.torrent\?[^\*].*$/.torrent/' "$out"/*.torrent\?* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment