Posts: 5
Joined: Fri Aug 03, 2012 4:03 pm

[HOW-TO] youtube from terminal

Sun Aug 05, 2012 12:27 pm

Hi, this is my first post/contribution to this forum and I want to share with you how watch youtube videos from terminal using omxplayer.

This guide make use of a perl script called youtube-viewer


It performs searches directly from terminal; these are youtube options:

Code: Select all

all               : play all the results in order
next              : go to the next page (same as <ENTER>)
back              : return to the previous page
login             : will prompt you for login
logout            : will delete the authentication key
[integer]         : play the corresponding video
i, info [i]       : show more informations about one video
c, comments [i]   : show video comments (e.g.: c 19)
r, related [i]    : show related videos (e.g.: r 6)
v, videos [i]     : show author's latest videos
p, playlists [i]  : show author's latest playlists
subscribe [i]     : subscribe to author's channel
like, dislike [i] : like or dislike a video
fav, favorite [i] : favorite a video (e.g.: fav 3)
[keywords]        : search for youtube videos
3-8, 3..8         : same as 3 4 5 6 7 8
8 2 12 4 6 5 1    : play the videos in your order
-argv -argv2=v    : set some arguments (e.g.: -u=google)
e, edit-config    : edit and apply the configuration
load-config       : (re)load the configuration file
/my?[regex]*$/    : play videos matched by a regex (/i)
reset, reload     : restart the application
q, quit, exit     : close the application
Let's begin:

1) Obviously, first of all install the script; it's a single file to put in /usr/bin and give execution permission

2) The script requires two perl modules:
- libwww-perl (from repos)
- XML::Fast : unfortunately it isn't in repos so you have to install it manually through cpan; the command is:

Code: Select all

sudo cpan -i XML::Fast
The command downloads and compiles the module. The problem I encountered was an error during make: it was unable to find gcc-4.7; infact seems that my raspbian came with gcc-4.6; i removed gcc-4.6 and installed gcc-4.7 so the previous command completes correctly.

3) Now the tricky part; youtube-viewer uses mplayer as default. Since it has, atm, the problems we all know, we must revert to omxplayer; the easiest way is to edit a single line of the script:

Code: Select all

system @mplayer_line, $streaming;
I recommend to comment out it and add new one:

Code: Select all

#system @mplayer_line, $streaming;
system 'omxplayer', $streaming;
Stated that way, does not seem so difficult, but I encountered problem passing '-o hdmi' option; adding this extra text to the line above make the script do not work as expected (the player doesn't start). The best solution I found is to create in /usr/bin a bash script to launch omxplayer with the desired option and use the name of this script in youtube-viewer; this is the content of the script:

Code: Select all

/usr/bin/omxplayer -o hdmi $1
give it a name of your choice, make it executable and change the line in youtube-viewer:

Code: Select all

system 'my_omxplayer_launcher', $streaming;
Extra custumization: hide console content during playback: I use 'setterm' this way:

Code: Select all

system 'setterm -blank force';
system 'omxplayer', $streaming;
system 'setterm -blank poke';
That's all. Have fun,

User avatar
Posts: 38
Joined: Tue Jul 17, 2012 9:37 am
Location: Sweden

Re: [HOW-TO] youtube from terminal

Sun Aug 05, 2012 1:45 pm

Thank you for the detailed instructions, works like a charm! I like the way youtube-viewer prefers high definition video by default.

On Arch I used perl-libwww from extra and perl-xml-fast from aur. gcc is of course up to date already if you are a diligent pacman user ;)

Posts: 5
Joined: Fri Aug 03, 2012 4:03 pm

Re: [HOW-TO] youtube from terminal

Sun Aug 05, 2012 2:28 pm

@ph0ng, Probably I should emphasize that the steps concern raspbian, debian based. On desktop I use Arch so I know that it's easier to install missing packages. However, I have yet to try archlinux for raspi.

User avatar
Forum Moderator
Forum Moderator
Posts: 2810
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: [HOW-TO] youtube from terminal

Sun Aug 05, 2012 2:51 pm

Excellent. Thanks for sharing this. Unfortunately I can't test it at the moment, but I'm looking forward to doing so. :D
Alex Eames RasPi.TV, RasP.iO

Posts: 179
Joined: Wed Jun 06, 2012 1:51 am
Location: United States
Contact: Website AOL

Re: [HOW-TO] youtube from terminal

Sun Aug 05, 2012 10:42 pm

This worked great. I'm not using '-o HDMI' since I'm connected via composite. You don't need to uninstall GCC 4.6, you can have 4.7 and 4.6 installed. Before doing 'sudo cpan -i XML::Fast' type this first:

export CC=gcc-4.7
export CXX=g++-4.7
My blog of various geeky things - http://blog.sheasilverman.com
PiPLAY - http://piplay.org
DeskCade.com - Mini Raspberry Pi Arcade Cabinet

Return to “General discussion”

Who is online

Users browsing this forum: Baidu [Spider], drgeoff, ise7, wintux and 57 guests