YouTube on the Raspberry Pi At Last

July 12th, 2014 subogero Comments off

To cut a long story short: YouTube finally works in HD on my TV with RemotePi. I can’t stop watching LaFerrari and McLaren P1 videos in HD with great sound!

Why was it so difficult?

In the old times, youtube-dl -g spat out YouTube stream URLs, and omxplayer could play them straight away. The excellent ncurses based yt worked this way. But things have changed. YouTube now only streams the video if a session cookie is presented. But omxplayer can’t use cookie jars.

But curl can! We tell youtube-dl to save the cookie, and let curl save/stream the video using the cookie.

curl -b jar `youtube-dl -g --cookies jar --write-thumbnail`

will spit out the video stream.

1st Attempt – Save to File

Let curl save to a file, and start omxplayer a few seconds later to play it back. Keep fingers crossed that curl saves faster than omxplayer reads.

It does not. This solution is so disk/sdcard IO intensive, that omxplayer will reach the EOF too soon and exit.

2nd Attempt – Stream via FIFO

Let’s create a FIFO file, and let curl write the video stream into that. And start omxplayer immediately to read the video stream from the FIFO. It works beautifully:

  • there is no disk IO at all, so curl writes faster than omxplayer reads
  • even if it’s not the case due to a slow network, the player does not exit, just blocks until curl catches up. Bacause the FIFO is a character device!
  • if omxplayer exits for any reason, curl gets a SIGPIPE and exits too

The Result – rpyt

It’s all wrapped up in a new script packaged with omxd: rpyt.

And the RemotePi remote-control web-app also uses that from now. See the project homepage and the code on Github.

RemotePi Cover Art

July 8th, 2014 subogero Comments off
Avi Nissim and Lior Perlmutter

Avi Nissim and Lior Perlmutter

This is the current state of RemotePi. Note the progress bar for the current track (fully text based), and the cover art. Involving no MP3 tags, no 3rd party databases, just good old directories and files.

Also note my current taste in music. Most say it’s crap. Others say it’s fun. It’s definitely controversial and definitely not mainstream.

Quiz: What model is the phone used as remote control?

Categories: Uncategorized Tags:

Perl Hash Slices

May 22nd, 2014 subogero Comments off

Perl always does what you want, except if you want consistency.

I remember those “Wouldn’t it be great?” moments throughout my Perl hacking years. The answer was invariably “Yes, you can”.

Wouldn’t it be great if you could interpolate variables into regular expressions? Yes. you can.
Wouldn’t it be great if you could address a hash with a subset of keys and get a subset of values? Yes, you can.

Which, in turn, brings me to hash slices and a few related tricks.

Slicing Hashrefs

This is how you slice a hash, building an array of values from an array of corresponding keys. Pythonistas now notice the beautiful simplicity compared to their silly list comprehensions…

%hash = (one => 1, two => 2, three => 3);
@one_three = @hash{'one', 'three'};

But how to slice a hashref?

$hashref = {one => 1, two => 2, three => 3};
@one_three = @{$hashref}{'one', 'three'};

The rule is that if you have a $hashref instead of a %hash, you can do everything the same way, just replace the bare sigil-less name of the hash with {$hashref}. Pythonistas are at this moment enlightened about the usefulness of sigils. They wish that not everything was a reference, saving them from headaches about deep copies and dilemmas about a and b being the same thing or not.

Merging Hashes

Hash slices can be lvalues too, so you can assign an array of values to an array of keys.

%numbers = (one => 1, two => 2);
%more = (three => 3, four => 4);
@numbers{keys %more} = values %more;

Note the @ sigil in front of all hash slices. They are arrays!

Categories: Uncategorized Tags: , , , ,

Linus Torvalds Quote of the Week

April 9th, 2014 subogero Comments off

How can a cursing, politically incorrect, rude man lead a project of Linux’ size. This is how:

On Wed, Apr 2, 2014 at 4:28 PM, Andrew Morton <akpm@linux-foundation.org> wrote:
>
> Could be done per-fd: put a struct ratelimit_state into struct
> devkmsg_user.

Yeah, what Andrew said. My suggestion of per-task or per-cred is
obviously moronic in comparison.

                Linus "hangs head in shame" Torvalds
Categories: Uncategorized Tags:

The (semi) Ultimate YouTube Party

February 7th, 2014 subogero Comments off

screenshot-1391729480793

YouTube parties have a few flaws. Five to ten people gather around a small laptop, an even smaller tablet or a tiny smartphone. Nobody can see the screen really well. It’s no biggie, actually, as nobody cares for videos someone else wants to show. You only want to show off yours. And here is the problem:

You have to wait until the end of that lame boring clip, just to start the search for that brilliant masterpiece you’ve come across last night.

And that’s where remotepi and youtube-dl come for the help of the party, to fix the small problem and the big problem. First, the actual video is played on your huge flatscreen TV by the Raspberry Pi. Second, everyone can search for the next clip on their mobile phones in the meantime!

Head to the homepage or github.com/subogero/remotepi to solve your YouTube problems.

And why semi-ultimate? Erm, a few small problems. The omxd playlist daemon may or may not work properly with the freshest omxplayer. Also, a few video URLs can’t be played by the latter, probably due to authentication problems. But give it a try, anyway.

Categories: Uncategorized Tags: , ,

My Raspberry Pi Media Player Suite

September 26th, 2013 subogero Comments off
RemotePi screenshot

RemotePi browsing music

