#!/bin/sh
# test we are root
if [ "$USER" != "root" ] ; then
   exit 1                                                      
fi

# no flags its a repack

P=yt-dlp
V=2026.08.19
SRC=$P-$V

USER=`cat /etc/sysconfig/tcuser`
LIST="compiletc submitqc  "
for Z in $LIST 
    do 
    su -c "tce-load -i $Z" $USER
done

cd /tmp
mkdir -p $P/usr/local/bin $P/usr/local/share/doc/$P
cd $P/usr/local/bin
/usr/local/bin/wget -nc --no-check-certificate \
https://github.com/$P/$P/releases/download/$V/$P 
chmod 755 $P
cd /tmp/$P/usr/local/share/doc/$P
/usr/local/bin/wget -nc --no-check-certificate \
https://raw.githubusercontent.com/yt-dlp/yt-dlp/refs/heads/master/LICENSE
cd /tmp

# yt borks on audio extraction if you have wrong python sym linked
# tce.install
#############
mkdir -p $P/usr/local/tce.installed
cat << EOF > $P/usr/local/tce.installed/$P 
#!/bin/sh
# assume members may have loaded wrong Version of python before 3.14
# break and re-establish the sym link
cd /usr/local/bin
rm -rf python3
ln -s python3.14 python3
EOF
chown -R root:staff $P/usr/local/tce.installed
chmod -R 775        $P/usr/local/tce.installed

# TCZ them
#######
LIST="$P "
for Z in $LIST
do
	mksquashfs $Z $Z.tcz
	md5sum $Z.tcz > $Z.tcz.md5.txt
	cd $Z
	find . -not -type d | cut -c 2- | sort > /tmp/$Z.tcz.list
	cd /tmp
done

ls -hal

echo 'Title:          yt-dlp.tcz  
Description:    python3.14 script to download youtubes
Version:        2026.08.19
Author:         https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTORS 
Original-site:  https://github.com/yt-dlp/yt-dlp
Copying-policy: https://github.com/yt-dlp/yt-dlp/blob/master/LICENSE 
Size:           2.9M
Extension_by:   aus9 
Tags:           youtube downloader
Comments:       WARNING
                Install script assumes you may have loaded the wrong python version
                before loading this TCE. So I break and re-link python3.14 to python3
                Either reboot to use older pythons or after using this TCE, use root powers
                to break my link and relink either python3.6 or python3.9 to python3
                ALSO you may need to remove this TCE from boot list if you are using
                TCEs that rely on older pythons

                For movie--without ffmpeg7 to merge video and audio into a webm file, 
                you will have a video file (mp4) with no audio and an audio file (webm) 
                with no video. Hence the need for large ffmpeg7 dependency.
                
                video+audio $ yt-dlp <url>
                audio only  $ yt-dlp -x <url>
              
                If your player can not play webm or opus or use $ ffplay
                $ ffmpeg -i filename.webm filename.mp4
                $ ffmpeg -i filename.opus filename.mp3
              
Change-log:     2023/05/04 v 2023.03.04 on 14x 
                2024/10/31 v 2024.10.22 on 15x add ca-certificates dep
                2026/01/04 v 2025.12.08 on 17x errors unless ffmpeg7 loaded 
Current:        2026/10/01 v 2026.08.19 on 17x + install script for python sym link      ' > $P.tcz.info
echo 'python3.14.tcz
ca-certificates.tcz
ffmpeg7.tcz  ' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

