Page 1 of 1

Using YouTube download - fails for this single occasion

Posted: Sun Dec 18, 2022 11:43 pm
by cobaka

Hello all! Woof!

I got a script from this forum - YouTube download.
This shell program sits in the top corner of the desk-top. Using click & drag the script will put a you-tube file in your drive.

Great program - but it doesn't work with this file:
https://www.youtube.com/results?search_ ... nian+style
The video is called "A country fair, Tasmanian style"

It's a beaut little home-video made by an American travelling in Tasmania. (Oh! You don't know about Tasmania? It's an island south of Australia, 26,215 square miles in area.)
Any ideas why the you-tube down-loader works for nearly everything except this file?

собака

o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o

The code:
I put this in /bin. Click to run.

Code: Select all

#!/bin/bash

if [ -z $(busybox which gxmessage) ]; then
MESSAGE=xmessage
else
MESSAGE=gxmessage
fi

if [ -z `busybox which yad` ]; then
	msg=" You don't have yad installed.\nIt's a dependency of this program.\n Please install it."
	echo $msg
	$MESSAGE "`echo -e $msg`"
exit 0
fi

if [ -z `busybox which yad` ]; then
	msg=" You don't have yad installed.\nIt's a dependency of this program.\n Please install it."
	echo $msg
	$MESSAGE "`echo -e $msg`"
exit 0
fi

if [ -z `busybox which youtube-dl` ] && [ -z `busybox which youtube-dlc` ]; then
	msg=" You don't have youtube-dl or youtube-dlc installed.\n  It's a dependency of this program.\n   Please install it."
	echo -e "$msg"
yad --center --text=" $msg  " --button="gtk-close:0"
exit
fi

if [ $(busybox which youtube-dl) ]; then
YTDL=youtube-dl
elif [ $(busybox which youtube-dlc) ]; then
YTDL=youtube-dlc
fi

# Config file for to remember Downloads folder
if [ ! -f  "$HOME/.config/ytdl-dnd.conf" ]; then
DL_DIR=$HOME
echo "$DL_DIR" > "$HOME/.config/ytdl-dnd.conf"
else
if [ -z "$(cat "$HOME/.config/ytdl-dnd.conf")" ]; then
DL_DIR=$HOME
echo "$DL_DIR" > "$HOME/.config/ytdl-dnd.conf"
fi
fi


TITLE="YouTube downloader, do not close until done"                 # dialog title
TEXT="             <b>Download</b> in progress:"        # dialog text

export ICON="/tmp/yt_dl.svg"
if [ ! -e "$ICON" ]; then
	SVG='<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="48px" height="48px" viewBox="0 0 48 48" enable-background="new 0 0 48 48" xml:space="preserve">  <image id="image0" width="48" height="48" x="0" y="0"
    xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAABGdBTUEAALGPC/xhBQAAACBjSFJN
AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAI
hklEQVRo3u1Za4hdVxX+1t7nnPuYRzKZR6ZpJ6aTtDQEYiVFpPpDf/SnRRApxaKiSEKtFFoMIqnP
9keVxidVK9gf0tDiH5GCL1IQrNFoaiZJY5JOMmnSaWaSyZ3O4957Hnuv5Y+zz50zkzsz904abCH7
su6+j3PWXt9e315r7X2Am+1mu9ne142u475MlCJSw50d3j19vcG9A32dG4JCqcv3igqkC1rphMUY
YVM1pj4VRrWDE5Pzr12tJOPVmmWAAUhO3nUABEAB8B++647eT952647eQmF7SautPtFmj2iTBg1o
oIcEZUB0akoTW4gAgoDICDDPwBQDkxZy0QBjkeXTlTg++fzoudO/OTtWxwK4NQHQu3p7Nnx/1933
9wXBJzqU/nAA3E6WtSSWxDDEWsAyhAVggYgsGC4rjEYEUpT2WgFagTwF8jTI0yJa1QzhWCzy14kw
euHjfzp40oFpGUDpmzt33Pfg0G37S4aHJUxIEgsxNmdou85uwdXk3rQC+Roq8EClIAk1/eyXo+f2
7T95ur50anQz4x+5c9unv7x56Nf+bH3QzobEUQIxFpIZf4NayjyBMEMSCw4TcBhrD/jIroG+neP1
8Hf/nZ21KwHQZa3v3r9zx6/Kc1EfR+aGGdsyKBZwlJCC3HnvLQPVX5wdO4ScF9SS6zseGLr1M+tj
u4ljk87Ge0FYYKsRBUmyu79QKCJH/TwABWDgg10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y+Sa5bCkbynv
vRuxkVr4nAex0ueb7X3X/gelYbWykrzxXAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMC0xMi0xMlQy
MDowNTo1OSswMzowMNXDXtUAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjAtMTItMTJUMjA6MDU6NTkr
MDM6MDCknuZpAAAAAElFTkSuQmCC" />
</svg>'
	echo "$SVG" > /tmp/yt_dl.svg
