[mythtv-users] MythWeb from URL to modified filenames via utils.php, handler.pl, tv.pl and others

Stefan Wolpert mythtv at wolps.com
Fri Feb 18 02:20:30 UTC 2011


On Sun, Jan 23, 2011 at 2:15 AM, Nick Rout <nick.rout at gmail.com> wrote:
>
> On Sat, Jan 22, 2011 at 7:00 PM, Stefan Wolpert <mythtv at wolps.com> wrote:
> > Hello All,
> >
[snip]
> > I cannot figure out exactly how
> > the MythWeb URLs are translated to filenames on the hard disk.
[snip]
>
> My understanding is tha both are different representations of the
> channel and start of recording time. eg
>
>
> http://media/mythweb/tv/detail/2937/1295764140
>
> translates to 2937_201101232130.mpg
>
> The 1295764140 is one of those unixy timestamps that uses the number
> of seconds since 1970, whereas 201101231930 is the year, month, date,
> time representation
>
[snip]


I finally had a chance to figure it out.  The email is long-winded,
but hopefully in-depth enough to help someone in the future.
You might want to use the following explanations to:
    Display the filename or path of the recorded video in MythWeb
    Link to a modified version of the video (or transcoded version) in MythWeb

Definitions:
/mythweb/ = /var/www/mythweb/ or wherever you mythweb dir is
I put actual code within square brackets.

Let's look at the Perl scripts that the following example URI calls
http://server//mythweb/pl/stream/1001/1297821600.asx
(not sure why the second // is there)

1. Redirect all MythWeb http /pl/* requests to the mythweb.pl
    [RewriteRule     ^(pl(/.*)?)$            mythweb.pl/$1] from
/mythweb/mythweb.conf.apache
    For the example link:
http://server/mythweb/mythweb.pl/stream/1001/1297821600.asx

2. Extract the type of request, channel ID and start time from the
virtual "URI". Include the appropriate handler
    [require "modules/$Path[0]/handler.pl";] from /mythweb/mythweb.pl
    For the example link: include /mythweb/modules/stream/handler.pl
    The request information (module chanid starttime
optional-extension) is stuffed into the $Path array.

(Note: From here, I only looked into the stream module)

3. Include /mythweb/modules/stream/tv.pl and include the proper
streaming format Perl script
    [require "modules/$Path[0]/tv.pl";]
    [if ($ENV{'REQUEST_URI'} =~ /\.asx$/i) {
            require "modules/$Path[0]/stream_asx.pl";]
    Now here is where the guts start to become evident.  To add a
filetype, you'll need to add a case to include your new handling
script.  Notice that the else statement points to stream_raw.pl , the
reason for this will become evident later.
    For the example link: include /mythweb/modules/stream/stream_asx.pl

4. /mythweb/modules/stream/tv.pl
    This script looks up the requested chanid and starttime from the
URI to find the actual recording. In the rest of the scripts "below"
handler.pl will have access to the variables from tv.pl because they
are "required".  The key variables you might be interested in are
evident in this single line of code:
    [$filename = "$video_dir/$basename";] and $basename includes the
file extension.

5. /mythweb/modules/stream/stream_asx.pl
    Continuing the example URI of
http://server//mythweb/pl/stream/1001/1297821600.asx , stream_asx.pl
generates the ASX file (Advanced Stream Redirector), which is
basically XML that points to a web address to stream a video.  If you
open a MythWeb ASX file with a text editor, you'll notice that the
HREF points to the same URI as the "Direct Download" link, which means
that the video data is handled by stream_raw.pl

Other important things to know to modify the MythWeb streamers:
-- recordings.php (or the web interface you want to change)
    For me, I just use the default interface, so I modified
/mythweb/modules/tv/tmpl/default/recorded.php to show what I wanted.
Note: [video_url($show, true)] is the same as [video_url($show,
'asx')]

-- the video_url function within /mythweb/includes/utils.php
    This is important to return the properly coded URL and extension
for a web link.


My reasons for these modifications was that I wanted:
    Original recordings to remain as just that, unchanged in name and
content for MythTV frontends (commercials intact, for auto-skip)
    In MythWeb, separate links to download the original recording or
commercials removed version
    In MythWeb, stream the commercial-free version via flowplayer

If you have specific questions about how I did this, feel free to
email me.  I've attached a zip of I think all the relevant files so
you can reference things better.


Stefan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mythweb_mods.zip
Type: application/zip
Size: 17310 bytes
Desc: not available
Url : http://mythtv.org/pipermail/mythtv-users/attachments/20110217/006e4ad0/attachment-0001.zip 


More information about the mythtv-users mailing list