2 # @(#)$Header: /home/mythtv/mythtvrep/scripts/topdocumentaryfilm.pl,v 1.17 2010/07/24 23:28:11 mythtv Exp $
3 # Auric 2010/01/10 http://web.aanet.com.au/auric/
5 # MythNetvision Grabber Script for topdocumentaryfilm site.
7 # If you want to alter any of the default settings.
8 # Create/Change $HOME/.mythtv/MythNetvision/userGrabberPrefs/topdocumentaryfilm.cfg
11 # playerargs=-fs -zoom %MEDIAURL%
13 # Some settings you can have in this are
14 # Print info/progress message: 0 - off, 1 - low ,2 - high
16 # Info messages go to: 0 = stderr, filename = filename
18 # External player to use
20 # Args to external player %MEDIAURL% will be replaced with content url
22 # External download to use
24 # Args to external download %MEDIAURL% will be replaced with content url
26 # A network player like a flash or html5 html. TODO 0.24 May not be approved
30 # Seconds to cache results Default 72000
33 ################################################################################
38 use HTML::TreeBuilder;
47 use FindBin '$Bin', '$Script';
48 use lib "$Bin/nv_perl_libs";
51 #################################### Settings #################################
52 # Load from config file. May overwrite above.
53 mnvloadconfig(fileparse($Script, '.pl'), "notused");
54 # SKIP completely skips the video
56 'youtube.com' => '&autoplay=1',
57 '220.ro' => '&aplay=true',
58 'megavideo.com' => 'SKIP',
59 'veoh.com' => 'videoAutoPlay=1',
60 'crunchyroll.com' => 'auto_play=true',
61 'mediaservices.myspace.com' => ',AutoPlay=true',
64 #################################### Globals ##################################
65 my $version = '$Revision: 1.17 $'; $version =~ s/\D*([\d\.]+)\D*/$1/; # rcs tag populated
66 my $command = "topdocumentaryfilm.pl"; my $commandthumbnail = "topdocumentaryfilm.png"; my $author = "Auric";
67 my $site = 'TopDocumentaryFilms';
68 my $description = 'Great collection of documentary movies';
69 my $baseurl = 'http://topdocumentaryfilms.com/';
70 my $baseicon = 'http://www.danaroc.com/ezine_pics_031510_websites.jpg';
71 my $store = "/tmp/.${site}.diritemsref.store";
72 our ($opt_v, $opt_T, $opt_p, $opt_S);
75 #################################### Site Specific Subs ##########################
76 # Build all vid items for all directories
77 # input hash ref to { "directory name" => [array of anonymous hash's] }
79 # 'dirthumbnail' => $icon,
81 # 'mythtv:subtitle' => "",
82 # 'author' => $author,
83 # 'pubDate' => $pubDate,
84 # 'description' => $description,
86 # 'player' => $player,
87 # 'playerargs' => $playerargs,
88 # 'download' => $download,
89 # 'downloadargs' => $downloadargs,
90 # 'media:thumbnailurl' => "",
91 # 'media:contenturl' => $contenturl,
92 # 'media:contentlength' => $length,
93 # 'media:contentduration' => "",
94 # 'media:contentwidth' => "",
95 # 'media:contentheight' => "",
96 # 'media:contentlanguage' => $language,
98 # 'mythtv:country' => ""
99 # 'mythtv:season' => ""
100 # 'mythtv:episode' => ""
101 # 'mythtv:customhtml' => ""
103 # Basically this hash ref is what you need to build.
108 my $diritemsref = shift @_;
109 my $baseurl = shift @_;
111 my $dirurlsref = builddirurls($baseurl);
112 my $vidurlsref = buildvidurls($dirurlsref);
114 foreach my $dir (keys(%$vidurlsref)) {
115 my $diritemsfound = 0;
116 foreach my $urltitle (@{$vidurlsref->{$dir}}) {
117 my($url, $title) = @{$urltitle};
118 my $found = builditems($diritemsref, $dir, $url, $title);
119 $itemsfound += $found;
120 $diritemsfound += $found;
122 mnvinfomsg(1, "$dir Items found $diritemsfound");
130 $link = decode_entities($link);
131 unless ($link =~ s/(.*[?&]autoplay=)false(.*)/${1}true${2}/i) {
132 unless ($link =~ s/(.*[?&]autostart=)false(.*)/${1}true${2}/i) {
133 unless ($link =~ s/(.*[?&]aplay=)false(.*)/${1}true${2}/i) {
134 unless ($link =~ s/(.*[?&]autoplay=)0(.*)/${1}1${2}/i) {
135 unless ($link =~ s/(.*[?&]autostart=)0(.*)/${1}1${2}/i) {
136 unless ($link =~ s/(.*[?&]aplay=)0(.*)/${1}1${2}/i) {
137 foreach my $ap (keys(%autoplay)) {
138 if ($link =~ /$ap/) {
139 ($autoplay{$ap}) or return encode_entities($link);
140 ($autoplay{$ap} eq 'SKIP') and return 0;
141 if ($autoplay{$ap} =~ /^[\?\&,]/) {
142 $link .= $autoplay{$ap};
145 $link .= '&' . $autoplay{$ap};
147 $link .= '?' . $autoplay{$ap};
150 return encode_entities($link);
154 $link .= '&' . mnvgetconfig('defaultautoplay');
156 $link .= '?' . mnvgetconfig('defaultautoplay');
158 return encode_entities($link);
167 # Collect url's of all the podcasts
169 # return hash ref to { "directory name" => "url" }
171 my $baseurl = shift @_;
175 mnvinfomsg(1, "Getting $baseurl");
176 my $content = get($baseurl);
178 die "Could not retrieve $baseurl";
180 my $tree = HTML::TreeBuilder->new;
181 eval { $tree->parse($content); };
183 die "$baseurl parse failed, $@";
187 my @ptrs = $tree->find_by_tag_name('a');
188 foreach my $ptr (@ptrs) {
189 if ($ptr->attr('href') =~ /topdocumentaryfilms.com\/category\//) {
190 my $dir = $ptr->as_trimmed_text();
191 $dirurls{$dir} = mnvcleantext($ptr->attr('href'));
194 (keys(%dirurls)) or die "No urls found";
199 # Collect url's to all vids
200 # return hash ref to { "directory name" => "url" }
201 # return hash ref to { "directory name" => [[url,title]] }
203 my $dirurls = shift @_;
207 foreach my $dir (sort(keys(%$dirurls))) {
208 mnvinfomsg(1, "Getting $dir $dirurls->{$dir}");
209 my $content = get($dirurls->{$dir});
211 warn "Could not retrieve $dirurls->{$dir}";
214 my $tree = HTML::TreeBuilder->new;
215 eval { $tree->parse($content); };
217 warn "$dirurls->{$dir} parse failed, $@";
222 my @ptrs = $tree->find_by_tag_name('h2');
225 foreach my $ptr (@ptrs) {
226 my $a = $ptr->find_by_tag_name('a');
228 my $url = mnvcleantext($a->attr('href'));
229 my $title = mnvcleantext($a->as_trimmed_text());
230 push(@{$vidurls{$dir}}, [$url, $title]);
237 # input hash ref to { "directory name" => [array of anonymous hash's] }
238 # input "directory name"
241 # output number of items added
243 my $diritemsref = shift @_;
246 my $title = shift @_;
248 mnvinfomsg(2, "Getting $dir Episode $url");
249 my $content = get($url);
251 warn "Could not retrieve $url";
254 my $tree = HTML::TreeBuilder->new;
255 eval { $tree->parse($content); };
257 warn "$url parse failed, $@";
262 my $desc = ""; my $icon = $baseicon; my @links;
263 my $pc = $tree->look_down('class', 'postContent');
265 my $ptr = $pc->find_by_tag_name('p');
266 ($ptr) and $desc = mnvcleantext($ptr->as_trimmed_text());
267 $ptr = $pc->find_by_tag_name('img');
268 ($ptr) and $icon = mnvcleantext($ptr->attr('src'));
269 my @ptrs = $pc->find_by_tag_name('embed');
270 foreach my $ptr (@ptrs) {
271 my $l = mnvcleantext($ptr->attr('src'));
273 my $lap = addautoplay($l);
277 mnvinfomsg(2, "Skipped $l");
280 (@links) or return 0;
284 my $oldtitle = $title;
285 foreach my $link (@links) {
287 $title = "$oldtitle Pt $addpart";
290 push(@{$diritemsref->{$dir}}, {
291 'dirthumbnail' => $icon,
293 'mythtv:subtitle' => "",
296 'description' => $desc,
298 'player' => mnvgetconfig('player'),
299 'playerargs' => mnvgetconfig('playerargs'),
300 'download' => mnvgetconfig('download'),
301 'downloadargs' => mnvgetconfig('downloadargs'),
302 'media:thumbnailurl' => $icon,
303 'media:contenturl' => $link,
304 'media:contentlength' => "",
305 'media:contentduration' => "",
306 'media:contentwidth' => "",
307 'media:contentheight' => "",
308 'media:contentlanguage' => "",
310 'mythtv:country' => $country,
311 'mythtv:season' => "",
312 'mythtv:episode' => "",
313 'mythtv:customhtml' => "no"
316 mnvinfomsg(2, "Added $title");
321 #################################### Main #####################################
322 # If you copy this for another site, hopefully these won't need to changed
326 ($mnvcommonsubs::netvisionver == 23) and print "$site|TS\n";
327 ($mnvcommonsubs::netvisionver > 23) and mnvprintversion($site, $command, $author, $commandthumbnail, $version, $description);
331 my $type; my $page = 1; my $search = "";
337 ($opt_p) and $page = $opt_p;
339 print STDERR "Must have -T or -S option\n";
343 $SIG{'INT'} = \&mnvcleanexit;
344 $SIG{'HUP'} = \&mnvcleanexit;
345 $SIG{'TERM'} = \&mnvcleanexit;
346 $SIG{'QUIT'} = \&mnvcleanexit;
348 my $diritemsref = \%diritems;
349 my $totalitems = 0; my $filtereditems = 0;
350 my $ss = stat($store);
351 if (($ss) && (time() - $ss->mtime) < mnvgetconfig('cachetime')) {
352 eval { $diritemsref = retrieve($store); };
354 die "Could not load store, $@";
356 $totalitems = mnvnumresults($diritemsref);
357 mnvinfomsg(1, "Using previous run data");
359 $totalitems = builddiritems($diritemsref, $baseurl);
360 eval { store($diritemsref, $store); };
362 warn "Could not save store, $@";
368 <title>'.$site.'</title>
369 <link>'.$baseurl.'</link>
370 <description>'.$description.'</description>'."\n";
371 if ($type eq "search") {
372 $filtereditems = mnvfilter($diritemsref, $search);
373 mnvprintsearch($diritemsref, $page);
374 mnvinfomsg(1, "Total Items match $filtereditems of $totalitems");
376 mnvprinttree($diritemsref);
377 mnvinfomsg(1, "Total Items found $totalitems");
379 print "</channel>\n";