You are not logged in.

#1 2016-06-07 10:21:31

misko_2083
Member
Registered: 2016-05-24
Posts: 83

yad wrapper for youtube-dl

Thanks to a script from Glutanimate for wget, I've managed to re-write damo's youtube script and make simultaneous downloads from youtube possible.
Haven't tested on Hydrogen yet, but I've already sent the pull request to damo's github.
https://github.com/capn-damo/scripts/pulls

some screenshots:
QA7yr8Eb.jpg
3WG9xwLb.jpg
ek7h3leb.jpg

BTW, this is off topic but I just found this little time script in my github gist. Totally forgot about it big_smile

#!/bin/bash
while true
 do 
   echo "1:#$(date '+%T')"
   echo "2:#$(date '+%D %a')"
   sleep 1  # update interval
 done | yad --multi-progress --title="Time" \
       --bar="Time":NORM --bar="Date":NORM \
       --window-icon="clock" --image="clock"

Edit: P.S. there has to be an easier way to automate attaching of the image thumbnails on the forum smile
You could make a tutorial for posting image thumbs from the various image hosting services at least.

Last edited by misko_2083 (2016-06-07 10:34:24)

Offline

#2 2016-06-09 09:59:21

shot-in-the-head
Member
Registered: 2015-10-28
Posts: 61

Re: yad wrapper for youtube-dl

doesn't work for me, I am just getting the video with no sound.
The audio only part works.
Damo's version also produces video with no sound for me.
Just using the cli works though eg
ytdl https://www.youtube.com/watch?v=Y4_Mi-EwFqw

Last edited by shot-in-the-head (2016-06-10 12:05:09)

Offline

#3 2016-06-10 14:46:28

misko_2083
Member
Registered: 2016-05-24
Posts: 83

Re: yad wrapper for youtube-dl

^ It's fixed now.

Offline

#4 2016-06-11 10:59:24

shot-in-the-head
Member
Registered: 2015-10-28
Posts: 61

Re: yad wrapper for youtube-dl

where can I get the fixed script then? as the one on Damo's github was last changed 16days ago.

Offline

#5 2016-06-11 15:15:22

damo
....moderator....
Registered: 2015-08-20
Posts: 4,224

Re: yad wrapper for youtube-dl

shot-in-the-head wrote:

where can I get the fixed script then? as the one on Damo's github was last changed 16days ago.

My script is working fine for me wink

@misko_2083 forked it, so you can find his version here: Misko-2083/scripts


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#6 2016-06-11 17:46:11

shot-in-the-head
Member
Registered: 2015-10-28
Posts: 61

Re: yad wrapper for youtube-dl

ok tried latest Misko version, same problem. but not a big deal as another script I found elsewhere works fine I will just adapt that to work with yad

Offline

#7 2016-09-03 00:27:25

misko_2083
Member
Registered: 2016-05-24
Posts: 83

Re: yad wrapper for youtube-dl

Offline

#8 2017-05-03 17:34:33

misko_2083
Member
Registered: 2016-05-24
Posts: 83

Re: yad wrapper for youtube-dl

Damo, I've tried to make just one window for this.
It works, checks for youtube-dl version at the begining and downloads the video.
The only problem is: when the download is active, and you close the dialog it continues to download. The stop button works.

#!/bin/bash

export ytdownload='@bash -c "download_video %1"'

# We need this to store the youtube PID
export ytdpid=$(mktemp -u --tmpdir ytpid.XXXXXXXX)

export ytdpipe=$(mktemp -u --tmpdir ytd.XXXXXXXX)
mkfifo "$ytdpipe"
export ytdpipetwo=$(mktemp -u --tmpdir ytd2.XXXXXXXX)
mkfifo "$ytdpipetwo"

trap "rm -f $ytdpipe $ytdpipetwo $ytdpid" EXIT

ytdkey=$(($RANDOM * $$))

