mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
9.8 KiB

  1. --- ./grab/de_tvtoday/tv_grab_de_tvtoday.in.orig 2004-09-15 15:41:16.423279656 +0200
  2. +++ ./grab/de_tvtoday/tv_grab_de_tvtoday.in 2004-09-15 15:47:54.423774384 +0200
  3. @@ -17,7 +17,7 @@
  4. [--days N] [--offset N]
  5. [--quiet] [--slow] [--nosqueezeout]
  6. -tv_grab_de_tvtoday --list-channels
  7. +tv_grab_de_tvtoday --list-channels [--icons]
  8. =head1 DESCRIPTION
  9. @@ -62,6 +62,10 @@
  10. B<--list-channels> write output giving <channel> elements for every
  11. channel available (ignoring the config file), but no programmes.
  12. +B<--icons> get the URL for channel-logos together with the channel-list.
  13. +Mind that this takes a long time, since a webpage has to be requested for
  14. +every channel.
  15. +
  16. B<--help> print a help message and exit.
  17. =head1 SEE ALSO
  18. @@ -83,7 +87,7 @@
  19. use warnings;
  20. use strict;
  21. use Date::Manip;
  22. -use XMLTV::Version '$Id: tv_grab_de_tvtoday.in,v 1.13 2004/05/09 17:49:11 epaepa Exp $ ';
  23. +use XMLTV::Version '$Id: tv_grab_de_tvtoday.in,v 1.19 2004/07/17 14:45:34 stesie Exp $ ';
  24. use Getopt::Long;
  25. use HTML::TreeBuilder;
  26. use HTML::Entities;
  27. @@ -101,7 +105,7 @@
  28. To grab data: $0 [--config-file FILE] [--output FILE]
  29. [--days N] [--offset N]
  30. [--quiet] [--slow] [--nosqueezeout]
  31. -Channel List: $0 --list-channels
  32. +Channel List: $0 --list-channels [--icons]
  33. END
  34. ;
  35. @@ -123,6 +127,7 @@
  36. sub squeeze_out_desc($$);
  37. sub refine_category_attr($$);
  38. sub get_channels();
  39. +sub get_icons();
  40. sub channel_id($);
  41. sub split_up_names($$);
  42. sub parse_date_data($);
  43. @@ -133,7 +138,7 @@
  44. sub refine_credits($);
  45. #-- Category-Matching RegExp
  46. -our constant $category_regexp = '^(.*?\s+)?((?:[\w�������-]+-?)?(?:[Aa]genten|[Cc]harts|[Dd]oku(?:mentar|mentation)?|Episoden|[Dd]rama|[Kk]rimi|[Kk]om�die|[Ll]iteratur|[Mm]agazin|[Mm]elodram|[Pp]ortr�t|[Rr]eportage|[Rr]eihe|[Ss]oap|[Ss]atire|[Ss]erie|[Ss]tudie|[Tt]alk|[Tt]hriller)-?(?:[Ff]ilm|[Mm]ovie|[Ss]how)?s?)([\s;,]+.*)?$';
  47. +our constant $category_regexp = '^(.*?\s+)?((?:[\w�������-]+-?)?(?:[Aa]genten|[Cc]harts|[Cc]omedy|[Dd]oku(?:mentar|mentation)?|Episoden|[Dd]rama|[Kk]rimi|[Kk]om�die|[Ll]iteratur|[Mm]agazin|[Mm]elodram|[Pp]ortr�t|[Rr]eportage|[Rr]eihe|[Ss]oap|[Ss]atire|[Ss]erie|[Ss]tudie|[Tt]alk|[Tt]hriller|Wunschclip)-?(?:[Ff]ilm|[Mm]ovie|[Ss]how)?s?)([\s;,]+.*)?$';
  48. #-- DEBUG FLUFF ...
  49. my $debug = 0;
  50. @@ -166,6 +171,7 @@
  51. my $opt_slow = 0;
  52. my $opt_nosqueeze = 0;
  53. my $opt_list_channels;
  54. +my $opt_icons = 0;
  55. my $opt_help;
  56. my $opt_share;
  57. @@ -179,6 +185,7 @@
  58. 'slow' => \$opt_slow,
  59. 'nosqueezeout' => \$opt_nosqueeze,
  60. 'list-channels' => \$opt_list_channels,
  61. + 'icons' => \$opt_icons,
  62. 'help' => \$opt_help,
  63. 'share=s' => \$opt_share,
  64. ) or usage(0);
  65. @@ -222,6 +229,11 @@
  66. #-- hey, we can't live without channel data, so let's get that now!
  67. my %channels = get_channels();
  68. +#-- if wanted, get the channel logos (only in list-channels-mode done here!)
  69. +my %icons;
  70. +%icons = get_icons() if $opt_icons && $opt_list_channels;
  71. +
  72. +
  73. # share/ directory for storing channel mapping files. This next line
  74. # is altered by processing through tv_grab_de_tvtoday.PL. But we can
  75. # use the current directory instead of share/tv_grab_de_tvtoday for
  76. @@ -331,8 +343,11 @@
  77. if ($mode eq 'list-channels') {
  78. foreach (keys %channels) {
  79. - $writer->write_channel({'id'=>channel_id($_),
  80. - 'display-name'=>[[$channels{$_}, $lang]]});
  81. + my %channel = ('id' => channel_id($_),
  82. + 'display-name' => [[$channels{$_}, $lang]]);
  83. + $channel{'icon'} = [{'src' => "http://www.tvtoday.de" . $icons{$_}}]
  84. + if(defined($icons{$_}));
  85. + $writer->write_channel(\%channel);
  86. }
  87. $writer->end();
  88. @@ -346,14 +361,10 @@
  89. die "No channels specified, run me with --configure flag\n" unless(scalar(@requests));
  90. +#-- We need to wait with writing the channels, therefore buffer the program-infos
  91. +my @writebuffer;
  92. -#-- write out <channel> tags
  93. -foreach(@requests) {
  94. - $writer->write_channel({'id'=>channel_id($_),
  95. - 'display-name'=>[[$channels{$_}, $lang]]});
  96. -}
  97. -
  98. -#-- write out <programme> tags
  99. +#-- get <programme> tags
  100. my $numdays = $opt_days + $opt_offset - 1;
  101. my $bar = new Term::ProgressBar('grabbing', scalar(@requests) * $opt_days)
  102. if Have_bar && not $opt_quiet;
  103. @@ -365,6 +376,18 @@
  104. }
  105. }
  106. +#-- write out <channel> tags
  107. +foreach(@requests) {
  108. + my $id = channel_id($_);
  109. + my %channel = ('id' => $id,
  110. + 'display-name' => [[$channels{$_}, $lang]]);
  111. + $channel{'icon'} = [{'src' => "http://www.tvtoday.de" . $icons{$id}}]
  112. + if(defined($icons{$id}));
  113. + $writer->write_channel(\%channel);
  114. +}
  115. +
  116. +#-- write out <program> tags
  117. +$writer->write_programme($_) foreach(@writebuffer);
  118. #-- hey, looks like we've finished ...
  119. $writer->end();
  120. @@ -466,7 +489,9 @@
  121. @el = $el[0]->content_list();
  122. - $_ = shift @el; #-- in this column there's only the logo of the tv station, ignore that
  123. + $_ = shift @el; #-- in this column there's the logo of the tv station
  124. + $icons{$grab->{'channel'}} = $_->look_down('_tag' => 'img')->attr('src')
  125. + unless(exists($icons{$grab->{'channel'}}));
  126. $_ = shift @el; #-- there we should have the time when our show begins ...
  127. die "unable to extract time-information from html code, content:\n", $_->as_text()
  128. @@ -490,6 +515,10 @@
  129. if (ref($span) eq "") {
  130. $span =~ s/\s*\([^\(]+\)\s*$//;
  131. + if ($span =~ s/\s*(\d+)\.\sTeil//gi) {
  132. + #- strip episode number from title field
  133. + $show{q(episode-num)} = [ [ $1, "onscreen" ] ];
  134. + }
  135. $show{title} = [[ $span, $lang ]];
  136. }
  137. elsif (ref($span) eq "HTML::Element" and $span->tag eq "a") {
  138. @@ -500,6 +529,10 @@
  139. my $title = ($tag->content_list())[0];
  140. $title =~ s/\s*\([^\(]+\)\s*$//;
  141. + if ($title =~ s/\s*(\d+)\.\sTeil//gi) {
  142. + #- strip episode number from title field
  143. + $show{q(episode-num)} = [ [ $1, "onscreen" ] ];
  144. + }
  145. $show{title} = [[ $title, $lang ]];
  146. }
  147. else { die }
  148. @@ -539,7 +572,36 @@
  149. #-- okay, commit that data now ...
  150. $show{channel} = $grab->{channel};
  151. - $writer->write_programme(\%show);
  152. +
  153. + #-- try to construct clumps, if necessary ...
  154. + if(defined($show{q(desc)})
  155. + && $show{q(desc)}->[0][0] =~ m/^anschl\.\s+(.*)/) {
  156. + my $clumpname = $1;
  157. +
  158. + delete $show{q(desc)};
  159. + $show{q(clumpidx)} = '0/2'; # first of two shows ...
  160. + push @writebuffer, \%show;
  161. +
  162. + my %newshow;
  163. + foreach(qw(start stop channel)) { $newshow{$_} = $show{$_}; }
  164. + $newshow{q(clumpidx)} = '1/2'; # second show ...
  165. +
  166. + #- $clumpname may contain a extra VPS start time ...
  167. + if($clumpname =~ s/\s+\(VPS ([012]?[0-9])\.([0-6][0-9])\)//) {
  168. + $newshow{q(vps-start)} = $newshow{q(start)};
  169. + substr($newshow{"vps-start"}, 8, 4) = sprintf("%02d%02d", $1, $2);
  170. + }
  171. +
  172. + warn("title of clumped show contains problematic chars, please take care")
  173. + if($clumpname =~ m/[,;:\*]/);
  174. +
  175. + $newshow{q(title)} = [[ $clumpname, $lang ]];
  176. + push @writebuffer, \%newshow;
  177. + }
  178. + else {
  179. + #-- common clumpless show, write out ...
  180. + push @writebuffer, \%show;
  181. + }
  182. last if($grab->{"lasttime"} >= 86400 && !$grab->{"lastday"});
  183. }
  184. @@ -698,9 +760,10 @@
  185. my $show = shift;
  186. my @newdesc;
  187. - #push(@newdesc, $show->{"desc"}->[0][0]) if($show->{"desc"});
  188. - if(my @parts = ($$desc =~ m/^\s*(\(([^\)]*)\))?\s+([^,;]+)(,\s+([^,;]+)\s+([12][09][0-9]{2}(?:[\/-][0-9]{2})?))?\s*(?:; (Buch\/Regie|R): ([^;]+))?(; D: (.+))?\s*$/)) {
  189. + # try to match <category>, <country> <year>; R: <names>; D: <names> construct
  190. + # where <country>/<year> or the [RD]: stuff may be missing ...
  191. + if(my @parts = ($$desc =~ m/^\s*(\(([^\)]*)\))?\s+([^,;]+)(,\s+([^,;]+)\s+([12][09][0-9]{2}(?:[\/-][0-9]{2})?))?\s*; (?:(?:; )?(Buch\/Regie|R): ([^;]+))?\s*((?:; )?D: (.+))?\s*$/)) {
  192. $$desc = "";
  193. #-- $parts[1] is the show title in English (doesn't have to be available)
  194. @@ -806,14 +869,6 @@
  195. next;
  196. }
  197. - if (s/\(VPS ([0-2][0-9])\.([0-5][0-9])\)//) {
  198. - # assume that vps begins on the same day as the actual show,
  199. - # thus simply overwrite the stored 'start' information
  200. - # might do trouble when daylight savings time begins/ends
  201. - $show->{"vps-start"} = $show->{"start"};
  202. - substr($show->{"vps-start"}, 8, 6) = "$1$200";
  203. - }
  204. -
  205. if (my ($type, $names) = m/^\s*(Reporter:|Moderation:|Kommentar:|Gast:|G�ste:|Mit|Film von)\s+(?!de[nm]\s+)(.*?)\s*$/) {
  206. $names =~ s/\s*u.a.\s*$//;
  207. $names =~ s/\([^\(\)]+\)//g; #-- remove all brackets, that further describe the person
  208. @@ -1002,10 +1057,45 @@
  209. +#-- get channel logos
  210. +sub get_icons() {
  211. + my %icons;
  212. + my $url="http://www.tvtoday.de/tv/programm/programm.php?ztag=0&sparte=alle&uhrzeit=Ax00&sender=";
  213. + my $chan;
  214. + my $tag;
  215. + my $addr;
  216. +
  217. + my $bar = new Term::ProgressBar('grabbing icons', scalar(keys(%channels)))
  218. + if Have_bar && not $opt_quiet;
  219. +
  220. + foreach (keys %channels) {
  221. + my $tb = new HTML::TreeBuilder();
  222. + $tb->parse(get_page($url.$_));
  223. + $tag = $tb->look_down('_tag' => 'img',
  224. + sub {
  225. + return ($_[0]->attr('src') =~ m/^\/tv\/programm\/bilder\/senderlogos\//);
  226. + });
  227. +
  228. + update $bar if Have_bar && not $opt_quiet;
  229. +
  230. + unless(ref($tag) eq "HTML::Element") {
  231. + $tb->delete;
  232. + next;
  233. + };
  234. +
  235. + $icons{$_} = $tag->attr('src');
  236. + $tb->delete;
  237. + }
  238. +
  239. + return %icons;
  240. +}
  241. +
  242. +
  243. +
  244. #-- get channel listing
  245. sub get_channels() {
  246. my %channels;
  247. - my $url="http://www.tvtoday.de/tv/programm/programm.php?ztag=0&sparte=alle&uhrzeit=Ax00&sender=ZDF";
  248. + my $url="http://www.tvtoday.de/tv/programm/programm.php?ztag=0&sparte=alle&uhrzeit=Ax00&sender=alle";
  249. my $tb=new HTML::TreeBuilder();
  250. $tb->parse(get_page($url));