Go Back   maemo.org - Talk > Software > Multimedia
 
Register FAQ Community Calendar Today's Posts Search

Notices

Reply
 
Thread Tools
  #1  
Old 2010-05-27, 15:33
arajantie arajantie is offline
 
Join Date: Jan 2010
Posts: 46
Thanks!: 5
Thanked 66 Times in 19 Posts
Default TVCatchup script

With the World Cup approaching, I found it really annoying that there is no good way of watching live TV on N900 in the UK. Recorded content works well on iPlayer in the pop-out window, but live TV does not.

The obvious alternative is to use TVCatchup, who provide a lighter stream for the iPhone. N900 cannot play these streams out of the box because they use some non-standard playlist format, so I wrote a simple shell script that extracts the video stream and plays it with mplayer. For the script to work, you'll also need Firefox because I couldn't find a way to tell the built-in browser not to send the playlist to the Media Player.

Save this script as /home/user/tvcatchup.sh:
Code:
#!/bin/sh
dldir=/var/tmp
catchupdir=/home/user/.catchup
initialwait=1
buffer=1
wgetopts=""
mplayeropts=""


note()
{
/usr/bin/dbus-send --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteInfoprint string:"$1"
echo $1
}

download()
{
rm tmp*.ts
count=0
urlbase=`tail -1 $dldir/playlist.m3u8 | cut -d "/" -f 1-5`
echo Base URL: $urlbase
while [ 1 ]
        do
        wget $wgetopts -T10 `tail -1 $dldir/playlist.m3u8` -O url
        urlold=$url
        url=`tail -1 url`
        if [[ "$url" == "$urlold" ]] 
                then
                sleep 1
                else
                if [[ "`echo $url | cut -c1-4`" != "http" ]]
                        then
                        url2=$urlbase/$url
                        else
                        url2=$url
                        fi
                wget $wgetopts -T10 $url2 -O tmp$count.ts
		bytes=`wc -c < tmp$count.ts`
                echo "$count: Downloaded $bytes bytes"
		if [ "$bytes" == "0" ]
			then
			echo $url2
			echo Retrying
			else
	                count=`expr $count + 1`
			fi
                fi
        sleep 1
done
}

play()
{
count=0
while [ 1 ]
        do
        countnext=`expr $count + $buffer`
        while [ ! -e tmp$countnext.ts ]
                do
                sleep 1
                done
        cat tmp$count.ts 
        rm tmp$count.ts
        count=`expr $count + 1`
        done
}

rm $dldir/playlist.m3u8
echo Starting browser
sleep 1
/usr/bin/dbus-send --system --type=method_call --dest=com.nokia.osso_browser /com/nokia/osso_browser/request com.nokia.osso_browser.load_url string:"http://iphone.tvcatchup.com"
note "Choose the channel"
while [ ! -e $dldir/playlist.m3u8 ]
	do
	sleep 1
	done
note "Playlist file found - Buffering"
mkdir 2>/dev/null $catchupdir
cd $catchupdir
download &
while [ ! -e "$catchupdir/tmp$initialwait.ts" ]
        do
        sleep 3
	killall 2>/dev/null mediaplayer
	note "Initial buffering"
        done
killall 2>/dev/null mediaplayer
note "Starting mplayer - Please be patient!"
rm tvfifo.ts
mkfifo tvfifo.ts
play > tvfifo.ts &
mplayer $mplayeropts -fs -hardframedrop -ao pulse -cache 4096 -vfm ffmpeg -lavdopts fast tvfifo.ts
""rm -r $catchupdir
exit
You should now be able to find the TV Catchup icon (just the plain blue square) in your menu. When you click it, it opens Firefox and takes you to the TVCatchup iPhone page, where you can choose the channel you want to watch. Firefox will ask you what you want to do with playlist.m3u8. You'll need to save it to /home/user/MyDocs/.documents, which I believe is the default location. Once you have saved that file, close Firefox, and you can see in the terminal window how it starts to buffer the stream. After a while MPlayer should start playing it.

This is very experimental, so I won't give any guarantees, but it works on my phone. You need at least Mplayer and Firefox, and possibly something else too. There is a lot of room for improvement, so if anyone with more skill and experience wants to develop this further, I would encourage them to do so.

