# (c) 2008 by Ralf Ertzinger # licensed under GNU GPL v2 # # Grabber for mncast.com package videosite::MNCastGrabber; use videosite::GrabberBase; @ISA = qw(videosite::GrabberBase); use XML::Simple; use HTML::TokeParser; use Data::Dumper; use strict; sub new { my $class = shift; my $self = $class->SUPER::new( NAME => 'mncast', PATTERNS => ['(http://www\.mncast\.com/\?(\d+))'], @_, ); return bless($self, $class); } sub _parse { my $self = shift; my $url = shift; my $pattern = shift; my $content; my $metadata = {}; my $p; my $t; my @accum; my $vid; my $ua = $self->ua(); $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 = $self->simple_get(sprintf('http://www.mncast.com/player/index.asp?mnum=%s', $2), $ua))) { $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 = $self->simple_get(sprintf('http://www.mncast.com/_MovieInfo_/_MovieInfoXML_Tag_v2.asp?movieID=%s&loginPNum=-1&player=0', $vid), $ua))) { $self->error('Could not download XML metadata'); return undef; } # There is no XML header in the data, which makes XML::Simple unhappy $content = '' . $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;