Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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...

share|improve this question

1 Answer 1

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.

share|improve this answer
    
Thx mssever, In fact 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 ;) –  Winael May 6 '11 at 23:56
    
@Winael: I've updated my answer to reflect the additional information you gave. Please edit the original question. –  Scott Severance May 7 '11 at 8:33
    
Hi Scott,Thx for your answer. I tried it yesterday but it didn't work. The progress bar don't progress... So tonight I'll try to redirect the outpout of egrep/awk command to a file to check if my args is good to isolate the percents. I'll let you know... –  Winael May 9 '11 at 8:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.