4

I tried to use a zenity progress bar with cclive. I'm writting a script to download web videos files and I wanna see the progression of the download.

But when I try something like

$cclive <url> 2>&1 | zenity --progress

But when I execute the command line but it not seems to work. Any idea of how I can do that ?

BR,

[Edit]

cclive have this kind of output :

cclive http://www.youtube.com/watch?v=youtubevideo

Checking ... .......... ..........done. youtubevideo.flv 2.5M 75.8K/s 00:09:29 5%

So I need to send the last part to sdout but I dont know how. Else and about pulsate, we can't see th progression with this option, and I really need it... So I will not using pulsate for this script.


think that the paste | zenity --progress after commands - will not work.

You know that it's loaded only at the end of downloading.

I try to use zenity with --percentage parameter, and i know the best way to check state of process.

In my script I know size of file.

size_t=$theoretical_size_of file     # I don't know where are from you take FULL size     of your file. I know it in myself script.
size_r=`du -b /tmp/$filename`
perc=$[$size_t/$size_r*100] 

Where should i write zenity --progress --percentage=$perc

AND i think that it should be a loop, cause du -b continiously changing...

Winael
  • 256

1 Answers1

2

I don't know how cclive works, but in order to make zenity display a progress bar, it needs to send percentages to stdout.

Here's an example:

# This works:
(for i in $(seq 0 3 100); do echo "$i"; sleep 0.1; done) | zenity --progress

# This doesn't:
(for i in $(seq 0 3 100); do echo "hi"; sleep 0.1; done) | zenity --progress

Unless you can arrange for cclive to do that, you'll have to settle for

zenity --progress --pulsate

Edit

Based on the comments, here's some additional info. I can't give you an exact answer since apparently cclive is broken on Maverick. At any rate, I only get errors when I try to use it.

The first thing you need to do is to get cclive to print a percentage somewhere. I'm assuming the logfile will print such a percentage, but I can't test it. Then, you need to parse that output and send it to zenity. Here's an example (untested, or course) script:

#!/bin/bash

url="$1"
tmp="/tmp/cclive.log"

mkfifo "$tmp"
cclive --background --logfile="$tmp" "$url"
egrep '[0-9]+%$' < "$tmp" | zenity --progress
rm "$tmp"

If cclive's output is in a different format, just adjust the script as appropriate. If cclive doesn't dump percentages to the logfile, try changing the cclive command to:

cclive "$url" > "$tmp" &

One final thing: You probably shouldn't send stderr out stdout (2>&1). Zenity will consume stdout, but you probably don't want it to eat all error messages.

Edit 2

You might have to throw awk in somewhere in the pipeline so you can isolate the percentage. The basic syntax is:

awk '{print $1}' # change $1 to the correct space-separated field

In testing, I couldn't make it work correctly, but since I can't make cclive work, I can't really troubleshoot it.