#!/bin/sh #nitram was here #CNK came along later EXECDIR="/tmp/get_youtube-dl/usr/local/bin" BUILDDIR="/tmp/get_youtube-dl" OLDTEMPDIR="/tmp/old_youtube-dl" OPTIONALDIR="/etc/sysconfig/tcedir/optional" UPGRADEDIR="/etc/sysconfig/tcedir/optional/upgrade" TCZ="youtube-dl.tcz" MD5FILE="youtube-dl.tcz.md5.txt" DEPFILE="youtube-dl.tcz.dep" YTDL="youtube-dl" # No python.tcz on PiCore if uname -m | grep -q arm; then DEP="python2.7.tcz" else DEP="python.tcz" fi REBOOT="0" cleanup () { [ -d "$BUILDDIR" ] && sudo rm -rf "$BUILDDIR" [ -d "$OLDTEMPDIR" ] && sudo rm -rf "$OLDTEMPDIR" } cleanup if [ "$1" ]; then YTDLTYPE="$1" else clear echo "get_youtube-dl.sh (v202305) creates \"$TCZ\" from downloaded executable. youtube-dl Homepage: https://rg3.github.io/youtube-dl/ Supported sites: https://rg3.github.io/youtube-dl/supportedsites.html Detailed usage: https://github.com/rg3/youtube-dl/blob/master/README.md Daily builds: https://github.com/ytdl-patched/youtube-dl/ yt-dlp Homepage: https://github.com/yt-dlp/yt-dlp Supported sites: https://github.com/yt-dlp/yt-dlp/blob/master/supportedsites.md Detailed usage: https://github.com/yt-dlp/yt-dlp#usage-and-options Streaming example (copy all including dashes): youtube-dl -f 36 -o - https://www.youtube.com/watch?v=_v94XqFW4Qw | mplayer - Press Enter to continue, or Ctrl-c to cancel..." read echo -e "youtube-dl\nyoutube-dl_daily\nyt-dlp" > /tmp/ytsel if [ -f "$OPTIONALDIR"/"$TCZ" ]; then select "Choose release type to update existing \"$TCZ\" to" /tmp/ytsel else select "Choose release type to create new \"$TCZ\":" /tmp/ytsel fi YTDLTYPE="`cat /tmp/select.ans`" rm /tmp/ytsel /tmp/select.ans fi if [ "$YTDLTYPE" ]; then case "$YTDLTYPE" in "youtube-dl") YTDL=youtube-dl YTDLDOMAIN=yt-dl.org YTDL_URL=https://yt-dl.org/downloads/latest/youtube-dl ;; "youtube-dl_daily") YTDL=youtube-dl YTDLDOMAIN=github.org YTDL_URL=https://github.com/ytdl-patched/youtube-dl/releases/latest/download/youtube-dl ;; "yt-dlp") YTDL=yt-dlp YTDLDOMAIN=github.org YTDL_URL=https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp DEP="python3.9.tcz" ;; http*) YTDL="${YTDLTYPE##*/}" if [ "$YTDL" == "yt-dlp" ]; then DEP="python3.9.tcz" fi YTDLDOMAIN=`expr \"$YTDLTYPE\" : '.*://\([^ /]*\)/'` YTDL_URL="$YTDLTYPE" ;; "q") exit ;; *) echo -e "* Unknown type \"$YTDLTYPE\".\n Options are: youtube-dl, youtube-dl_daily, "\ "yt-dlp, or custom URL." exit 1 ;; esac else exit fi ## Network check: echo "* Checking network connection and $YTDLDOMAIN availability." if ! /bin/ping $YTDLDOMAIN -c 1 >/dev/null 2>&1; then echo "* Network connection or $YTDLDOMAIN unavailable, check connection, exiting.." exit 1 fi ## Retrieve latest: mkdir -p "$EXECDIR" cd "$EXECDIR" echo "* Retrieving latest "$YTDL" from $YTDLDOMAIN." if [ -e /usr/local/tce.installed/ca-certificates ]; then wget "$YTDL_URL" else echo -e "* ca-certificates.tcz is not installed, so not checking certificate\n"\ " for $YTDLDOMAIN.\n\n"\ " You may want to run $YTDL with the --no-check-certificate\n"\ " option to avoid errors during use." wget --no-check-certificate "$YTDL_URL" fi if [ $? -ne 0 -o ! -f "$EXECDIR"/"$YTDL" ]; then echo "* Issue retrieving "$YTDL", exiting.." cleanup exit 1 fi ## Make it execute with the python2 command provided by python.tcz: if [ "$YTDLTYPE" != "yt-dlp" ]; then sed -i 's/\/usr\/bin\/env python$/\/usr\/bin\/env python2/' "$EXECDIR"/"$YTDL" fi ## Update check: if [ -f "$OPTIONALDIR"/"$TCZ" ]; then mkdir -p "$OLDTEMPDIR" cp "$OPTIONALDIR"/"$TCZ" "$OLDTEMPDIR" cd "$OLDTEMPDIR" unsquashfs -n "$TCZ" >/dev/null 2>&1 OLDMD5="`md5sum \"$OLDTEMPDIR\"/squashfs-root/usr/local/bin/*`" OLDPROG="${OLDMD5##*/}" OLDMD5="${OLDMD5%% *}" echo "* System "$OLDPROG" md5sum: "$OLDMD5"" NEWMD5="`md5sum \"$EXECDIR\"/\"$YTDL\"`" NEWMD5="${NEWMD5%% *}" echo "* Latest "$YTDL" md5sum: "$NEWMD5"" if [ "$OLDMD5" == "$NEWMD5" ]; then echo "* Already using latest "$YTDL", exiting.." cleanup exit else echo "* Newer "$YTDL" available, updating." REBOOT="1" fi fi ## Retrieve dep as needed: if [ -f "$OPTIONALDIR"/"$DEP" ]; then echo "* Dependency "$DEP" already installed." : else echo "* Retrieving "$DEP" dependency from `cat /opt/tcemirror`." tce-load -w "$DEP" if [ ! -f "$OPTIONALDIR"/"$DEP" ]; then echo "* Issue retrieving "$DEP" dependency, exiting.." cleanup exit 1 fi fi ## Create updated youtube-dl.tcz: echo "* Creating "$TCZ", dependency and md5sum files." cd "$EXECDIR" chmod a+rx "$YTDL" cd /tmp sudo chown -R root:root "$BUILDDIR" mksquashfs "$BUILDDIR" "$TCZ" >/dev/null 2>&1 md5sum "$TCZ" > "$MD5FILE" echo "$DEP" > "$DEPFILE" if [ -f "$OPTIONALDIR"/"$TCZ" ]; then echo "* Moving files to "$UPGRADEDIR"/." [ -d "$UPGRADEDIR" ] || mkdir -p "$UPGRADEDIR" mv -f "$TCZ" "$MD5FILE" "$DEPFILE" "$UPGRADEDIR" else echo "* Moving files to "$OPTIONALDIR"/." mv "$TCZ" "$MD5FILE" "$DEPFILE" "$OPTIONALDIR" fi cleanup echo ## Exit options: if [ -z "$1" ]; then read -p "Add "$TCZ" to (b)oot, (o)ndemand or (n)o change? " ANS if [ "$ANS" == "b" ]; then if grep -q "$TCZ" /etc/sysconfig/tcedir/onboot.lst; then echo "* "$TCZ" already in onboot.lst." else echo "* Adding "$TCZ" to /etc/sysconfig/tcedir/onboot.lst." echo "$TCZ" >> /etc/sysconfig/tcedir/onboot.lst fi elif [ "$ANS" == "o" ]; then if [ -e /etc/sysconfig/tcedir/ondemand/"$YTDL" ]; then echo "* "$TCZ" already in OnDemand." else echo "* Adding "$TCZ" to OnDemand." ondemand "$TCZ" fi fi fi if [ "$YTDLTYPE" == "youtube-dl" ]; then echo "* Release notes: https://github.com/rg3/youtube-dl/releases" elif [ "$YTDLTYPE" == "yt-dlp" ]; then echo "* Release notes: https://github.com/yt-dlp/yt-dlp/releases" fi if [ "$REBOOT" == "1" ]; then echo "* Reboot to complete "$TCZ" update, exiting.." else echo "* Load "$TCZ" to utilize, exiting.." fi