You are not logged in.

#251 2021-10-23 02:03:30

sleekmason
zoom
Registered: 2018-05-22
Posts: 691
Website

Re: The great yad hacking thread

Figured out a good fix. Put the commands into a separate script to call from the yad script.  Works quite well.  In this case, I'm using toggles to individually turn on and off the conky's like so.

#!/bin/bash

yad --title "Conky" --button=gtk-close:1 --form --center --on-top --width=250 \
--height=305 --text="\n CHOOSE YOUR\n SELECTIONS. \n" --text-align=center \
--window-icon=applications-system \
    --form \
    --field="Conky Light":BTN "toggle.conky-light" \
    --field="Conky Dark":BTN "toggle.conky-dark" \
    --field="Conky None":BTN "toggle.conky-none" \
    --field="Restart Conky":fbtn "killall -SIGUSR1 conky" \
    --field="Kill Conky":fbtn "killall conky" \

And then for the toggle:

#!/bin/bash
# conky-light - toggle individual conky on/off

if pgrep -f conky-light.conf > /dev/null; then
    pkill -f conky-light.conf
else
    conky -c $HOME/.config/conky/conky-light.conf
fi

This gives all sorts of control from the toggle script.

Last edited by sleekmason (2021-10-23 02:16:44)

Offline

#252 2021-10-23 08:32:44

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

Re: The great yad hacking thread

malm wrote:

@Misko - hope you're getting better.

I came across gtkdialog and thought you might be interested.

There is a cool script here wwals by 01micko with some screenshots.

Thanks, I'm familiar with gtkdialog and heard about micko. Actually I may have trolled him once or twice :-D


They use force, to make you do, what the deciders, have decided you must do!

Offline

#253 2021-10-23 08:54:42

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

Re: The great yad hacking thread

sleekmason wrote:

Figured out a good fix. Put the commands into a separate script to call from the yad script.  Works quite well.  In this case, I'm using toggles to individually turn on and off the conky's like so.

Instead of files one function would do. It needs to be exported to be available to bash subshells or children as they are called.

#!/bin/bash

toggle_conky () {
#  toggle individual conky on/off

if pgrep -f ${1}.conf > /dev/null; then
    pkill -f ${1}.conf
else
    conky -c $HOME/.config/conky/${1}.conf
fi
}
export -f toggle_conky

yad --title "Conky" --button=gtk-close:1 --form --center --on-top --width=250 \
--height=305 --text="\n CHOOSE YOUR\n SELECTIONS. \n" --text-align=center \
--window-icon=applications-system \
    --form \
    --field="Conky Light":BTN "bash -c 'toggle_conky conky-light'" \
    --field="Conky Dark":BTN "bash -c 'toggle_conky conky-dark'" \
    --field="Conky None":BTN "bash -c 'toggle_conky conky-none'" \
    --field="Restart Conky":fbtn "killall -SIGUSR1 conky" \
    --field="Kill Conky":fbtn "killall conky" 

I'm not sure if I messed up the quoting somewhere, I'm typing this on a phone.
I didn't start the computer for a month and don't feel like switching it on yet.

Last edited by misko_2083 (2021-10-23 08:55:16)


They use force, to make you do, what the deciders, have decided you must do!

Offline

#254 2021-10-23 13:20:28

sleekmason
zoom
Registered: 2018-05-22
Posts: 691
Website

Re: The great yad hacking thread

@misko_2083  -  Brilliant!  Exactly what I was looking for but didn't know how to accomplish:)  Thank you for narrowing it down!

Offline

#255 2021-10-23 18:51:57

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

Re: The great yad hacking thread

sleekmason wrote:

@misko_2083  -  Brilliant!  Exactly what I was looking for but didn't know how to accomplish:)  Thank you for narrowing it down!

What a surprise, it actually worked. big_smile
Hurray!
I was beginning to question my memory. In the hospital the nurse has asked me where did I go to school.
Nothing came to my mind, nada, blank. And I'm not that old to start forgetting.
She measured my oxigen twice. big_smile
Then another time doctor asked me when did I get my vaccine shots.
Could not remember that either. I told her in March and April but really couldn't remember.
I think I wrote that on this forum too. When I checked the papers, it turned out in May 31st and June 21st.
So after 3 months after vaccination I got covid.


