Monday, June 17, 2013

Twitch.tv without Adobe Flash

How to watch streams in your favourite video player.

Current problems with Flash under Linux:

  • new versions of Adobe plugins will support only Chrome Pepper - for other browsers only older plugins will be available
  • closed source ™
  • sometimes you cannot exit full screen mode
  • sometimes just hangs with 100% CPU usage
  • sometimes it just crash

There is some alternative - shumway but currently it doesn't support YouTube so my guess is that Twitch isn't either. Additionally when page is using SWFObject we will see only "install Adobe Flash" text.

Downloading

Listing flv files for given archive link (past broadcast), archive.py:

#!/usr/bin/python3

from urllib.request import urlopen
import json, sys, re

decoder = json.decoder.JSONDecoder()

for arg in sys.argv[1:]:
 m = re.match(r"^.*/([^/]+)/b/([0-9]+)$", arg)
 video_id = int(m.group(2))
 with urlopen("http://api.justin.tv/api/broadcast/by_archive/%d.json" % video_id) as f:
  resp = decoder.decode(f.read().decode())
  for i in resp:
   print(i["video_file_url"])

Usage:

$ ./archive.py http://www.twitch.tv/some_channel/b/4173086
http://store30.media30.justin.tv/archives/2013-6-15/live_user_some_channel_13713088.flv
http://store38.media38.justin.tv/archives/2013-6-15/live_user_some_channel_13713106.flv
http://store6.media6.justin.tv/archives/2013-6-15/live_user_some_channel_13713124.flv

Only remaining thing is to download those files.

Watching

We will be needing livestreamer and rtmpdump. To not litter in system i've used python virtualenv. Steps below are assuming that rtmpdump is not installed in system.

So:

cd /path/to/project
git clone git://git.ffmpeg.org/rtmpdump
virtualenv env
make -C rtmpdump/
source env/bin/activate
pip install livestreamer

Next step could be writing script for starting player:

#!/bin/bash

d="$(dirname $0)"

source "${d}"/l/bin/activate
LD_LIBRARY_PATH="${d}"/rtmpdump/librtmp/ livestreamer -p /path/to/player -r "${d}"/rtmpdump/rtmpdump "${@}"

... and we can start watching:

./run.sh http://www.twitch.tv/dreamhacksc2 720p

you can also save stream to file:

./run.sh http://www.twitch.tv/dreamhacksc2 720p -o file.flv

Friday, June 14, 2013

Eclipse: The Dark IDE - Linux edition

Not so long ago I've stumbled upon http://ethanschoonover.com/solarized. It is kind of magical set of dark and light themes for range of IDE/editors/widgets etc. and it looks kind of good. I was thinking for a while about background and foreground color contrast - it could be illegible - but it is written that colors comply to CIELAB spec and this solution was tested on variety of devices. So it has to be true! ;)

Since I am spending so much time working with Eclipse, at one time I've decided to try and take Google's advice - darker colors could may reduce eye fatigue (especially when you're coding at night). I'm presenting you steps how to fully theme Eclipse with dark theme (Linux edition).

end result as incentive

Eclipse

At the beginning we have:

To apply above themes you have to first install Eclipse Color Themes and Chrome Theme.

After applying new theme (for Aptana and Eclipse) I've come to see that Aptana's background is a little darker than Eclipse's so I've changed some colors for appropriate - from base scheme (download changed theme).
Our next step is to change color of tabs and other Eclipse widgets, we will use Chrome Theme for it. There you can download already prepared configuration file for ui - you need to place it in workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings. In case of manual fun you will need to remember about adding CSS line from answer on stackoverflow.com:

#org-eclipse-e4-ui-compatibility-editor * { background-color: #002b36; }

GTK

Happily GTK+ 2 theme is easy to find: https://github.com/heichblatt/gtk2-theme-solarizeddark.
You don't need it enabled for whole system, just Eclipse will suffice.

GTK2_RC_FILES=~/.themes/solarized.gtkrc /mnt/sandbox/eclipse/eclipse

Desktop file

If you want to run styled Eclipse from your Desktop Menus, you'll need change Exec part of its .desktop file. Below is whole file as used by me:

[Desktop Entry]
Encoding=UTF-8
Name=Eclipse IDE
Comment=Eclipse Programming IDE
Exec=env GTK2_RC_FILES=~/.themes/solarized.gtkrc /mnt/sandbox/eclipse/eclipse
Icon=/mnt/sandbox/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=Application;Development;

Sadly, event after everything is properly styled you can still find editors where colors will be wrong. For example - Twig editor from Symfony2 package. (fixed Twig configuration)