--- /dev/null
+# (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;