Mythweb-rss.pl

From MythTV Official Wiki
Revision as of 16:42, 31 December 2012 by Wagnerrp (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Author roach
Description A perl script to provide a RSS source for recorded programs, allowing integration on some media players.
Supports Version26.png 


This is a quick RSS source plugin / extender for mythweb.

Source code

Application-x-perl.png mythweb-rss.pl

#!/usr/bin/perl -w
#
# Provides RSS for recorded programs.
#
# @url       $URL$
# @date      $Date$
# @version   $Revision$
# @author    $Author$
# @license   GPL
#

# Install : put in the same directory as mythweb.pl, read below about config.xml

# Includes
# requires Net::UPnP::QueryResponse
# requires .mythtv/config.xml for the uid of the web server.
    use DBI;
    use MythTV;
    use CGI qw/:standard/;
    use XML::RSS;
    use DateTime;

# Connect to mythbackend
    my $Myth = new MythTV({'connect' => 0});

# Connect to the database
    $dbh = $Myth->{'dbh'};

# set url
    my $mythweburl = "http://".$ENV{'SERVER_NAME'};
    my $mythicon = $mythweburl."skins/default/img/tv.png";

# execute

    my $sth = $dbh->prepare('SELECT chanid,UNIX_TIMESTAMP(starttime),title,description,basename,hostname FROM recorded ORDER BY starttime DESC LIMIT 100')
            or die "Couldn't prepare statement: " . $dbh->errstr;

    $sth->execute();

    my $rss = new XML::RSS (version => '2.0');

    my $rowcounter = 0;

    while (@data = $sth->fetchrow_array()) {
     my $chanid = $data[0];
     my $starttimets = $data[1];
     my $title = $data[2];
     my $description = $data[3];
     my $basename = $data[4];
     my $hostname = $data[5];

     my $link = $mythweburl."/pl/stream/".$chanid."/".$starttimets.".asx";

# dont know
     my $thumb = $mythweburl."/tv/get_pixmap/".$hostname."/".$chanid."/".$starttimets."/100/56/-1/".$basename.".100x56x-1.png";

# post date
     $dt = DateTime->from_epoch( epoch => $starttimets );
     $postdate = $dt->day_abbr.", ".$dt->day." ".$dt->month_abbr." ".$dt->year." ".$dt->hms." ".$dt->time_zone_short_name;

     $rss->add_item(
        title           => "$title",
        link            => "$link",
        description     => "$description",
        enclosure       => {
          url           => "$thumb",
          type          => "image/png",
        },
        pubDate         => "$postdate",
        guid            => "$basename",
     );

# no examples of just pulling the first row from teh array in dbi so
     $rowcounter ++;
     if ($rowcounter == 1) {
        $dt = DateTime->from_epoch( epoch => $starttimets );
        $rssdate = $dt->datetime();
     };

    };

    $sth->finish;

    $dbh->disconnect;

    $rss->channel(
      title             => "mythweb",
      link              => "$mythweburl",
      description       => "Most recent mythtv recordings",
      dc                => {
        date            => "$rssdate",
        subject         => "MythTV Recordings",
        creator         => 'your@email.here',
        publisher       => 'your@email.here',
        language        => 'en-us',
      },
      syn               => {
        updatePeriod    => "hourly",
        updateFrequency => "1",
        updateBase      => "1901-01-01T00:00+00:00",
      }
    );

    $rss->image(
      title  => "MythWeb RSS",
      url    => "$mythicon",
      link   => "$mythweburl",
      dc => {
        creator  => "MythTV",
      },
    );

   print CGI->header('text/xml');
   print $rss->as_string