You are not logged in.

#1 2016-05-24 05:42:19

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

The great yad hacking thread

1

Last edited by kleiner_hussar (2016-06-02 10:40:50)

Offline

#2 2016-05-24 05:56:40

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

Re: The great yad hacking thread

Cheeky boy - you've been peeking in my github repo big_smile

Good idea for a thread though. Tutorials and examples for yad, which are much use, are hard to find (although the yad wiki now has a lot more examples). I've spent hours trawling through a google group thread, which seemed to be the main "resource" for answers to problems.


Be Excellent to Each Other...

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

Offline

#3 2016-05-24 06:16:34

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

2

Last edited by kleiner_hussar (2016-06-02 10:41:02)

Offline

#4 2016-05-24 10:41:19

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

3

Last edited by kleiner_hussar (2016-06-02 10:41:14)

Offline

#5 2016-05-24 11:39:51

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 147

Re: The great yad hacking thread

Hey this is really cool!

I tried to get the radio working immediately but running it from cli it looks like this

naik@HP-D2:~$ sh ~/scripts/radio
Gtk-Message: GtkDialog mapped without a transient parent. This is discouraged.
/home/naik/scripts/radio: 39: /home/naik/scripts/radio: [[: not found
/home/naik/scripts/radio: 41: /home/naik/scripts/radio: [[: not found
/home/naik/scripts/radio: 46: /home/naik/scripts/radio: [[: not found

[httpget.c:172] error: Error reading from socket or unexpected EOF.

[httpget.c:640] error: readstring failed

[mpg123.c:611] error: Access to http resource http://swr-mp3-s-swr1bw.akacast.akamaistream.net/7/395/137133/v1/gnl.akacast.akamaistream.net/swr-mp3-s-swr1bw failed.

running it using the mocp server works just fine though it is not shown in my mocp related conky section for any reason.
can you maybe help me to fix at last one of this problems so i can listen to the radio without being annoyed by this minor troubles?


"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub

Offline

#6 2016-05-24 11:45:05

xaos52
The Good Doctor
From: Planet of the @pes
Registered: 2015-09-30
Posts: 695

Re: The great yad hacking thread

Use 'bash' to launch the script in stead of 'sh'
[[ is a bashism

Offline

#7 2016-05-24 11:57:44

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

4

Last edited by kleiner_hussar (2016-06-02 10:41:27)

Offline

#8 2016-05-24 12:41:02

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 147

Re: The great yad hacking thread

kleiner_Husar wrote:

Run the script as an application

Thats what i did. I just checked back, when nothing happend after clicking "ok". Things work quiet well now. As it seems most of the links won`t work, which is sad but i`ll try to get back with an updated copy of the script..
Great work anyways. I realy like it a lot!

...und danke für den Hinweis auf yad, das hab ich bisher noch gar nicht so richtig wahr genommen.

naik --greetz


"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub

Offline

#9 2016-05-24 12:49:16

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

5

Last edited by kleiner_hussar (2016-06-02 10:41:39)

Offline

#10 2016-05-24 18:04:17

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

6

Last edited by kleiner_hussar (2016-06-02 10:41:50)

Offline

#11 2016-05-24 19:42:46

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

Re: The great yad hacking thread

Helper functions for BunsenLabs yad scripts

For BunsenLabs yad scripts, @johnraff has included a time-saver 'includes' file, which has several yad utility functions. Add this at the beginning of a script which uses yad, to source them:

BL_COMMON_LIBDIR='/usr/lib/bunsen/common'

if ! . "$BL_COMMON_LIBDIR/yad-includes" 2> /dev/null; then
    echo "Error: Failed to source yad-includes in $BL_COMMON_LIBDIR" >&2
    exit 1
fi

The 'yad-includes' file has the following Help comments:

# These are global options for all the yad functions defined below.
# You can add to them for the duration of your script with something like:
# yad_common_args+=(--image=debian)
# Override options already set with, eg:
# yad_common_args+=(--borders=30)
# Unset options with 0, eg:
# yad_common_args+=(--center=0)

yad_common_args=('--window-icon=distributor-logo-bunsenlabs' '--center' '--borders=20')
yad_popup_args=('--undecorated' '--fixed' '--on-top')

# Call these functions as shorthand for simple popups etc.
# Append any options you want to add, change or unset.
# Plain strings will be regarded as --text eg:
# yad_info "It's not as bad as you think."
# Buttons are identified by their return values
# so their labels can be changed, eg:
# yad_error 'Something went wrong.' --button='Resigned acceptance':0
# New buttons will be added on the right, eg:
# yad_question 'Continue?' --button='Tell me more':2

Be Excellent to Each Other...

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

Offline

#12 2016-05-25 06:31:47

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

6

Last edited by kleiner_hussar (2016-06-02 10:42:06)

Offline

#13 2016-05-25 10:19:01

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

7

Last edited by kleiner_hussar (2016-06-02 10:42:22)

Offline

#14 2016-05-25 10:33:39

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

8

Last edited by kleiner_hussar (2016-06-02 10:42:32)

Offline

#15 2016-05-25 18:32:00

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

Re: The great yad hacking thread

Problem with yad --progress sad

I am re-writing my youtube-dl wrapper script and have run into an issue with the progress window. "--auto-kill" should kill the parent process if the Cancel button is pressed, and I want to use this to clean up the .part file if the download is interrupted, by using the $PIPESTATUS shell var.

.....
# Run youtube download, pipe to progress dialog
youtube-dl -i -o "$SAVEDIR/%(id)s.%(ext)s" $URL | yad --progress --pulsate \
            --progress-text="" \
            --auto-kill --auto-close \
            --window-icon=distributor-logo-bunsenlabs --borders=10 \
            --center --undecorated --text="Youtube downloader:
.....

Raw script: https://raw.githubusercontent.com/capn- … er/youtube

However the Cancel button is ineffective (and the window is blocked until the download completes), as soon as the .part file starts to be written. I presume that a second youtube-dl process starts when the data is being written, and the first one waits until it completes.

Any clever people know how to troubleshoot this?


Be Excellent to Each Other...

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

Offline

#16 2016-05-25 18:41:46

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

Re: The great yad hacking thread

@damo Try this:

.....
# Run youtube download, pipe to progress dialog
youtube-dl -i -o "$SAVEDIR/%(id)s.%(ext)s" $URL | (if ! yad --progress --pulsate \
            --progress-text="" \
            --auto-close \
            --window-icon=distributor-logo-bunsenlabs --borders=10 \
            --center --undecorated --text="Youtube downloader:" \
            --button="Cancel:1"; then killall $(basename $0); exit; fi)
.....

Offline

#17 2016-05-25 19:20:49

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

Re: The great yad hacking thread

^ Exact same behaviour I'm afraid sad


Be Excellent to Each Other...

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

Offline

#18 2016-05-25 19:57:29

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

9

Last edited by kleiner_hussar (2016-06-02 10:42:44)

Offline

#19 2016-05-25 20:20:32

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

Re: The great yad hacking thread

Thanks for trying this. With your code I'm still getting a non-responsive dialog once the .part file has started to be written.

My first script had a progress function, which was completely separate from the youtube-dl process. Piping a command to the progress dialog is a lot more elegant, but obviously it is depending on the behaviour of the command.

Maybe I'll go back to my first approach hmm

BTW For numerical testing my understanding is that it is recommended to use the "((...))" syntax

(( $ret == 1 ))

Be Excellent to Each Other...

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

Offline

#20 2016-05-26 03:42:02

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 3,438
Website

Re: The great yad hacking thread

kleiner_hussar wrote:

I thought I figured it out (=the yad includes), but not. Grrr

Try it in a terminal first. Just run

. /usr/lib/bunsen/common/yad-includes

then try a simple dialog like

yad_info

and see if the window comes up. Then you can try out the different options and figure out where the problems were.

And see /usr/bin/bl-dropbox-pipemenu for some working examples.

Last edited by johnraff (2016-05-26 03:44:26)


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
In case you forget, the rules.

Online

#21 2016-05-26 04:58:20

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

9

Last edited by kleiner_hussar (2016-06-02 10:42:56)

Offline

#22 2016-05-26 05:24:57

kleiner_hussar
Member
From: Traunstein, Germany
Registered: 2016-04-25
Posts: 82

Re: The great yad hacking thread

10

Last edited by kleiner_hussar (2016-06-02 10:43:07)

Offline

#23 2016-05-26 11:07:21

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

Re: The great yad hacking thread

There will be broken pipe error but it will work big_smile

...
# Run youtube download, pipe to progress dialog
youtube-dl --newline -i -o "$SAVEDIR/%(id)s.%(ext)s" $URL \
| while read -r line || [[ -n "$line" ]]; do
   if [[ "$(echo $line | grep '[0-9]*%')" ]];then
      percent=$(echo $line | grep -Eo "[^[-+]?[0-9]+\.?[0-9]]*$*%" | tr -d '%')
      printf "%.f\n" "$percent"
   fi 
      echo "#$line"
done | yad --progress --auto-close \
            --window-icon=distributor-logo-bunsenlabs \
            --text="Youtube downloader:" --button="gtk-cancel:1"
...

--auto-kill seems to kill the parent process

Offline

#24 2016-05-26 12:10:23

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

Re: The great yad hacking thread

I've figured it out. It looks hacky but it works as it should. LoL
Progress bar is working and it displays ETA.
Used a file to determine if the progress is canceled.

#!/bin/bash
##
## yad dialog to download and save youtube video
##
## written by <damo> May 2016

if ! type youtube-dl &>/dev/null;then
    DLG=$(yad --form --window-icon=distributor-logo-bunsenlabs \
        --borders=10 \
        --text="   youtube-dl not found\n\n  Install it first and run the script again" --button="OK" \
        --title="Youtube downloader" --center --undecorated \
    )
    exit
fi

while :; do
    ENTRY=$(yad --form --window-icon=distributor-logo-bunsenlabs --center \
        --borders=10 \
        --title="Youtube downloader" \
        --field="Enter Save directory:DIR" \
        --field="Enter youtube url" \
        --field="Play file when downloaded:CHK" \
        )
    RET=$?

    OIFS=$IFS # save Internal Field Separator
    IFS="|" # separator is "|" in returned choices
    i=0
    retChoice=()

for ret in $ENTRY;do 
    retChoice[$i]="$ret"
    i=$(($i+1))
done

    IFS=$OIFS # reset IFS back to default

    SAVEDIR=${retChoice[0]} # directory path
    URL=${retChoice[1]}
    URL=${URL##*'='}
    PLAY=${retChoice[2]}
    
    if (( $RET == 1 ));then
        exit
    fi
    if [[ -z $SAVEDIR ]] || [[ -z $URL ]];then
        yad --form --text="Complete both fields" --center --window-icon=distributor-logo-bunsenlabs
    else
        break
    fi
done

STRING=$(date +%s | sha256sum | base64 | head -c 8)
EXIT=/tmp/$STRING

# Run youtube download, pipe to progress dialog
( ( youtube-dl --newline -i -o "$SAVEDIR/%(id)s.%(ext)s" $URL )& echo $! ) \
| (  read PIPED_PID; while read -r line || [[ -n "$line" ]]; do
   if [[ "$(echo $line | grep '[0-9]*%')" ]];then
      percent=$(echo $line | grep -Eo "[^[-+]?[0-9]+\.?[0-9]]*$*%" | tr -d '%')
      printf "%.f\n" "$percent"
   fi 
      echo "#$line"
done | yad --progress \
            --auto-close \
            --window-icon=distributor-logo-bunsenlabs --borders=10 \
            --center --undecorated --text="Youtube downloader:" --button="Cancel:1" ||  echo "rm" > $EXIT; kill $PIPED_PID )

if [[ -f $EXIT ]];then
    rm -f $EXIT
    rm $(find $SAVEDIR -type f -name $URL.* | grep part) &>/dev/null
    notify-send -t 3000 --icon "dialog-info" "Download cancelled"
    exit
fi

if [[ $PLAY = TRUE ]] &>/dev/null;then
    xdg-open "$SAVEDIR/$URL".*
fi

exit 0

Last edited by misko_2083 (2016-05-26 12:35:46)

Offline

#25 2016-05-26 13:14:38

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

Re: The great yad hacking thread

Thanks team smile

I've used @misko_2083's method and trimmed it a little. There are still too many pipes/processes created, so I'm sure it can be made much more efficient for the purists, but it works!

Added an audio-only option...
youtube.jpg

github script

NB youtube-dl can manage the downloading of videos from many more sites than just youtube wink

Last edited by damo (2016-05-26 14:12:57)


Be Excellent to Each Other...

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

Offline

Board footer

Powered by FluxBB