- Add grabber for mncast
authorRalf Ertzinger <sun@lain.camperquake.de>
Sun, 4 May 2008 11:13:45 +0000 (13:13 +0200)
committerRalf Ertzinger <sun@lain.camperquake.de>
Sun, 4 May 2008 11:13:45 +0000 (13:13 +0200)
videosite/MNCastGrabber.pm [new file with mode: 0644]

diff --git a/videosite/MNCastGrabber.pm b/videosite/MNCastGrabber.pm
new file mode 100644 (file)
index 0000000..344bc2c
--- /dev/null
@@ -0,0 +1,93 @@
+# (c) 2008 by Ralf Ertzinger <ralf@camperquake.de>
+# licensed under GNU GPL v2
+#
+# Grabber for mncast.com
+
+package MNCastGrabber;
+
+use GrabberBase;
+@ISA = qw(GrabberBase);
+
+use LWP::Simple qw(!get);
+use XML::Simple;
+use HTML::TokeParser;
+use Data::Dumper;
+
+use strict;
+
+sub new {
+    my $class = shift;
+    my $self = $class->SUPER::new();
+
+    $self->{'NAME'} = 'mncast';
+    $self->{'PATTERNS'} = ['(http://www\.mncast\.com/\?(\d+))'];
+
+    bless($self, $class);
+    $self->_prepare_parameters();
+
+    return $self;
+}
+
+sub _parse {
+    my $self = shift;
+    my $url = shift;
+    my $pattern = shift;
+    my $content;
+    my $metadata = {};
+    my $p;
+    my $t;
+    my @accum;
+    my $vid;
+
+    $url =~ m|$pattern|;
+    $url = $1;
+
+    $metadata->{'URL'} = $url;
+    $metadata->{'ID'} = $2;
+    $metadata->{'TYPE'} = 'video';
+    $metadata->{'SOURCE'} = $self->{'NAME'};
+    $metadata->{'TITLE'} = undef;
+    $metadata->{'DLURL'} = undef;
+
+    # First, get a webpage containing the video ID
+    unless(defined($content = LWP::Simple::get(sprintf('http://www.mncast.com/player/index.asp?mnum=%s', $2)))) {
+        $self->error('Could not download player page');
+        return undef;
+    }
+
+    $p = HTML::TokeParser->new(\$content);
+
+    while ($t = $p->get_tag('script')) {
+        if ($p->get_text() =~ m|strMID = \x22([^\x22]+)\x22|s) {
+            $vid = $1;
+            last;
+        }
+    }
+
+    # Get the XML file containing the video metadata
+    unless(defined($content = LWP::Simple::get(sprintf('http://www.mncast.com/_MovieInfo_/_MovieInfoXML_Tag_.asp?movieID=%s&loginPNum=-1&player=0', $vid)))) {
+        $self->error('Could not download XML metadata');
+        return undef;
+    }
+
+    # There is no XML header in the data, which makes XML::Simple unhappy
+    $content = '<?xml version="1.0" encoding="UTF-8"?>' . $content;
+    $p = XML::Simple->new();
+
+    unless(defined($t = $p->XMLin($content, KeepRoot => 1))) {
+        $self->error('Could not parse XML metadata');
+        return undef;
+    }
+
+    $metadata->{'DLURL'} = sprintf('http://%s.flv', $t->{'moviedata'}->{'url'});
+    $metadata->{'TITLE'} = $t->{'moviedata'}->{'title'};
+
+    unless(defined($metadata->{'DLURL'}) && defined($metadata->{'TITLE'})) {
+        $self->error('Could not extract download URL and title');
+        return undef;
+    }
+
+    return $metadata;
+}
+
+1;