marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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/2 ... 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/viewt ... 221#p74221

toxibunny
Posts: 1383
Joined: Thu Aug 18, 2011 9:21 pm

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

Tue Jun 12, 2012 12:41 am

cheers :)
note: I may or may not know what I'm talking about...

RussIT
Posts: 28
Joined: Thu Jan 05, 2012 11:34 am

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

Tue Jun 12, 2012 12:51 am

very cool just tried it on wheezy, are there play and stop/pause keys?

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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.

nommo
Posts: 37
Joined: Sun Jun 10, 2012 10:17 am
Location: UK

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

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.

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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!

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

Tue Jun 12, 2012 2:24 pm

I guess you can't edit. Oh well. :P

robotfunk
Posts: 45
Joined: Wed May 30, 2012 7:28 pm

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

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

jchadwick
Posts: 4
Joined: Tue Jun 12, 2012 12:43 pm

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

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

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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?

robotfunk
Posts: 45
Joined: Wed May 30, 2012 7:28 pm

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

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)

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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

nommo
Posts: 37
Joined: Sun Jun 10, 2012 10:17 am
Location: UK

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

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.

robotfunk
Posts: 45
Joined: Wed May 30, 2012 7:28 pm

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

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

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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?

robotfunk
Posts: 45
Joined: Wed May 30, 2012 7:28 pm

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

Tue Jun 12, 2012 4:15 pm

yeah that's exactly how it looks (tabbed)... I guess the forum removed the spaces..

robotfunk
Posts: 45
Joined: Wed May 30, 2012 7:28 pm

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

Tue Jun 12, 2012 4:19 pm

Forgot to mention, I'm on Debian Squeeze, if that matters.

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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?

robotfunk
Posts: 45
Joined: Wed May 30, 2012 7:28 pm

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

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

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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

jchadwick
Posts: 4
Joined: Tue Jun 12, 2012 12:43 pm

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

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.

texy
Forum Moderator
Forum Moderator
Posts: 4991
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

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

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
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

marktbaldridge
Posts: 23
Joined: Tue Feb 21, 2012 4:58 am

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

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? :?:

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

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

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
PiPLAY - http://piplay.org
DeskCade.com - Mini Raspberry Pi Arcade Cabinet

texy
Forum Moderator
Forum Moderator
Posts: 4991
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

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

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
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

Return to “Media centres”

Who is online

Users browsing this forum: No registered users and 17 guests