generated from me/template-mit
Move the download-website function to shared, plus add random wait and wait retry options and enhance final output slightly.
This commit is contained in:
@@ -581,6 +581,75 @@ alias pull-audio="v2a"
|
|||||||
alias pa="v2a"
|
alias pa="v2a"
|
||||||
|
|
||||||
|
|
||||||
|
### Web ###
|
||||||
|
|
||||||
|
function download-website {
|
||||||
|
website="$1"
|
||||||
|
if [[ -z "$website" ]]; then
|
||||||
|
echo "ERROR: Website not provided. $website"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
if [[ "$website" != "http"* ]]; then
|
||||||
|
website="http://$website"
|
||||||
|
fi
|
||||||
|
# https://simpleit.rocks/linux/how-to-download-a-website-with-wget-the-right-way/
|
||||||
|
# Does not simplify the links for offline usage.
|
||||||
|
# wget --wait=2 \
|
||||||
|
# --level=inf \
|
||||||
|
# --limit-rate=20K \
|
||||||
|
# --recursive \
|
||||||
|
# --page-requisites \
|
||||||
|
# --user-agent=Mozilla \
|
||||||
|
# --no-parent \
|
||||||
|
# --convert-links \
|
||||||
|
# --adjust-extension \
|
||||||
|
# --no-clobber \
|
||||||
|
# -e robots=off \
|
||||||
|
# $website &&
|
||||||
|
|
||||||
|
# https://www.digitalcitizen.life/how-to-download-entire-website-for-offline-viewing/
|
||||||
|
# This one is supposed to work too and is much smaller.
|
||||||
|
# wget --mirror \
|
||||||
|
# --convert-links \
|
||||||
|
# --adjust-extension \
|
||||||
|
# --page-requisites \
|
||||||
|
# --no-parent \
|
||||||
|
# $website &&
|
||||||
|
|
||||||
|
# Combine the two by using mirow and removing the rate limit.
|
||||||
|
wget --mirror \
|
||||||
|
--wait=2 \
|
||||||
|
--level=inf \
|
||||||
|
--recursive \
|
||||||
|
--page-requisites \
|
||||||
|
--user-agent=Mozilla \
|
||||||
|
--no-parent \
|
||||||
|
--convert-links \
|
||||||
|
--adjust-extension \
|
||||||
|
--no-clobber \
|
||||||
|
-e robots=off \
|
||||||
|
--timeout=15 \
|
||||||
|
--tries=0 \
|
||||||
|
--continue \
|
||||||
|
--waitretry=5 \
|
||||||
|
--random-wait \
|
||||||
|
$website &&
|
||||||
|
{
|
||||||
|
echo -e "\nSuccess!"
|
||||||
|
} || {
|
||||||
|
echo -e "\nERROR: Command reported a failure. (Error code '$?')"
|
||||||
|
echo "This may mean that the URL was not converted to local links."
|
||||||
|
echo "Please check the error and contents and try again if needed."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alias website-download="download-website"
|
||||||
|
alias curl-site="download-website"
|
||||||
|
alias pull-site="download-website"
|
||||||
|
alias curl-www="download-website"
|
||||||
|
alias pull-www="download-website"
|
||||||
|
alias www-pull="download-website"
|
||||||
|
|
||||||
|
|
||||||
## Finalize ##
|
## Finalize ##
|
||||||
|
|
||||||
# Export all functions! #
|
# Export all functions! #
|
||||||
|
|||||||
Reference in New Issue
Block a user