fi

dnd() {
kill $pdyad 2> /dev/null

dload(){
  # Starts the download and pipes the output to a loop
  # Loop is used to display the text in multi-progressbar

  $YTDL --no-check-certificate -c -f "$QUAL" --newline -i -o "$DL_DIR/%(title)s.%(ext)s" "$1" 2>&1 \
  | while read -r line; do
     if [[ "$(echo $line | grep '[0-9]*%')" ]];then
        percent=$(echo $line | awk '{print $2}')
           echo "$2:${percent%.*}"                            # sends percentage to the progress bar
     fi

     if [[ "$(echo $line | grep -E '\[download\]')" ]];then
        progress=$(echo $line | awk '{print $2,$4,$5,$6,$7,$8}')
        echo "$2:#$progress"       # sends text to the progressbar
     fi
   done
    RET_YT="${PIPESTATUS[0]}"
    if [[ "$RET_YT" = 0 ]]
      then
          echo "$2:100%"
          echo "$2:#Download completed."
          
      else
          echo "$2:#Download error."
    fi
}
export -f dload

iterate () {
IFS=" "
COUNTER="1"
DYNAMIC_COUNTER="1"

# main
# iterate through all URIs, download them in the background and 
# pipe all output simultaneously to yad
# source: http://pastebin.com/yBL2wjaY

kill $pd

cat "$URILIST" | while read -r URI;
do

    if [[ "$DYNAMIC_COUNTER" = "$MAXDLS" ]] # only download n files at a time
      then
          dload "$URI" "$COUNTER"      # if limit reached wait until wget complete
          DYNAMIC_COUNTER="1"               # before proceeding (by not sending download() to bg)
      else
          dload "$URI" "$COUNTER" &      # pass URI and URI number to download()
          DYNAMIC_COUNTER="$[$DYNAMIC_COUNTER+1]"
    fi
    COUNTER="$[$COUNTER+1]"        # increment counter

done | yad --center --image-on-top --multi-progress --on-top --auto-kill $YADBARS --title "$TITLE" \
--text "$TEXT" --window-icon "$ICON" --image "$ICON"

# ^ launch yad multi progress-bar window
rm -f "$URILIST"
}
export -f iterate

DROP_SIZE="40x40"
DROP_GEOM="+5+5"
DROP_TEXT="Drag N' Drop \nYoutube URL"

## Main GUI function
drag_main() {
yad \
        --image="$ICON" \
	--geometry="${DROP_SIZE}$DROP_GEOM" \
	--title="DragnDrop" \
	--dnd --sticky --on-top \
	--undecorated --no-buttons

}

# Drag and drop handler
drag_main | while read line
do

[ "$QUALT" ] && QLT="$QUALT!Quality Medium 360p!Quality High 720p!Quality Very High!Quality Highest!Quality Low!Quality Lowest!Audio Only" || QLT="Quality Medium 360p!Quality High 720p!Quality Very High!Quality Highest!Quality Low!Quality Lowest!Audio Only"

DL_DIR=`cat "$HOME/.config/ytdl-dnd.conf"` 

qual_opt() {
if [ "$QLT" = "Quality Medium 360p" ]; then
QUAL=18/34/43/35/5/17
fi
if [ "$QLT" = "Quality High 720p" ]; then
QUAL=22/44/35/43/18/34/5/17
fi
if [ "$QLT" = "Quality Low" ]; then
QUAL="bestvideo[height<=350]+worstaudio"
fi
if [ "$QLT" = "Quality Lowest" ]; then
QUAL="worstvideo+worstaudio"
fi
if [ "$QLT" = "Audio Only" ]; then
QUAL=140/251/250
fi
if [ "$QLT" = "Quality Very High" ]; then
QUAL="bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio"
fi
if [ "$QLT" = "Quality Highest" ]; then
QUAL="bestvideo+bestaudio"
fi
}

YTURL="$line"
case $YTURL in
*youtube.com*v%3D*) VIDID=${YTURL#*v%3D};;
  *youtube.com*v=*) VIDID=${YTURL#*v=};;
  *youtu.be*      ) VIDID=${YTURL#*.be/};;
  *               ) yad --center --no-markup --text "Not a recognized YouTube URL:\n\n${YTURL::50}" --button="gtk-close:0"; continue;;
