Last active
July 12, 2019 15:57
-
-
Save ATRescue/1edec23a8d639913c434a9987e68ec9f to your computer and use it in GitHub Desktop.
Rescuing historical YouTube Trends data. Version: 1.6.0.1
This file contains hidden or 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
# YouTube Trends Archiver – Automatically saves YouTube trends into the Wayback Machine | |
# URL format: https://www.youtube.com/feed/trending?hl=EN&gl=[language initials in capital letters, e.g. “DE”] | |
# Feel free to leave suggestions in the comments. | |
# Start newest version automatically: . ./"$(ls YouTube_Trends_Archive*.*sh -1 -t |head -n 1)" | |
Version="1.6.0.1" # Features such as the ability to change without restarting the script will be added. | |
dbglog="YTtrendsArchiver.dbg.log" # Name of Debug Log file. | |
echo "Version: $Version" | |
function timestamp { date "+%Y%m%d%H%M%S" ;} | |
function timestamp_timehighlight { printf "$(timestamp | sed -r s/"^([0-9]{8})(([0-9]{6}))$"/"\1$(highlighttext "\\\2")"/g )" ;} | |
function highlighttext { printf "\e[7m\e[1m""$@""\e[27m\e[21m" ;} | |
function pgtitle { curl -s "$@" | grep -ioe "<title>.*</title>" | sed -r "s#</?title>##g" ;} | |
function acv { wget -a wget.dbg -O "/dev/null" "http://web.archive.org/record/$@" ;} # Android Terminal only supports “curl” , but this runs on desktop Linux terminal. | |
function debuglog() { echo -e "$(timestamp) YouTube Trends Archiver: Debug log: Version:$Version Information:" "$@" >>"$dbglog" ;} | |
function debuglog_verbose() { echo -e "$(timestamp_timehighlight) YouTube Trends Archiver: Debug log (verbose): Version:$Version Information:" "$@" |tee -a "$dbglog" ;} | |
function acv_interval_printf { printf "\e[7m";if [ -n "$acv_interval" ];then printf "$acv_interval";else printf $acv_interval_default;fi;printf "\e[27m" ;} | |
acv_interval_default="6h" # Default value. # deprecated. | |
if [ -f "./.YTTA.cfg.sh" ];then . "./.YTTA.cfg.sh";fi # Placeholder. | |
# Log file backups: | |
cp -n $dbglog "$dbglog.version$(timestamp)" | |
cp -n wget.dbg "wget.$(timestamp).dbg" | |
debuglog "Initiated." "Asking for archival interval. Default: $acv_interval_default. " | |
if [ -z "$1" ];then | |
read -p "Set YouTube Trends archival interval: " acv_interval | |
debuglog_verbose "Archival interval set to: $acv_interval" | |
else | |
acv_interval="$1" | |
debuglog_verbose "Archival interval set to: $(highlighttext $acv_interval) using transcluded \$1 argument." | |
fi | |
####################################################################### | |
debuglog_verbose "YouTube Trends archival initiated. Interval: $(acv_interval_printf) Interval variable: $acv_interval. Default: $acv_interval_default." | |
while :; do | |
debuglog_verbose "YouTube Trends archival: loop \e[33mstarted.\e[0m Interval set to: $(acv_interval_printf)." # Colours added for easier oversight. | |
acv "https://www.youtube.com/feed/trending?hl=EN&gl=" | |
acv "https://www.youtube.com/feed/trending?hl=EN&gl=EN" | |
acv "https://www.youtube.com/feed/trending?hl=EN&gl=DE" | |
debuglog_verbose "YouTube Trends archival \e[32mfinished.\e[0m Next archival in: $(acv_interval_printf)." | |
sleep "${acv_interval:-"$acv_interval_default"}" # Android Terminal does only support plain integer numbers for the “sleep” command, no “s” “m” “h” “d” or digits behind decimal, such as “0.9” or “.1m”. | |
debuglog_verbose "Interval timer finished. Restarting loop." | |
echo -e "––––––––––" >> $dbglog | |
done | |
# Created by ATrescue. | |
# https://gist.github.com/ATRescue/ | |
# Discord: ATrescue#4675 | |
# https://en.wikipedia.org/wiki/User_talk:ATrescue?action=edit§ion=new | |
# https://www.ArchiveTeam.org/index.php?title=User:ATrescue (deprecated) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment