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

# no flags as script
# I also tried the tarball and [code]make yt-dlp[/code] but size of script is still 2.6 M
# so this is an easier build

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

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

cd /tmp
su -c "/usr/local/bin/wget \
https://github.com/$P/$P/releases/download/$V/$P " $USER 
mv $P $SRC

# main
###### because I saved download chown command added
mkdir -p $P/usr/local/bin
mv $V $P/usr/local/bin/$P
chmod 755 $P/usr/local/bin/$P
chown root:root $P/usr/local/bin/$P

mkdir -p $P/usr/local/share/doc/$P
echo 'A license with no conditions whatsoever which dedicates works 
to the public domain. Unlicensed works, modifications, and larger 
works may be distributed under different terms and without source code.' > $P/usr/local/share/doc/$P/LICENSE

# 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

cat >> $P.tcz.info <<'EOF'
Title:          yt-dlp.tcz  
Description:    command line fork of youtube-dl 
Version:        2024.10.22
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.8M
Extension_by:   aus9 
Tags:           youtube downloader
Comments:       Youtube web browser & yt-dlp are more complicated.
                
                If you are getting the download link in your web browser. You do not 
                need to play it so it can be a basic web browser. In browser test, I
                suggest disable adblocker, enable DRM & plugins openH264 + widevine.
                Loading ffmpeg4 or 5 no longer converts audio to mp3 by simple command. 
    
                Basic use includes video download 
                $ yt-dlp <url>
                Older youtubes download as .mp4 - more recent as .webm or .mkv
                mkv should play in vlc or qmplay2 to convert webm to mp4 try
                $ tce-load -i ffmpeg5 
                $ ffmpeg -i file.webm file.mp4
                
                audio only
                yt-dlp -x <url>
                Older youtubes download as .m4a - more recent as .opus
                If you want mp3 do this
                $ tce-load -i ffmpeg5 
                $ ffmpeg -i file.m4a file.mp3
                $ ffmpeg -i file.opus file.mp3

                Playback in larger web browsers, vlc or qmplay2
                mp3 only need cli apps like mpg123 YMMV
                Note qmplay2 context menu allows you to download as mp3 
                 
                help or see original site for more info.
                $ yt-dlp -h
            
Change-log:     2023/05/04 v 2023.03.04 on 14x 
Current:        2024/10/31 v 2024.10.22 on 15x add ca-certificates dep
EOF

echo 'python3.9.tcz
ca-certificates.tcz' > $P.tcz.dep

submitqc --libs
rm -rf *.zsync