#!/bin/bash
#
# RJP https://puolanka.info/goto/youtube-lataaja/
# Remade from https://www.antixforum.com/forums/topic/simple-youtube-download-script/
# Use the latest yt-dlp https://github.com/yt-dlp/yt-dlp
# 14.6.2026 New downloader for rpm distros

TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=youtube-downloader2

if ! nc -zw1 google.com 443; then 
yad --width=400 --text-align=center --center --title=$"No network connection:" --text="
     No network connection
       
    Add network connection and try again  "
fi

touch ~/.Xresources
echo ' ! Use a truetype font and size.
xterm*faceName: Monospace ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources
echo 'xterm*faceSize: 14 ' | grep -xFv -f $HOME/.Xresources >> $HOME/.Xresources
xrdb -merge ~/.Xresources
        
TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=youtube-downloader2-paksu

TUBE="$(yad --title=$"Youtube Video Downloader" --center --width=500 --height=100 --text-align=center --text=$"PUT VIDEO´S ADDRESS INTO BOX" --entry --entry-label=$"ADRESS" --entry-text="")"
if [ $? = 0 ];
then
yad --title=$"Youtube Video Downloader" --center --width=500 --height=100 --text-align=center --text="ADDRESS IS: $TUBE"
xterm -e /bin/sh -c "yt-dlp --extractor-args "youtube:player-client=default,-tv_simply" -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' --no-playlist -o '%(title)s.%(ext)s' $TUBE" && xterm -e /bin/bash -c "read -p \"Video downloaded. You can close this message \"" \

else exit 0
fi
