diff --git a/rc_shared.sh b/rc_shared.sh index 389197b..e61725d 100644 --- a/rc_shared.sh +++ b/rc_shared.sh @@ -581,6 +581,75 @@ alias pull-audio="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 ## # Export all functions! #