function download_video
{
  echo "2:@disable@"
# Check if the URL is valid with the spider
if wget -q --spider "$1"; then
  echo "#Preparing to download" >> "$ytdpipe"

   >"$ytdpid"
   while read line; do
     if [[ "$(echo $line | grep '[0-9]*%')" ]];then
        percent=$(echo $line | awk '{print $2}')
        echo "${percent%.*}%" >> "$ytdpipe"
     fi

     if [[ "$(echo $line | grep '\[download\]')" ]];then
        progress=$(echo $line | awk '{$1=""; print $0}')
        echo "#$progress" >> "$ytdpipe"
     fi
   done < "$ytdpipetwo" &
   LOOP_PID="$!"

    youtube-dl -f 'bestvideo [ext = mp4] + bestaudio [ext = m4a] / bestvideo + bestaudio' --merge-output-format mp4 --newline -i -o "%(title)s.%(ext)s" "$1" 2>&1 >> $ytdpipetwo & echo $! > "$ytdpid"
    wait $!   # Wait also returns exit status

    if [[ "$?" = 0 ]]
      then
         echo "100%" >> "$ytdpipe"
         echo "#Download completed." >> "$ytdpipe"
         kill "$LOOP_PID"
    elif [[ ! -s "$ytdpid" ]]; then
         echo "#Download canceled" >> "$ytdpipe"
         kill "$LOOP_PID"
    else
         echo "#Download error" >> "$ytdpipe"
         kill "$LOOP_PID"
    fi
else
    echo "#Invalid URL" >> "$ytdpipe"
fi

    echo "2:$ytdownload"
}
export -f download_video

function ytdl_version () {
    echo "#Checking youtube-dl version" >> "$ytdpipe"
    wget --spider --user-agent="Mozilla/5.0 Gecko/20100101" --timeout=30 -q "https://rg3.github.io/youtube-dl/" -O /dev/null
    if [[ "$?" -ne "0" ]]; then
       echo "#Can't connect to youtube-dl server site" >> "$ytdpipe"
    fi
    ytdlcv=$(youtube-dl --version)
    ytdllv=$(wget -O- -q "https://rg3.github.io/youtube-dl/update/LATEST_VERSION")
    if [[ "$ytdlcv" == "$ytdllv" ]]; then
       echo "#youtube-dl is up-to-date"  >> "$ytdpipe"
    else
       echo "#youtube-dl update is available" >> "$ytdpipe"
    fi
}

function get_pid_and_kill () { # Thank you fredx181 for this idea
if [[ -s "$ytdpid" ]]; then
  BCKUPID="$(<$ytdpid)"
  >"$ytdpid"
  kill $BCKUPID 2>/dev/null
fi
}
export -f get_pid_and_kill

exec 3<> $ytdpipe
exec 4<> $ytdpipetwo

yad --plug="$ytdkey" --tabnum=1 --form --field "Enter video url":CE "https://www.youtube.com/" \
    --image=browser-download --field="Download!browser-download:fbtn" "$ytdownload" &

yad --plug="$ytdkey" --tabnum=2 --window-icon="$ICON" \
      --progress  --borders=6 <&3 &

  ytdl_version &

yad --paned --key="$ytdkey"  \
    --button="Stop":'bash -c "get_pid_and_kill" 2>/dev/null'  --text="" --width=500 --height=200 \
    --title=$"YouTube Downloader" --window-icon="$ICON" --center

exec 3>&-
exec 4>&-

Offline

#9 2017-05-04 05:13:22

ohnonot
...again
Registered: 2015-09-29
Posts: 3,048
Website

Re: yad wrapper for youtube-dl

i just had this idea... what if a yad wrapper for youtube-dl also included downloading the newest version of youtube-dl itself?

Offline

#10 2017-05-13 13:21:14

misko_2083
Member
Registered: 2016-05-24
Posts: 83

Re: yad wrapper for youtube-dl

^That would be cool. smile

Offline

Board footer

Powered by FluxBB