They use force, to make you do, what the deciders, have decided you must do!

Offline

#256 2021-11-27 00:55:46

achim
Member
Registered: 2019-08-23
Posts: 39

Re: The great yad hacking thread

Hi,

The following code is a downloader version that I have further developed with yt-dlp, an alternative to youtube-dl. It works so far, only with the progress indicator in lines 30 to 40 I have a problem.
Perhaps someone from the experts present here (misko_2083 or damo) can check where the error is.
I am also interested in whether the output (e.g. lines 52, 55, 81 etc.) can also be colored.

Thanks very much

#!/bin/bash
#
fd="/home/achim/bin/icons"
TITLE="Video Downloader by Achim"                 # dialog title
#
cd $HOME/Videos/Youtube-Videos
#
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 "#Download wird vorbereitet..." >> "$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="$!"
#
    yt-dlp -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' "$1" 2>&1 >> $ytdpipetwo & echo $! > "$ytdpid"
    
    #yt-dlp -f 'bv,ba' -o '%(title)s.f%(format_id)s.%(ext)s' "$1" 2>&1 >> $ytdpipetwo & echo $! > "$ytdpid"
    #yt-dlp -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 $!
#
    if [[ "$?" = 0 ]]
      then
         echo "100%" >> "$ytdpipe"
         echo "#Download erfolgreich abgeschlossen!" >> "$ytdpipe"
         kill "$LOOP_PID"
    elif [[ ! -s "$ytdpid" ]]; then
         echo "#Download abgebrochen!" >> "$ytdpipe"
         kill "$LOOP_PID"
    else
         echo "#Download Fehler!" >> "$ytdpipe"
         kill "$LOOP_PID"
    fi
else
    echo "#ungültige URL!" >> "$ytdpipe"
