HOWTO: YouTube on the Raspberry Pi - sans X B-)


165 posts   Page 1 of 7   1, 2, 3, 4, 5 ... 7
by marktbaldridge » Tue Jun 12, 2012 12:18 am
So guys, this is my first Raspberry Pi howto, so as the saying goes, bear with me. :)

I love the terminal. And to quote one guy on another forum (I don't remember where) "Chicks dig guys with terminals." B-)

Also, the terminal is significantly more RP friendly than X (differ if you must, but I really feel that it's inherent because of the amount of RAM)

I spend about 80% of my time on the RP in the terminal without ever starting X.

So, here's how to play youtube without ever having to boot X!

BTW, this requires omxplayer for the RP.

Advantages:
  • Don't have to boot X
  • Hardware Acceleration
  • What the heck?? Who needs Flash or HTML5??

So here's how:

First, we need several dependencies: youtube-dl and python-setuptools. Problem: youtube-dl isn't in the ARM repos. Not sure why... it's python...

So, we have to download it here: https://github.com/rg3/youtube-dl/raw/2012.02.27/youtube-dl
Code: Select all
wget https://github.com/rg3/youtube-dl/raw/2012.02.27/youtube-dl


Then we have to manually install it:
Code: Select all
chmod +x youtube-dl
cp youtube-dl /usr/bin/youtube-dl


Now we need to install python's setup tools. And BTW, don't worry, this is all small stuff. You won't clutter up your SD card. :)
Code: Select all
sudo apt-get install python-setuptools


Next we need to download and extract yt which is an awesome python console utility for playing youtube videos.
Code: Select all
wget http://pypi.python.org/packages/source/w/whitey/whitey-0.1.tar.gz
tar -zxvf whitey-0.1.tar.gz


But DON"T INSTALL YET! We need to tell yt to use omxplayer not mplayer because that doesn't work on the RP.

Navigate to whitey's /src/yt/ directory, and edit __init__.py as follows: The line that has the mplayer command in it, change mplayer to omxplayer, and remove the argument switches.

Or, you can download my edited version here: https://dl.dropbox.com/u/33311875/__init__.py and replace the file completely.

Next, navigate up two directories so that you are in the main whitey folder, and then install:
Code: Select all
sudo python setup.py install


Then you should be able to just run ~$ yt and watch the magic happen! The interface is really quite intuitive IMHO.

NOTE: If you don't have omxplayer, it's getting easier and easier to install these days. Just follow the instructions on this comment: http://www.raspberrypi.org/phpBB3/viewtopic.php?p=74221#p74221
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by toxibunny » Tue Jun 12, 2012 12:41 am
cheers :)
note: I may or may not know what I'm talking about...
Posts: 1051
Joined: Thu Aug 18, 2011 9:21 pm
by RussIT » Tue Jun 12, 2012 12:51 am
very cool just tried it on wheezy, are there play and stop/pause keys?
Posts: 28
Joined: Thu Jan 05, 2012 11:34 am
by marktbaldridge » Tue Jun 12, 2012 12:54 am
RussIT wrote:very cool just tried it on wheezy, are there play and stop/pause keys?


I think so.
Play/Pause = Space
Skip = Arrow keys
Quit = q

There's probably more, but that's the most basic stuff.
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by nommo » Tue Jun 12, 2012 12:07 pm
I didn't get any sound via hdmi but using the following to '__init__.py' before install worked:

Code: Select all
    mplayer = subprocess.Popen(
            ['omxplayer', '-ohdmi', url.decode('UTF-8').strip()],
            stdout = subprocess.PIPE, stderr = subprocess.PIPE)
    mplayer.wait()


I first tried unsuccessfully with '-o hdmi' and a few escape chars that I could recall, but it seems omxplayer is happy to parse the args without a space anyway...
Early model B with Raspbian updating Xively (was Cosm) with CurrentCost Envi plus NAS, Get Iplayer, YT (whitey) and a general ssh linux playpen plus a 512MB model B with OpenElec.
Posts: 37
Joined: Sun Jun 10, 2012 10:17 am
Location: UK
by marktbaldridge » Tue Jun 12, 2012 2:22 pm
Okay, yeah. I was using composite and analog when I did this hack. I've heard about having to pass that argument to omxplayer if you want sound over HDMI.

I'll edit the HOWTO.

Thanks for the tip!
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by marktbaldridge » Tue Jun 12, 2012 2:24 pm
I guess you can't edit. Oh well. :P
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by robotfunk » Tue Jun 12, 2012 2:36 pm
When I run yt I get


Traceback (most recent call last):
File "/usr/local/bin/yt", line 9, in <module>
load_entry_point('whitey==0.1', 'console_scripts', 'yt')()
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 16, in main
ui.run()
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 56, in run
curses.wrapper(self._curses_main)
File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper
return func(stdscr, *args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 69, in _curses_main
curses.curs_set(0)
_curses.error: curs_set() returned ERR
Posts: 45
Joined: Wed May 30, 2012 7:28 pm
by jchadwick » Tue Jun 12, 2012 2:38 pm
Interestingly enough, I did something very similar with YouTube dl, although what I really want to do is write a C/OpenMax/OpenGL-based YouTube client.

I'll have to give this a go, though. Does seeking work in this by chance?

(Still trying to get my head straight with this whole EGL/OpenGL ES 2/OpenMAX IL stack... Could use a bit more docs.)
Posts: 4
Joined: Tue Jun 12, 2012 12:43 pm
by marktbaldridge » Tue Jun 12, 2012 2:41 pm
robotfunk wrote:When I run yt I get


Traceback (most recent call last):
File "/usr/local/bin/yt", line 9, in <module>
load_entry_point('whitey==0.1', 'console_scripts', 'yt')()
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 16, in main
ui.run()
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 56, in run
curses.wrapper(self._curses_main)
File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper
return func(stdscr, *args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 69, in _curses_main
curses.curs_set(0)
_curses.error: curs_set() returned ERR


Are you using my edit? If not, can we see your edit of that section of __init__.py?
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by robotfunk » Tue Jun 12, 2012 2:54 pm
Yes I modified it like so:

mplayer = subprocess.Popen(
['omxplayer', url.decode('UTF-8').strip()],
stdout = subprocess.PIPE, stderr = subprocess.PIPE)
Posts: 45
Joined: Wed May 30, 2012 7:28 pm
by marktbaldridge » Tue Jun 12, 2012 3:22 pm
Okay, after a bit of googling, I think it's actually a bug in the yt program itself.

Evidently, the curs_set() changes the visibility of the console cursor. It seems that there's an incompatibility with that command and some terminals. Is this through SSH? or did you set the RP to use vt100 or something like that?

You could try commenting out that line (line 69 I believe), and re "compiling" (sudo python setup.py install). Or put a try/catch around that part of the code.

From what I understand, the yt program isn't very well documented or even maintained. Here's the homepage: http://pypi.python.org/pypi/whitey/0.1
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by nommo » Tue Jun 12, 2012 3:55 pm
marktbaldridge wrote:Okay, yeah. I was using composite and analog when I did this hack. I've heard about having to pass that argument to omxplayer if you want sound over HDMI.

I'll edit the HOWTO.

Thanks for the tip!


No worries! Thanks for sharing the howto! :D
Early model B with Raspbian updating Xively (was Cosm) with CurrentCost Envi plus NAS, Get Iplayer, YT (whitey) and a general ssh linux playpen plus a 512MB model B with OpenElec.
Posts: 37
Joined: Sun Jun 10, 2012 10:17 am
Location: UK
by robotfunk » Tue Jun 12, 2012 4:01 pm
Yes, this was through SSH, I just tried it on the Pi directly, and got a whole lot more errors...
Posts: 45
Joined: Wed May 30, 2012 7:28 pm
by marktbaldridge » Tue Jun 12, 2012 4:07 pm
Hum... one other thing that might throw errors. When you have this bit:
Code: Select all
mplayer = subprocess.Popen(
['omxplayer', url.decode('UTF-8').strip()],
stdout = subprocess.PIPE, stderr = subprocess.PIPE)

Should that be tabbed over? (python stakes it's life on white-space)
Code: Select all
mplayer = subprocess.Popen(
     ['omxplayer', url.decode('UTF-8').strip()],
     stdout = subprocess.PIPE, stderr = subprocess.PIPE)


Like so?
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by robotfunk » Tue Jun 12, 2012 4:15 pm
yeah that's exactly how it looks (tabbed)... I guess the forum removed the spaces..
Posts: 45
Joined: Wed May 30, 2012 7:28 pm
by robotfunk » Tue Jun 12, 2012 4:19 pm
Forgot to mention, I'm on Debian Squeeze, if that matters.
Posts: 45
Joined: Wed May 30, 2012 7:28 pm
by marktbaldridge » Tue Jun 12, 2012 4:26 pm
Not sure if that would matter...

To be honest, I'm a bit stumped right about now... :|

Can you give a full error dump?

And... does anybody else have any input for robotfunk?
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by robotfunk » Tue Jun 12, 2012 4:39 pm
Here's the error I get when I run yt on the Pi itself:

Traceback (most recent call last):
File "/usr/local/bin/yt", line 9, in <module>
load_entry_point('whitey==0.1', 'console_scripts', 'yt')()
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 16, in main
ui.run()
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 56, in run
curses.wrapper(self._curses_main)
File "/usr/lib/python2.7/curses/wrapper.py", line 43, in wrapper
return func(stdscr, *args, **kwds)
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 99, in _curses_main
self._update_screen()
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 157, in _update_screen
self._add_table_row(self._help, 0, 0, w-1, self._bar_attr, max_width=16, win=self._help_bar)
File "/usr/local/lib/python2.7/dist-packages/whitey-0.1-py2.7.egg/yt/__init__.py", line 334, in _add_table_row
win.addstr(y, x, truncate('%s:%s' % (k,v), min(w-x, cell_w)).encode(self._code), attr)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 12: ordinal not in range(128)

I wouldn't worry too much about it, I don't have an urgent need to play youtube from the Terminal, just wanted to share the results...
Posts: 45
Joined: Wed May 30, 2012 7:28 pm
by marktbaldridge » Tue Jun 12, 2012 4:45 pm
Okay, yeah. Humm...

If you or somebody else figures it out, please be sure to share the fix. :)
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by jchadwick » Tue Jun 12, 2012 5:28 pm
Oh btw, youtube-dl IS in the Debian/ARM repos, just not in Squeeze. After updating to sid I have youtube-dl.

It's also in sqeeze-backports, according to Debian.org.
Posts: 4
Joined: Tue Jun 12, 2012 12:43 pm
by texy » Tue Jun 12, 2012 6:29 pm
Many thanks for this - working a treat!
Its a pity the yt app isn't being maintained any more - for example, how do you select clips 10 to 12?
Also, is it possible to log in to you tube so that you can select your channels, etc ?

Cheers,
Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2316
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England
by marktbaldridge » Tue Jun 12, 2012 7:18 pm
I think what you see down there on the command bar is what you get.

I have a feeling that it's going to be a while before we see flash on the RP, and in-browser html5 video will probably be a while too.

So, aside from XBMC, this might be the only practical youtube interface.

If yt is pretty much dead, maybe we should pick up the slack. Thoughts? :?:
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am
by SSilver2k2 » Wed Jun 13, 2012 3:11 am
This is cool. Going to try this tomorrow (also cool that this is written in Python since that's my language of choice)
My blog of various geeky things - http://blog.sheasilverman.com
DeskCade.com - Mini Raspberry Pi Arcade Cabinet
PiMAME - http://pimame.org
Posts: 177
Joined: Wed Jun 06, 2012 1:51 am
Location: United States
by texy » Wed Jun 13, 2012 6:25 am
texy wrote:Many thanks for this - working a treat!
Its a pity the yt app isn't being maintained any more - for example, how do you select clips 10 to 12?
Also, is it possible to log in to you tube so that you can select your channels, etc ?

Cheers,
Texy


Well after playing a bit more I sussed out how to get clips 10 to 12. Instead of selecing 1 to 9, you can press v, then 10 <return>

Texy
"2.8inch TFT LCD + Touch screen" add-on boards for sale here :
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=93&t=65566
50p goes to the Foundation ;-)
Forum Moderator
Forum Moderator
Posts: 2316
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England