My Raspberry Pi media player suite has reached a generally usable level. At the bottom of the stack there is omxplayer, then the omxd playlist daemon, the rpi.fm command-line internet radio player and, finally, RemotePi the remote control web-app, optimized for smart-phone screens.

Check out its home page.

Why Not XBMC?

I admit I suffer from severe NIH (Not Invented Here) symptoms. But this time, I actually tried to install XBMC from Michael Gorven’s Debian package. But what do I see?

I need to get 44 MB of archives. 120 MB additional disk space will be used. RemotePi, rpi.fm and omxd are 3 MB including all sources, all binaries and all git repositories.

And lo and behold, who are among the dependencies?

  • qt3
  • mysql-common
  • samba-common-bin

Come on! I never use my Raspberry’s GUI. All the GUI RemotePi has is a web-app.

MySQL? Probably a sign of a nice tag-based media library which, in real life, is an absolute pain in the neck to use. You have a DJ-set album, from all sorts of different artists, and a tag-based player just refuses to play it in the order intended by the DJ. I’ll stick to my files and directories, thank you very much.

Samba? I’m one of those smug Penguinistas whose home is Windows-free. So no thanks.

Redmine Command Line Interface – redlist

May 27th, 2013 subogero Comments off

redupload, redupdate, redshow, and now redlist. The new one prints the list of issues in plain text, project-wise or globally.

$ redlist -p test localhost/redmine
# Tracker Status      Subject      Assignee      Due date   
2 Feature In Progress Test Feature Szabó Gergely            
1 Bug     In Progress Test Issue   Szabó Gergely 2013-05-26

Uploading files? Check.
Creating or updating issues? Check.
Showing issue details? Check.
Listing issues? Check.

Redlist uses the CSV export feature of Redmine. As Text::CSV is not part of the standard Perl library, I decided to write my own CSV parser. It seemed easy until I tried it on an old mine, 0.9.3 to be precise. In which case it fell apart as the bastard puts each and every existing attribute into the CSV, including the multiline Description. What started with two simple regular expressions, ended up with five, plus a state-machine.

There was some trouble with encoding too. For best results, set your terminal’s locale to utf-8, as well as Redmine’s csv-encoding. On Debian, the yml files are in /usr/share/redmine/config/locales/ for each language. Look for

   general_csv_encoding: UTF-8

Bot the old mine’s output is still too wide for a terminal. Until you define your personal filters, that is. Create ~/.redgit and add

[redlist]
Created
Updated
Description
Parent task
Estimated time

Whatever. It’s still on Github: http://github.com/subogero/redgit

HP Laserjet P1102 on Raspberry Pi

May 22nd, 2013 subogero 3 comments

Printing is evil. Back in the day this evilness sparked even Richard Stallman’s ire and so the Free Software Movement was born. It was 1980 and the new Xerox 9700 laser printer’s proprietary software could not be modified to add an email notification feature.

Fast forward 33 years. The HP Laserjet P1102 has a proprietary driver plugin. It’s freely available for the hp-setup program on Linux. Except, that HP does not compile it for the armv6 architecture. So my home print server, a Raspberry Pi, did not work with my new shiny P1102.

Until I found Rick Richardson’s foo2jzs driver, that is. Instructions and download on http://foo2zjs.rkkda.com.

Morale of the story: free software has nothing to do with communism. On the contrary: it promotes private property rights. The communist, a.k.a. thief, is HP. I bought their printer with my own money, but the tricky bastards did not allow me to use it. A classic case of “redistribution of wealth”. It was Rick’s opens source driver that saved my day.

rpi.fm My Stations

May 20th, 2013 subogero Comments off

The Raspberry Pi kicks ass as a media player. Thanks to, among others, rpi.fm, my and my friends’ favourite internet radio player.

Ladies and Gentlemen!

Upon popular user request, I hereby present its new “My Stations” function. rpi.fm now remembers whenever you choose a station. It builds a list from them, ranked by how often you’ve chosen each, and offers a new command “m” to access them.

Enjoy. But only after you’ve updated rpi.fm form Github.

For those in the know:

cd rpi.fm
git pull origin master
sudo make install
rpi.fm

For rpi.fm Noobs:

git clone https://github.com/subogero/rpi.fm
cd rpi.fm
sudo make install
rpi.fm

Redmine Command Line Interface – redupdate

May 19th, 2013 subogero Comments off

We love Redmine. It’s everyone’s favourite integrated bug-tracker-wiki-gantt-roadmap-web-app running on Rails. It has everything. Except a decent command line interface.

There are some half-baked attempts on the internet, usually having suffered a few years’ time of bitrot and featuring loads of undocumented Ruby-related dependencies, so-called gems in Ruby-speak. I tried to install a few, but not being a hard-core Rubyist, I had to give up.

Long ages of desperation followed. Until I looked into Redmine’s email interface. Which, it turns out, is a command-line interface in disguise. I decided to leave Exim4 well alone, and write a user friendly command line wrapper around the obvious

/usr/share/redmine/extra/mail_handler/rdm-mailhandler.rb

My first attempt was a server-side only shell-script. But then I realized that any self-respecting person who uses the command-line has some sort of shell access to the Redmine server anyway, which also accommodates the central-ish git repos. So I added an option to run via SSH.

Ladies and Gentlemen: redupdate

Please find it on Github along with a few other scripts:
https://github.com/subogero/redgit

The other scripts include:

  • redupload: upload files to Redmine
  • redshow: view issues in plain text format
  • gitcreate: create bare repo, add HTTP access, optional email notification upon pushes