How to Stream Movies to your iPhone or iPad

I have just found a way to successfully stream movies (avi, mkv, mp4, etc) to my iPhone. It’s via an app called AirPlayer.

First, set up a media server on your home network (for example, PS3 Media Server, like what I have explained in my previous post, “How To Share Media Between PlayStation 3 and Linux”). Then, just access your movies through the AirPlayer app. Everything just works, without much setting or config changes.

Create Your Own Web App to Execute Linux Command

Let say you need to run a command (which you use frequently) on your headless Linux box, such as, copying files, start/stop services, reboot, etc. However too lazy to go to the physical machine or open a ssh command from another pc.
Would it be nice if we have a web application that can easily be accessed through a web browser (even from a mobile web browser), to execute those commands. All we have to to is type the url (http://my-server-ip-address:myportnumber), and click on a link.
All these could easily be achieved using very simple service using Python.

1. Create a simple Python script. The Python script will be using WSGI to serve HTTP request/response.

vi mypythonscript.py

2. A sample of the Python script below:

import os
from cgi import parse_qs, escape

def hello_world(environ, start_response):
    parameters = parse_qs(environ.get('QUERY_STRING', ''))
    if 'type' in parameters:
        mycommand = escape(parameters['command'][0])
    else:
        mycommand = ''
    start_response('200 OK', [('Content-Type', 'text/html')])

    if mycommand == 'copyfile1':
	#your linux command here. Example below
	os.system('cp myfile1.txt mynewfile.txt')
    elif mycommand == 'copyfile2':
	os.system('cp myfile2.txt mynewfile.txt')

    return ['''Command to execute:  %(mycommand)s 
    <a href='?command=copyfile1'>Copy file 1</a>
    <a href='?command=copyfile2'>Copy file 2</a>
    ''' % {'mycommand': mycommand}]

if __name__ == '__main__':
    from wsgiref.simple_server import make_server
    #put your own server ip address and port here
    srv = make_server('127.0.0.1',81, hello_world)
    srv.serve_forever()

3. Make the Python script run on every startup. Create a bash script for this:
vi myserver

4. Here’s the script for the bash file:

#! /bin/sh
# /etc/init.d/myserver
#

# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "Starting myserver "
    python /home/username/mypythonscript.py&
    echo "[OK]"
    ;;
  stop)
    echo "Stopping myserver "
    kill -9 `pidof python`
    echo "[OK]"
    ;;
  *)
    echo "Usage: /etc/init.d/myserver {start|stop}"
    exit 1
    ;;
esac

exit 0

5. make the bash script executable.
chmod +x myserver

6. copy myserver script to /etc/init.d
sudo cp /wherever/you/saved/myserver /etc/init.d/myserver

7. update the startup folders to include the new script.
sudo update-rc.d myserver defaults

8. To test your Python web app, open a web browser, and type:
http://my-server-ip-address:81

How to Queue Torrents in Transmission

Currently there’s no queue features in Transmission. Luckily we can improvise this with the help of transmission-remote, a command based client for transmission, and along with some Linux bash scripting.

Below I have created a simple bash script:

1. Install transmission remote:
sudo apt-get install transmission-cli

2. Copy the script below, and save as my_script_name.sh , (or whatever name you prefer, but note the .sh extension).

#!/bin/sh
 
# *************
# Configuration
REMOTE="/usr/bin/transmission-remote"
USERNAME="my_username"
PASSWORD="my_password"
MAXDOWN="max_number_of_torrent_to_download"
MAXACTIVE="max_active_torrent"
CONFIG="/my_location_to_transmission_config_file/settings.json"
TRANSOPTS="127.0.0.1:my_port_number"
 