EDIT: There is now a low quality stream available on the tvcatchup.com website, which works fine on N900. However, the quality is a bit lower, so this script may still be of use. Updated the script so that it no longer needs Firefox. It runs in fullscreen mode now - press q to exit. To install, save the attached tarball and run
Code:
tar -xzvf tvcatchup.tar.gz -C /home/user
in the terminal. You need to have wget installed (thanks [DarkGUNMAN] - see post #19 for details).
Attached Files
File Type: gz tvcatchup.tar.gz (1.2 KB, 223 views)

Last edited by arajantie; 2010-06-09 at 08:57. Reason: Updated the script to use builtin browser
Reply With Quote
  #2  
Old 2010-05-27, 15:37
ddwwf1 ddwwf1 is offline
 
Join Date: Nov 2009
Posts: 237
Thanks!: 18
Thanked 44 Times in 25 Posts
Default Re: TVCatchup script

would be awesome if someone could package this up as a single download and install am really looking forward to world cup and this would be great
Reply With Quote
  #3  
Old 2010-05-27, 15:49
ddwwf1 ddwwf1 is offline
 
Join Date: Nov 2009
Posts: 237
Thanks!: 18
Thanked 44 Times in 25 Posts
Default Re: TVCatchup script

or is it possible for you to post some step by step instructions on this cheers mate
Reply With Quote
  #4  
Old 2010-05-27, 16:00
bjknight bjknight is offline
 
Join Date: Mar 2010
Posts: 81
Thanks!: 15
Thanked 54 Times in 22 Posts
Default Re: TVCatchup script

ddwwf1, if you work through the above post, you should find that it works fine.

Give it a go.
Reply With Quote
  #5  
Old 2010-05-27, 16:16
oweng's Avatar
oweng oweng is offline
 
Join Date: Jan 2010
Posts: 210
Thanks!: 120
Thanked 178 Times in 58 Posts
Default Re: TVCatchup script

Followed the steps, and tried running the Tvcatchup App (well the shortcut created). Terminal launches but closes almost straight away.

I've tried running /home/user/tvcatchup.sh
manually in terminal but I get a permission denied...



Quote:
Originally Posted by arajantie View Post
With the World Cup approaching, I found it really annoying that there is no good way of watching live TV on N900 in the UK. Recorded content works well on iPlayer in the pop-out window, but live TV does not.

The obvious alternative is to use TVCatchup, who provide a lighter stream for the iPhone. N900 cannot play these streams out of the box because they use some non-standard playlist format, so I wrote a simple shell script that extracts the video stream and plays it with mplayer. For the script to work, you'll also need Firefox because I couldn't find a way to tell the built-in browser not to send the playlist to the Media Player.

Save this script as /home/user/tvcatchup.sh:
Code:
#!/bin/sh
download()
{
rm tmp*.ts
count=0
urlbase=`tail -1 $dldir/playlist.m3u8 | cut -d "/" -f 1-5`
echo Base URL: $urlbase
while [ 1 ]
        do
        wget -q `tail -1 $dldir/playlist.m3u8` -O /tmp/test
        urlold=$url
        url=`tail -1 /tmp/test`
        if [[ "$url" == "$urlold" ]] 
                then
                sleep 1
                else
                if [[ "`echo $url | cut -c1-4`" != "http" ]]
                        then
                        url2=$urlbase/$url
                        else
                        url2=$url
                        fi
                wget -q $url2 -O tmp$count.ts
                echo $count: Downloaded `wc -c < tmp$count.ts` bytes
                count=`expr $count + 1`
                fi
        sleep 1
done
}

play()
{
count=0
while [ 1 ]
        do
        countnext=`expr $count + 2`
        while [ ! -e tmp$countnext.ts ]
                do
                sleep 1
                done
        cat tmp$count.ts 
        rm tmp$count.ts
        count=`expr $count + 1`
        done
}

dldir=/home/user/MyDocs/.documents
rm $dldir/playlist.m3u8
echo Starting Firefox
/usr/bin/dbus-send --print-reply --type=method_call --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.SystemNoteDialog string:"Choose the channel, SAVE the playlist, and CLOSE Firefox!" uint32:0 string:'note'
fennec http://iphone.tvcatchup.com
if [ ! -e $dldir/playlist.m3u8 ]
        then
        No playlist file!
        exit
        fi
catchupdir=/tmp/catchup
mkdir $catchupdir
cd $catchupdir
echo Buffering
download &
pid1=$!
echo PID1=$pid1
while [ ! -e "$catchupdir/tmp3.ts" ]
        do
        sleep 1
        done
echo Starting mplayer
rm tvfifo.ts
mkfifo tvfifo.ts
play > tvfifo.ts &
mplayer -quiet -hardframedrop -ao pulse -cache 128 tvfifo.ts
exit
and this desktop file as /home/user/.local/share/applications/hildon/tvcatchup.desktop:
Code:
[Desktop Entry]
Encoding=UTF-8
Name=TV Catchup
GenericName=TV Catchup
Exec=osso-xterm "/bin/sh /home/user/tvcatchup.sh"
Terminal=true
Type=Application
You should now be able to find the TV Catchup icon (just the plain blue square) in your menu. When you click it, it opens Firefox and takes you to the TVCatchup iPhone page, where you can choose the channel you want to watch. Firefox will ask you what you want to do with playlist.m3u8. You'll need to save it to /home/user/MyDocs/.documents, which I believe is the default location. Once you have saved that file, close Firefox, and you can see in the terminal window how it starts to buffer the stream. After a while MPlayer should start playing it.

This is very experimental, so I won't give any guarantees, but it works on my phone. You need at least Mplayer and Firefox, and possibly something else too. There is a lot of room for improvement, so if anyone with more skill and experience wants to develop this further, I would encourage them to do so.
Reply With Quote
  #6  
Old 2010-05-27, 16:18
jdave76 jdave76 is offline
 
Join Date: Oct 2009
Posts: 40
Thanks!: 20
Thanked 5 Times in 5 Posts
Default Re: TVCatchup script

this sounds great but sorry for being a nob but how do you save a script
Reply With Quote
The Following User Says Thank You to jdave76 For This Useful Post:
  #7  
Old 2010-05-27, 16:29
oweng's Avatar
oweng oweng is offline
 
Join Date: Jan 2010
Posts: 210
Thanks!: 120
Thanked 178 Times in 58 Posts
Default Re: TVCatchup script

sorry to bump but this is an exciting development
Reply With Quote
  #8  
Old 2010-05-27, 16:37
ddwwf1 ddwwf1 is offline
 
Join Date: Nov 2009
Posts: 237
Thanks!: 18
Thanked 44 Times in 25 Posts
Default Re: TVCatchup script

Quote:
Originally Posted by bjknight View Post
ddwwf1, if you work through the above post, you should find that it works fine.

Give it a go.
just not sure how to save a script in the locations specified
Reply With Quote
  #9  
Old 2010-05-27, 17:06
[DarkGUNMAN] [DarkGUNMAN] is offline
 
Join Date: Jan 2010
Posts: 309
Thanks!: 59
Thanked 456 Times in 133 Posts
Default Re: TVCatchup script

Tried the script - modified it to use Opera Mobile as the browser to download the playlist.. get the following:
Code:
~ $ sh tvcatchup.sh
Starting Opera
method return sender=:1.32 -> dest=:1.220 reply_serial=2
   uint32 10
mkdir: cannot create directory '/tmp/catchup': File exists
Buffering
rm: cannot remove 'tmp*.ts': No such file or directory
PID1=3377
Base URL: http://84.234.23.231:1935/iphone/iphone_bbcone.sdp
tvcatchup.sh: line 61: wget: not found
tail: can't open '/tmp/test': No such file or directory
tail: no files
Error on Line 61 repeats until I stop the script wth CTRL+Z
Reply With Quote
  #10  
Old 2010-05-27, 17:08
[DarkGUNMAN] [DarkGUNMAN] is offline
 
Join Date: Jan 2010
Posts: 309
Thanks!: 59
Thanked 456 Times in 133 Posts
Default Re: TVCatchup script

Quote:
Originally Posted by ddwwf1 View Post
just not sure how to save a script in the locations specified
If you saved/created the file in MyDocs, use this to move it:

mv /home/user/MyDocs/tvcatchup.sh /home/user/tvcatchup.sh
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 21:35.