esac
VIDID=${VIDID::11}
choice="https://www.youtube.com/watch?v=$VIDID"

down_load() {
export loglst=/tmp/test$$
export URILIST=/tmp/tMPlist$RANDOM
tail -f $HOME/.config/youtube-get.conf | yad --center --borders 5 --progress --width=400 --progress-text "Please Wait... Download will start in a moment"  --pulsate --undecorated --no-buttons &
pd=$!

while read -r url; do

qual_opt
URLFILE=$($YTDL -sci -f $QUAL --get-id --get-filename -o "%(title)s" $url | grep -v "WARNING:" 2>&1 | tee $loglst)
LOG_ERROR="$(cat $loglst 2> /dev/null | grep 'ERROR' | sed -e 's/\([[:punct:]]\)/ /g' | cut -c1-100)"
rm -f $loglst
if [ -n "$LOG_ERROR" ]; then
kill `jobs -p` $pd 2> /dev/null
yad --title="YouTube-Downloader" --center --text "  Sorry, there was an error, youtube-dl output:\n  ${LOG_ERROR} ...  " --button="gtk-close:0"
continue
fi
rm -f $loglst
#URLFILE=$(echo $url | sed 's|https://www.youtube.com/watch?v=||')

URL=$(echo "$URLFILE" | sed -n 1p)
FILE=$(echo "$URLFILE" | sed -n 2p)
#FORMAT=$(echo "$URLFILE" | sed -n 3p | awk '{ print $1 }')

FILENAME=$(echo "${FILE%.*}" | sed -e 's/\([[:punct:]]\)/ /g;s/ /-/g;s/^[-\t]*//' | tr -s '-')
ext=$(echo "${FILE##*.}")
echo -e "${URL}" > "$URILIST"

if [ $(echo "$FILENAME" | wc -c) -gt 80 ]; then
YADBAR="$(echo "$FILENAME" | busybox strings | sed 'N;s/\n//' | cut -c1-80)"
YADBARS="$YADBARS --bar=$YADBAR...:NORM"
else
YADBAR="$(echo "$FILENAME")"
YADBARS="$YADBARS --bar=$YADBAR:NORM"
fi

done <<< "$choice"

kill `jobs -p` $pd 2> /dev/null
iterate
rm -f $URILIST
}

itag_list() {
echo "$LIST" |  awk 'BEGIN {FS=" " } { print $1 }' | grep "^${1}$"
}
export -f itag_list

qual_list() {
LIST=$($YTDL -F $url | grep -v "WARNING:")

    itag_list 45
    itag_list 22
    itag_list 44
    itag_list 35
    itag_list 18
    itag_list 43
    itag_list 34
    itag_list 36
    itag_list 5
    itag_list 17
    itag_list 141
    itag_list 171
    itag_list 140
}
export -f qual_list

#if [ "$confdone" != "yes" ]; then
choices=$(yad --image="$ICON" --window-icon="$ICON" --center --height 220 --image-on-top \
 --title="YouTube-Get" \
 --form --align=center --columns=1 \
 --text="  <b>***  Download from drag n' drop YouTube url  ***</b>  \n Note: some quality options require <b>ffmpeg</b> to be installed\n (except 'Medium' and 'High')" \
 --field="Quality (if available)::CB" "$QLT" \
 --field="Downloads folder::DIR" "$DL_DIR" \
 --button="gtk-cancel:1" --button='gtk-ok:0')
ret=$?
echo $ret
[[ $ret -eq 1 ]] && unset QLT && continue
[[ $ret -eq 252 ]] && unset QLT && continue
#[[ $ret -eq 2 ]] && exec $0
echo "$choices"
choices=$(echo "$choices" | tr -d '\r')
#echo "$choices"
#choice=$(printf "$choices" | awk 'BEGIN {FS="|" } { print $1 }')
QLT=$(echo $choices | awk 'BEGIN {FS="|" } { print $1 }')
#SHOW=$(echo $choices | awk 'BEGIN {FS="|" } { print $3 }')
DL_DIR=$(echo $choices | awk 'BEGIN {FS="|" } { print $2 }')
echo "$DL_DIR" > "$HOME/.config/ytdl-dnd.conf"
DL_DIR=`cat "$HOME/.config/ytdl-dnd.conf"`
#fi
#confdone=yes
QUALT="$QLT"
down_load