fi
#
    echo "2:$ytdownload"
}
export -f download_video
#
function ytdl_version () {
    echo "#Versionscheck der letzten Version" >> "$ytdpipe"
    sudo wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /tmp/yt2-dlp && sudo chmod a+rx /tmp/yt2-dlp /dev/null
    if [[ "$?" -ne "0" ]]; then
       echo "#Kann keine Verbindung zum Server herstellen!" >> "$ytdpipe"
    fi
    sleep 3
    ytdlcv=$(yt-dlp --version)
    ytdllv=$(/tmp/yt2-dlp --version)
    

    if [[ "$ytdlcv" == "$ytdllv" ]]; then
    echo "#yt-dlp ist aktuell - Version $ytdlcv " >> "$ytdpipe"
    else
    echo "#Es ist ein neues yt-dlp Update verfügbar!" >> "$ytdpipe"
    sudo cp -a /tmp/yt2-dlp  /usr/local/bin/yt-dlp    
    echo "Die yt-dlp wird aktualisiert..." | GTK_THEME="gtk-3.0" yad --borders=50 \
   --window-icon="$fd/Movies-icon24.png" --title="Update" \
   --text-info --posx=700 --posy=600 --width=540 --no-buttons --timeout=4 --timeout-indicator=Bottom
   echo "#Es wurde die neueste yt-dlp Version $ytdllv installiert!" >> "$ytdpipe"
    sleep 5   
    fi
 #   
}
#
function get_pid_and_kill () {
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
#
GTK_THEME="gtk-3.0" yad --plug="$ytdkey" \
	--tabnum=1 \
	--image-on-top \
    --image="$fd/Gnome-Video-X-Generic-64.png" \
	--form \
	--field "Bitte hier die Video-Url eingeben: ":CE "https://www.youtube.com/" \
    --command=CMD \
    --field="Download!$fd/Gnome-Emblem-Downloads-32.png:fbtn" "$ytdownload" &    
#
GTK_THEME="gtk-3.0" yad --plug="$ytdkey" \
	--tabnum=2 \
    --progress \
    --borders=6 <&3 &
#
  ytdl_version &
#
GTK_THEME="gtk-3.0" yad --paned --key="$ytdkey"  \
    --width=1500 \
	--height=400 \
    --title="$TITLE" \
	--center --borders=6 \
    --text="" \
    --window-icon="$fd/youtube-dl-gui64.png" \
	--button="Download stoppen!$fd/Status-dialog-error-icon24.png":"bash -c get_pid_and_kill" \
    --button=" Schließen!$fd/Apps-session-logout-icon.png":1
#
#
if exist file *.part &>/dev/null
then
rm *part*
fi 
#
ret=$?
#
if [[ $ret -eq 252 ]]; then
    if file *.part &>/dev/null
    then
    rm *part*
    fi 
fi
#
[[ $ret -eq 1 ]] && exit 0
#
exec 3>&-
exec 4>&-
#
get_pid_and_kill
exit 0

Last edited by achim (2021-11-27 02:19:41)

Offline

#257 2021-11-30 06:33:09

achim
Member
Registered: 2019-08-23
Posts: 39

Re: The great yad hacking thread

@misko_2083
I am currently reading about your illness and, of course, I wish you a speedy recovery. You are probably still young and you will probably survive this terrible virus story better than an older person. I belong to this group, which is why there was also the booster vaccination.

All the best for you and get really well again.

Offline

#258 2021-12-10 16:13:28

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

Re: The great yad hacking thread

achim wrote:

@misko_2083
I am currently reading about your illness and, of course, I wish you a speedy recovery. You are probably still young and you will probably survive this terrible virus story better than an older person. I belong to this group, which is why there was also the booster vaccination.

All the best for you and get really well again.

Well, thank you achim, I'm very good now.
Yt-dlp is a fork of youtube-dl, so everything should be the same for noe.
From a quick look at the script I think this line

    yt-dlp -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' "$1" 2>&1 >> $ytdpipetwo & echo $! > "$ytdpid"

is missing --newline switch to print line buffered ouput and the script to read it.

Last edited by misko_2083 (2021-12-10 16:16:14)


They use force, to make you do, what the deciders, have decided you must do!

Offline

#259 2021-12-11 00:04:23

achim
Member
Registered: 2019-08-23
Posts: 39

Re: The great yad hacking thread

misko_2083 wrote:

Well, thank you achim, I'm very good now.

That makes me very happy!

    yt-dlp -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' "$1" 2>&1 >> $ytdpipetwo & echo $! > "$ytdpid"

No, that's a misunderstanding. This line (number 43) is present in the script. Except for the progress bar in lines 30 to 40, almost everything works. I can't find the bug.

I also asked whether the output (e.g. lines 52, 55, 81 etc.) could also be designed in color.

Offline

#260 2021-12-11 03:52:59

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

Re: The great yad hacking thread

change line 43 to this

 yt-dlp --newline -f 'bv*[ext=mp4]+ba[ext=m4a]/b[ext=mp4] / bv*+ba/b' "$1" 2>&1 >> $ytdpipetwo & echo $! > "$ytdpid"

The text color can be shown in the log using the pango markup language.
https://docs.gtk.org/Pango/pango_markup.html

Log is described in the manual

man yad
       --enable-log[=TEXT]
              Show log window. This window gathers all of  lines  from  stdin,
              started  from  #  instead  of setting appropriate progress text.
              Optional argument TEXT is a text label for window expander.

       --log-on-top
              Place log window above progress bars.

       --log-expanded
              Start with expanded log window.

       --log-height
              Set the height of log window.

They use force, to make you do, what the deciders, have decided you must do!

Offline

#261 2021-12-12 00:51:41

achim
Member
Registered: 2019-08-23
Posts: 39

Re: The great yad hacking thread

Thank you @misko_2083, the progress bar is now working. In order to achieve a colored text output, however, I still have to experiment a little.

Last edited by achim (2021-12-12 00:53:09)

Offline

Board footer

Powered by FluxBB