# *************
# Set-up variables
CMD="$REMOTE $TRANSOPTS --auth $USERNAME:$PASSWORD"
LOGCMD="/usr/bin/logger -t transmission-queue "
MAXRATIO=$(cat $CONFIG | grep \"ratio-limit\":)
MAXRATIO=${MAXRATIO#*\"ratio-limit\": }
MAXRATIO=${MAXRATIO%*, }
 
# *************
# deal with downloads
DOWNACTIVE="$($CMD -l | tail --lines=+2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | wc -l)"
if [ $MAXDOWN -lt $DOWNACTIVE ]; then
    DOWNTOSTOP="$($CMD -l | tail --lines=+2 | grep -v 100% | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | tail -n $(expr $DOWNACTIVE - $MAXDOWN) | awk '{ print $1; }')"
    for ID in $DOWNTOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $LOGCMD "< << $ID: ${NAME#*Name: }"
        $CMD --torrent $ID --stop >> /dev/null 2>&1
    done
else
    [ $(expr $MAXDOWN - $DOWNACTIVE) -gt 0 ] && (
    DOWNINACTIVE="$($CMD -l | tail --lines=+2 | grep -v 100% | grep Stopped | wc -l)"
    [ $DOWNINACTIVE -gt 0 ] && (
        DOWNTOSTART="$($CMD -l | tail --lines=+2 | grep -v 100% | grep Stopped | head -n $(expr $MAXDOWN - $DOWNACTIVE) | awk '{ print $1; }')"
        for ID in $DOWNTOSTART; do
            NAME="$($CMD --torrent $ID --info | grep Name:)"
            $LOGCMD ">>> $ID: ${NAME#*Name: }"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )
fi
# Then deal with total active
ACTIVE="$($CMD -l | tail --lines=+2 | grep -v Sum | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | wc -l)"
if [ $MAXACTIVE -lt $ACTIVE ]; then
    TOSTOP="$($CMD -l | tail --lines=+2 | grep 100% | grep -v Stopped | grep -v Verifying | grep -v Will\ Verify | tail -n $(expr $ACTIVE - $MAXACTIVE) | awk '{ print $1; }')"
    for ID in $TOSTOP; do
        NAME="$($CMD --torrent $ID --info | grep Name:)"
        $LOGCMD "< << $ID: ${NAME#*Name: }"
        $CMD --torrent $ID --stop >> /dev/null 2>&1
    done
else
    [ $(expr $MAXACTIVE - $ACTIVE) -gt 0 ] && (
    SEEDINACTIVE="$($CMD -l | tail --lines=+2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (strtonum(substr($0,52,4)) < ratio) print $0 ;}' | wc -l)"
    [ $SEEDINACTIVE -gt 0 ] && (
        TOSTART="$($CMD -l | tail --lines=+2 | grep 100% | grep Stopped | awk -v ratio=$MAXRATIO '{ if (strtonum(substr($0,52,4)) < ratio) print $0 ;}' | head -n $(expr $MAXACTIVE - $ACTIVE) | awk '{ print $1; }')"
        for ID in $TOSTART; do
            NAME="$($CMD --torrent $ID --info | grep Name:)"
            $LOGCMD ">>> $ID: ${NAME#*Name: }"
            $CMD --torrent $ID --start >> /dev/null 2>&1
        done
        )
    )
fi

Save the script on any location you prefer.

3. Create a cron job to run the script. Open the entry to crontab:
crontab -e

4. Let say you want to run the script 5 minutes, the entry on your cron job should be as below:
*/5 * * * * sh /location_to_my_script/my_script_name.sh

Script courtesy of www.4geeksfromnet.com

How To Share Media Between PlayStation 3 and Linux

A while ago I have posted on How To Share Media Between XBOX 360 and Linux. It also can be as easy with PlayStation 3 and Linux, with PS3 Media Server. Below are the steps that diablo 2 items suggests which can let you achieve that.

Install necessary codex or media player:
sudo apt-get install vlc ffmpeg mencoder mplayer

Install Sun Java:
sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts

Download PS3 Media Server. Then extract the downloaded tar to any location:
tar xzf pms-generic-linux-unix-1.20.412.tgz

Go to the folder that you have just extracted:
cd pms-linux-1.20.412/

Run the PS3 Media Server simply by:
./PMS.sh
Command above will open the PlayStation 3 Media Server user interface.

Movie Subtitles on Ubuntu 10.10
The yesgamers is the d2 store points out that the subtitle broke for Ubuntu 10.10. This is due to Mplayer needs to know the location of a TrueType Font to show movie subtitles. Command below will fix it:
sudo apt-get install ttf-bitstream-vera

ln -sv /usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf ~/.mplayer/subfont.ttf

Disable ASS/SSA subtitles:
1. Go to PS3 Media Server user interface. Go to “Transcoding Settings” tab.
2. Uncheck ASS/SSA subtitles checkbox.

Playing 1080p Video in Ubuntu Without Lag

I have not-so-bad specs for my laptop:
– Dell XPS M1530
– Intel Code 2 Duo CPU 2.40GHz
– 4GB RAM
– Running Ubuntu Karmic Koala 9.10

I have no problem running 720p .mkv HD video files. No lagging, no dropped frames whatsover. However, when running 1080p .mkv files, especially those big sizes full-HD Blue Ray medias, I have:
– Lagging,
– Dropped frames,
– 100% CPU utilizations.

It doesn’t matter if I’m using VLC, or Totem Movie Player, it will always have those problem above. From what I’ve read, this is probably due to FFMpeg codecs for H.264 decoding.

However, I have a solution, found from http://ubuntuforums.org/showthread.php?t=1037625

Below are the steps:
1. Install mplayer:
sudo apt-get install mplayer-nogui

2. Run your 1080p .mkv files with it:
mplayer -vo vdpau -vc ffh264vdpau /path/to/the/mkv/file

Now the HD movies playing in my Ubuntu laptop are smooth as it can be.
Try it out. Cheers.