unset YADBARS
done
}
export -f dnd
##### end drag n' drop section #####

dnd

Re: Using YouTube download - fails for this single occasion

Posted: Mon Dec 19, 2022 8:26 am
by Jasper

Hi @cobaka

I am afraid I cannot help you with the script.

However, I can recommend an alternative way to download the content.

@fredx181 has a super application which can do the work for you

Youtube-Get, a GUI frontend for youtube-dl (now yt-dlp)

https://www.forum.puppylinux.com/viewto ... 8903#p8903


Re: Using YouTube download - fails for this single occasion

Posted: Mon Dec 19, 2022 10:15 am
by keniv

@cobaka
@Jasper
I use both of the above and had the odd failure with both but all in all I find them both very good and would recommend them. I don't have a solution to cobaka's problem but would be interested to know what the solution/explanation is if there is one.

Regards,

Ken.


Re: Using YouTube download - fails for this single occasion

Posted: Mon Dec 19, 2022 11:00 am
by Jasper

@keniv and @cobaka

I took a peek at this and my initial thought was busybox should be looking for yt-dlp ???

also, a bit further down the script if tells me that "youtube-dl" is using it's own internal downloader.

In @fredx181 application (uses yt-dlp), I changed the option to use Aria2c as an external downloader. For me it works faster. You can also use WGet too.


Re: Using YouTube download - fails for this single occasion

Posted: Mon Dec 19, 2022 2:27 pm
by fredx181

@cobaka the problem was that the video ID (what comes after https://www.youtube.com/watch?v=) starts with a "-" https://www.youtube.com/watch?v=-meEe-jTFlk (rather exceptional, I guess)
So that way youtube-dl thinks of it as an option (that doesn't exist)
Updated the script ytdl-dnd with fix, see here: viewtopic.php?p=12313#p12313
Also note that youtube-dl is very much outdated (slow download speed), so I'd recommend to use the other attached script ytdlp-dnd (makes use of yt-dlp), but needs python3, see more info at link above.


Re: Using YouTube download - fails for this single occasion

Posted: Tue Dec 20, 2022 12:02 am
by cobaka

Hello @fredx181 and woof!

I think you're onto something about the "-" character. Recently (can't remember the detail) I did something with file-names beginning with hash "#". Nada, zip, nothing. Decided the file-name was passed to the shell where "#" was seen as 'comment'. I removed "#" and waddayaknow? Everything worked as expected.

Even Linux/Unix has foibles!
Thank you for this observation. I should be able to deal with '-' using a back-slash pre-fix.
Going back to the original video, "A country fair in Tasmania" - this ten minute video - is superb. Well scripted, nicely edited and has captured the essence of the Huon Valley, Tasmania. Bushmen, on their day off, doing what they do well.

Result of adding back-slash prefix before "-". "Download error".
I will explore the possibility of intercepting the video stream and saving to disk.
Also - other suggestions made by other 'woofers'.
Thinking about this - I intended to show this to my neighbour (who grew up in Tasmania but is fairly-well house-bound at the moment). Life will go on if it doesn't happen!

собака


Re: Using YouTube download - fails for this single occasion

Posted: Tue Dec 20, 2022 11:30 am
by fredx181

@cobaka There seems to be a misunderstanding, not ?
I recognized the code from your first post that it's mine from here: viewtopic.php?p=12313#p12313
And yesterday replaced the attached ytdl-dnd there with a fix for that "dash" problem.

Details:
The fix is on line 248
Replaced this:
echo -e "${URL}" > "$URILIST"
with this:
echo -e "https://www.youtube.com/watch?v=${URL}" > "$URILIST"
(the complete url instead of only the id, normally it works with only the ID, but not in case of starting with a dash)

See also issue here: https://github.com/ytdl-org/youtube-dl/issues/4800

In your case with the video "A country fair, Tasmanian style", using only the ID doesn't work as it starts with a "-", so youtube-dl -meEe-jTFlk fails to download,
make it youtube-dl https://www.youtube.com/watch?v=-meEe-jTFlk and it works.
(or as stated on the github issue, this would work too youtube-dl -- -meEe-jTFlk