giovedì 19 settembre 2013

Torrent and DLNA station with Raspberry Pi

A router, a Raspberry Pi and an external hard disk.
This is a quick guide that explains how to make a torrent and DLNA station with a Raspberry Pi. I'm writing this guide as a note for self, but it may also be useful for others. I use Ubuntu, therefore all the instructions in this guide are considered for a Linux system.

Advantages

The main advantage of this system is that you can basically leave your Raspberry Pi on 24/7 with a minimum power consumption and have a self managed server that downloads and stream your movies.

Raspberry Pi

The Raspberry Pi is a credit-card size single-board computer that you can buy for around 35e on this web site.

Install the OS

There are several Linux distribution available for installation on the Raspberry Pi on this web site. I personally use the Raspbian distribution. Once you have downloaded the zip file, extract it. Plug your SD card (on a computer that is not your Raspberry Pi) and run the ImageWriter application. This is a very easy software that makes you select the image you want to write (the one you have just extracted from the zip file) on the left, and the device you want to write on (the SD card) on the right. You need a 4GB SD card, I personally use a 32GB one.

Run the OS

Once you have copied the image on the SD, put it in your Raspberry Pi and run it. The first time you will be presented with a menu. From this menu the only entry that you have to select is "Expand root partition to fill SD card" that, obviously, expand the root partition and makes sure that the Raspbian OS can make use of all the space available, otherwise it will only see 2GB.

SSH

You won't use the Raspberry Pi through the desktop interface, so you need a way to communicate with your little PC, and this way is the SSH protocol. The following commands will install SSH on Raspbian and make it run at the start-up as system service:

sudo apt-get install ssh

sudo /etc/init.d/ssh start

sudo update-rc.d ssh defaults 

Now you can access the Raspberry Pi from another computer entering this command from a system terminal:

ssh pi@a.b.c.d

Where a.b.c.d is the network address of your Raspberry Pi, e.g. 192.168.1.100, and usually you can get this from the admin interface of your home router. You will be asked for the password, the default one is raspberry.

Transmission 

This is the software that will download your torrent files. You can install it with:
sudo apt-get install transmission-daemon
At this point you need to create at least two folders: one for the complete files and one for the downloading one. You can do so by entering the following commands:

mkdir movies

mkdir incomplete

Now, we need to stop Transmission to edit its configuration file. If you don't stop Transmission it will erase your settings, restoring the default, at the next start-up. Then, to stop Transmission:

sudo service transmission-daemon stop

Then, open the file to edit with:

sudo nano/etc/transmission-daemon/settings.json

In questo file dobbiamo modificare alcune voci:
  • "download-dir" : "/home/pi/movies"
  • "incomplete-dir" : "/home/pi/incomplete"
  • "incomplete-dir-enabled" : true
  • "download-queue-enabled" : false
  • "rpc-enabled" : true
  • "rpc-password" : "CHOOSE A PASSWORD"
  • "rpc-username" : "CHOOSE A USERNAME"
  • "rpc-whitelist-enabled" : false
At this point we can restart Transmission with:

sudo service transmission-daemon start

We want Transmission to start when the Raspberry Pi turns on, we can do so by entering the following command:

sudo update-rc.d transmission-daemon defaults

You can now control your Transmission server by web browser, accessing the following URL: http://a.b.c.d:9091/transmission where a.b.c.d is once again your Raspberry Pi IP. You will be asked to enter your username and password (the same you have set in the configuration file), at this point you can add and manage torrent files from the web interface.

Mediatomb

This is the software the streams your movies through the DLNA protocol. You can easily install it with:

sudo apt-get install mediatomb

When the installation is complete, you can launch it with:

mediatom

You can control Mediatomb through its web interface, available at: http://a.b.c.d:49153/ and you can use it to tell Mediatomb which movies you want to stream. To watch the movies you can use any DLNA client, I personally use my PS3 which works great.

Useful Links

Raspberry Pi: http://www.raspberrypi.org/
Raspberry Pi OS's: http://www.raspberrypi.org/downloads 
Transmission: http://www.transmissionbt.com/
Mediatomb: http://mediatomb.cc/

mercoledì 4 agosto 2010

Convert From OGG To AVI Files

mencoder out.ogg -o out.avi -oac mp3lame -ovc lavc

domenica 11 aprile 2010

PostgreSQL Timing

How to measure how long it takes to execute a query? On PostgreSQL just type

\timing

and after every SQL command your server will show you the query milliseconds!

lunedì 8 marzo 2010

PSQL: Month-Based Filtering

My need was to delete some DB entries based on the month field of the date. So I did used the function date_part of PostgreSQL, like this:

SELECT id FROM mytable WHERE date_part('month', date) = 3 AND date_part('year', date) = 2010 and datasetid = 356497950 GROUP BY id;

Now, to delete these entries, just nest this query in a DELETE FROM, like this:

DELETE FROM mytable WHERE id IN (SELECT id FROM mytable WHERE date_part('month', date) = 3 AND date_part('year', date) = 2010 AND datasetid = 356497950 GROUP BY id);

giovedì 23 ottobre 2008

Wedding in Paris

"I can't tell it's a passion, I mean, I like baking, but it's more... You know, after crossing India, and China, and all these places, it's great of course, it's great, but here, in Europe, it's full of... ovens! There are ovens everywhere, it's great! Isn't it?" I'm sure it is, but I've never really thought about this. He can't stop, it's a couple of hours I'm here and he has never stopped baking: lasagna, chocolate cookies, bread, apple pie, ... Will he keep baking forever? "Naa! Maybe I will go on like this for a month, three weeks, I think I will stop when I'll got used to all these ovens.". I was told it is possible to build a simple oven with mud and sand, it's something you learn during the summer camps, but it's hard for me to imagine him in one of these places, he's more a kind of people for... "Are you sure you can build an oven just with sand? Are you sure? It's amazing! You could even build a house with the sand, instead of those horrible tents, or...". Now her brain started, better stop it like this: "...a car! Yeah, you could build a sand car! Or..." Sam's turn: "...a boat! Or, let me thing..." it's me again: "...a SPACESHIP! Yes why not? A sand spaceship! And then you can land on the moon! That's a great idea!!! Ahahah!". Now Niki is a bit pissed off, but it doesn't last much, the idea of landing on the moon is more exciting and so she starts again: "Well, it's a good base, then we can go and visit Mars, and then...". I definetly need another beer...