Pages

Thursday, January 10, 2013

Simple WeepeeTV recorder


Created the record.pl script, with this simple script you can record WeepeeTV streams.

Unfortunately the WeepeeTV streams aren't that stable and ffmpeg (which is used to record) can't append recordings, so sometimes your recordings may not be complete.

How it works

Basically it will create a small shell script in /tmp which will be queued as an at job at the time you specified. This script will be executed at the specified time and will be calling ffmpeg to save the stream to a .mkv file in the outputdirectory you've specified.

Config

To run the script change the variables on top of record.pl


#make sure your ffmpeg supports https
my $FFMPEG="/usr/bin/ffmpeg-weepeetv";
my $ATCMD="/usr/bin/at";
#locations of xml source file
my $XMLFILE="wptv.xml";
#where to write the recordings
my $OUTPUTDIR="/opt/recordings";
#installation directory
my $PATH="/home/wim/wptvscraper";

Usage


record.pl --start=<time date> --duration <hh:mm:ss> --desc <description> --channel <name>

e.g.  perl record.pl --start=15:00 tomorrow --duration 00:30:00 --desc "crappy show" --channel een
records 30 minutes starting tomorrow at 15h on channel 'een'

<time date> can be anything 'at' supports, see 'man at'

Other options:
        --channels (shows available channels)


You can find the code on https://github.com/42wim/wptvscraper

10 comments:

  1. Ik heb gemerkt dat ffmpeg soms quit met errors. Ik heb dan een bash script geschreven dat de HLS stream gewoon opslaat, en als een .ts segment kleiner dan 180 bytes is nog een paar keer probeert van het opnieuw te downloaden.

    Ik heb ook dit gevonden: http://www.mythtv.org/wiki/User_Manual:Setting_up_HTTP_Live_Streaming_Recorder
    MythTV kan gebruikt worden als een backend voor de nieuwe PVR features van XBMC:
    http://wiki.xbmc.org/index.php?title=PVR/Backend/MythTV

    Cool nee? :-)

    ReplyDelete
  2. Wout, nice :) You may always share the bash script btw :)

    ReplyDelete
  3. Crappy bash script follows :-). It needs curl and stat.

    ============= save.sh ================
    #!/bin/bash
    # TODO
    # get URL from channel name
    # look at a file for start/stop times so you can change schedule on the fly
    # Usage: save.sh [base URL of the stream without ending / or stream.m3u8] [name of recording]
    base=$1
    shift
    name="$*"
    if [ -z "$base" ] || [ -z "$name" ]; then
    echo "Usage: base-url name"
    exit 1
    fi
    m3u="_recording.m3u8"
    if [ -e "$name" ] && [ -e "$name/$m3u" ]; then
    echo "$name already exists, continuing"
    else
    mkdir "$name"
    new=true
    fi
    cd "$name"
    fetch=""
    while
    for f in `curl -s $base/stream.m3u8`; do
    case "$f" in
    \#EXTINF*)
    t="$f"
    ;;
    *ts)
    if [ ! -e $f ]; then
    fetch="$fetch $f"
    echo "$t" >> $m3u
    echo "$f" >> $m3u
    fi
    ;;
    *)
    if [ -n "$new" ]; then
    echo "$f" >> $m3u
    fi
    ;;
    esac

    done
    new=
    for f in $fetch; do
    curl -s -o $f $base/$f &
    echo -n .
    done
    wait
    retry=
    for f in $fetch; do
    if [ "0`stat -f %z $f`" -lt 180 ]; then
    echo -n \!
    retry="$retry $f"
    fi
    done
    fetch="$retry"
    do
    sleep 3
    done

    ============= save.sh ================

    PS: Would be nice to get email notifications of replies on your blog

    ReplyDelete
  4. Ah I found the feature that sends notifications "aanmelden via email".

    ReplyDelete
  5. Any thoughts if this can work in Windows? (using ActivePerl or so)?

    ReplyDelete
  6. meon unfortunately not as-is because it's using also the linux 'at' to schedule the task.
    But if you got the windows ffmpeg binary you could probably use 'scheduled tasks' to schedule your recording.

    ReplyDelete
  7. @42wim Windows can also schedule using an "at" command (but is deprecated) ;-). Not the same syntax though. Quickly installed an Ubuntu VM to try this out. For a Windows-admin not an easy task :)

    ReplyDelete
  8. meon: welcome to the 'light' side ;-)

    ReplyDelete
  9. So, what was the "to be continued". I am fixing to try this out. Also, would an upgrade to 1.3 resolve this issue? I've seen online some recommend patching Prime to resolve the disk full issue.

    ReplyDelete
  10. Hi Rachid, you commented on the wrong story ;-)
    http://blog.42.be/2013/02/cisco-prime-infrastructure-ncs-12-and.html is the follow up.

    An upgrade to 1.3 will fix it, cause you first need to patch 1.2 with the patch to fix the disk full issue before you can upgrade to 1.3 ;-)

    ReplyDelete