1

I've seen many similar questions, but none really works for me.
I have a simple script that downloads latest 2 video episodes from one channel, so I can watch them later on mobile in offline mode. It uses yt-dlp command with -w switch not to overwrite if video exists. I would like to colorize "Destination" so I see more clearly file name, and "has already been downloaded" if file has already been downloaded.
So my script looks like this:

    cd /tmp
EPI=$(curl -s https://rumble.com/c/robbraxman | grep  -m 2 "href=/\v"| awk '{print $5}' |awk -F\> '{print $1}')
for i in ${EPI//href=/http://rumble.com}; do
  printf "\e[1;38;5;212m Downloading \e[1;38;5;196m $i\e[m \n"
  yt-dlp -f mp4-480p -w $i
done

output of the yt-dlp is like:

[Rumble] Extracting URL: http://rumble.com/v2820uk-let-me-show-you-brax.me-privacy-focused-app.html
[Rumble] v2820uk-let-me-show-you-brax.me-privacy-focused-app.html: Downloading webpage
[RumbleEmbed] Extracting URL: https://rumble.com/embed/v25g3g0
[RumbleEmbed] v25g3g0: Downloading JSON metadata
[info] v25g3g0: Downloading 1 format(s): mp4-480p
[download] Let Me Show You Brax.Me - Privacy Focused App [v25g3g0].mp4 has already been downloaded
[download] 100% of   20.00MiB



[Rumble] Extracting URL: http://rumble.com/v2820uk-let-me-show-you-brax.me-privacy-focused-app.html
[Rumble] v2820uk-let-me-show-you-brax.me-privacy-focused-app.html: Downloading webpage
[RumbleEmbed] Extracting URL: https://rumble.com/embed/v25g3g0
[RumbleEmbed] v25g3g0: Downloading JSON metadata
[info] v25g3g0: Downloading 1 format(s): mp4-480p
[download] Destination: Let Me Show You Brax.Me - Privacy Focused App [v25g3g0].mp4
[download]   3.8% of  525.67MiB at    5.79MiB/s ETA 01:27^C

So I would probably need to pipe output somehow, and then color it. yt-dlp actually colors progress when downloading. I've tried to put grc in front of yt-dlp but didn't color it.

3
  • I don't work with yt-dlp so I'm not sure if/how yt-dlp's colorization may interact with your desired colorization so fwiw .... this answer may be of interest if the objective is to apply different colors to various strings in the output streaming from the yt-dlp call Commented Feb 4, 2023 at 22:28
  • to keep your code less complicated I'd probably wrap the coloeization code (eg, awk script from that linked answer) in a function and then have your feed the yt-dlp output to the function; ymmv ... Commented Feb 4, 2023 at 22:44
  • Thanks @markp-fuso This use of awk is a bit much for my knowledge, also never really used functions in bash, but probably could learn to use it. Can you propose at least aprox solution. I just want to color filename or message that exists in red. No other colors Commented Feb 4, 2023 at 23:20

1 Answer 1

1

You can colorize specific things you want using grep:

yt-dlp 'URL' | grep --color -P "^|(Destination.*|.*has already been downloaded)" 

Basically it will match all lines with ^, so those lines will still be printed, however since this match contains no visible characters those lines will not be colored.

Then you just add in the parts you want colored after the regex |. The --color shouldn't be neccesary, just adding it to make sure that is not the issue.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks @Maximilian ... That works, and very simple/short. It doesn't show % counting while downloading, but good enough.
@DenisZ You can show percent while downloading in title bar with yt-dlp --console-title or you can print as newline with yt-dlp --newline. Unforunately grep has issues with displaying progress bars natively so there is no perfect way.
Thanks @Maximilian, that's brilliant... btw how can I reset console title to [screen #: user@host:/dir]
Maybe the -E flag will work as well, no?
btw @MaximilianBallard I was able to reset my console title with help of ChatGPT :) so I added printf "\033]0;\007" to my script. (it just removes last part where yt-dlp displays the status
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.