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

# I need to modify attached Makefile as we have no pandoc
export CFLAGS="-mtune=generic -Os -pipe"
export CXXFLAGS="-mtune=generic -Os -pipe -fno-exceptions -fno-rtti"

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

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

cd /tmp
/usr/local/bin/wget -nc --no-check-certificat \
https://github.com/$P/$P/archive/refs/tags/$V.tar.gz
tar xvf $V*gz
cd $SRC
# use modified Makefile 
make -j6
make install 
cd /tmp
# installs other stuff we want the exe

# main
###### 
mkdir -p $P/usr/local/bin $P/usr/local/share/doc/$P
mv /usr/local/bin/$P $P/usr/local/bin/
cp $SRC/LICENSE $P/usr/local/share/doc/$P/

# 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:    Fork of youtube-dl
Version:        2025.12.08
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:           3.0M
Extension_by:   aus9 
Tags:           youtube downloader
Comments:       Youtube is making it harder, so ffmpeg7 is now a dep
                Recent downloads likely SABR formats 
                https://github.com/yt-dlp/yt-dlp/issues/12482
                that results in video= webm - audio= opus

                video+audio $ yt-dlp <url>
                audio only  $ yt-dlp -x <url>
              
                If your player can not play webm or opus
                $ 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
Current:        2026/01/04 v 2025.12.08 on 17x errors unless ffmpeg7 loaded       ' > $P.tcz.info
echo 'python3.14.tcz
ca-certificates.tcz
ffmpeg7.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync

