Changeset 843

Show
Ignore:
Timestamp:
07/09/07 04:01:29 (6 years ago)
Author:
paul
Message:

imdb_augment_data: keep order of directors, cast and writers

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • postprocessors/imdb_augment_data

    r842 r843  
    2727 
    2828my $progname = "imdb_augment_data"; 
    29 my $version = "0.23"; 
     29my $version = "0.24"; 
    3030 
    3131use XMLTV; 
     
    521521        $tp = HTML::TokeParser->new(\$html_data); 
    522522        while (my $tag = $tp->get_tag('h5')) { 
    523                 last if ($tp->get_text =~ /^directed/i); 
     523                last if ($tp->get_text =~ /^(directed|director)/i); 
    524524        } 
    525525        while (my $tag = $tp->get_tag) { 
    526526                my $text = $tp->get_text(); 
    527                 last if (($text =~ /writing/i) || ($tag->[0] =~ /\/td/i)); 
     527                last if (($text =~ /^(writing|writer)/i) || ($tag->[0] =~ /\/td/i)); 
    528528                if ($tag->[0] eq 'a') { 
    529529                        my $id = $tag->[1]{href}; 
    530530                        next if ($id !~ /^\/name\/nm/); 
    531                         $data_cache->{movie_lookup}->{$movie_url}->{directors}->{$text} = $id; 
     531                        push(@{$data_cache->{movie_lookup}->{$movie_url}->{directors}}, [$text, $id]); 
    532532                        Shepherd::Common::log(" - parsed director ".$text." (".$id.")") if ($opt->{debug}); 
    533533                } 
     
    539539        $tp = HTML::TokeParser->new(\$html_data); 
    540540        while (my $tag = $tp->get_tag('h5')) { 
    541                 last if ($tp->get_text =~ /^writing/i); 
     541                last if ($tp->get_text =~ /^(writing|writer)/i); 
    542542        } 
    543543        while (my $tag = $tp->get_tag) { 
    544544                my $text = $tp->get_text(); 
    545545                last if ($tag->[0] =~ /div/i); 
    546                 if (($tag->[0] eq 'a') && ($text !~ /more/i)) { 
     546                if (($tag->[0] eq 'a') && ($text !~ /\bmore\b/i)) { 
    547547                        my $id = $tag->[1]{href}; 
    548548                        next if ($id !~ /^\/name\/nm/); 
    549                         $data_cache->{movie_lookup}->{$movie_url}->{writers}->{$text} = $id; 
     549                        push(@{$data_cache->{movie_lookup}->{$movie_url}->{writers}}, [$text, $id]); 
    550550                        Shepherd::Common::log(" - parsed writer ".$text." (".$id.")") if ($opt->{debug}); 
    551551                } 
     
    571571 
    572572                                if ((defined $person) && (defined $role)) { 
    573                                         $data_cache->{movie_lookup}->{$movie_url}->{cast}->{$person} = $role; 
     573                                        push(@{$data_cache->{movie_lookup}->{$movie_url}->{cast}}, [$person, $role]); 
    574574                                        Shepherd::Common::log(" - parsed cast (".$role.") ".$person) if ($opt->{debug}); 
    575575                                } 
     
    879879                } 
    880880 
    881                 $num = 0; 
    882881                if (defined $imdb->{cast}) { 
    883                         foreach my $c (sort keys %{($imdb->{cast})}) { 
    884                                 $imdb_desc .= sprintf "%s%s%s", 
    885                                   ($num > 0 ? ", " : "\n Cast: "),  
    886                                   $c,  
    887                                   ($imdb->{cast}->{$c} ? " as $imdb->{cast}->{$c}" : ""); 
    888                                 $num++; 
     882                        $num = 0; 
     883                        if (ref($imdb->{cast}) eq "ARRAY") { 
     884                                foreach my $c (@{$imdb->{cast}}) { 
     885                                        $imdb_desc .= sprintf "%s%s%s", 
     886                                        ($num > 0 ? ", " : "\n Cast: "), 
     887                                        @$c[0], 
     888                                        (@$c[1] ? " as @$c[1]" : ""); 
     889                                        $num++; 
     890                                } 
     891                        } else { # HASH 
     892                                foreach my $c (sort keys %{($imdb->{cast})}) { 
     893                                        $imdb_desc .= sprintf "%s%s%s", 
     894                                        ($num > 0 ? ", " : "\n Cast: "), 
     895                                        $c, 
     896                                        ($imdb->{cast}->{$c} ? " as $imdb->{cast}->{$c}" : ""); 
     897                                        $num++; 
     898                                } 
    889899                        } 
    890900                } 
    891901 
    892902                $imdb_desc .= sprintf "\n Directors: %s", 
    893                   join(", ",keys %{($imdb->{directors})}) 
     903                  join(", ", ref($imdb->{directors}) eq "ARRAY" ? 
     904                  map(@$_[0], @{$imdb->{directors}}) : sort keys %{$imdb->{directors}}) 
    894905                  if ($imdb->{directors}); 
    895906                $imdb_desc .= sprintf "\n Writers: %s", 
    896                   join(", ",keys %{($imdb->{writers})}) 
     907                  join(", ", ref($imdb->{writers}) eq "ARRAY" ? 
     908                  map(@$_[0], @{$imdb->{writers}}) : sort keys %{$imdb->{writers}}) 
    897909                  if ($imdb->{writers}); 
    898910 
     
    9941006 
    9951007        if (defined $imdb->{cast}) { 
    996                 foreach my $cast (sort keys %{($imdb->{cast})}) { 
     1008                foreach my $cast (ref($imdb->{cast}) eq "ARRAY" ? 
     1009                                map(@$_[0], @{$imdb->{cast}}) : sort keys %{$imdb->{cast}}) { 
    9971010                        my $found_cast = 0; 
    9981011                        if ((defined $prog->{credits}) && (defined $prog->{credits}->{actor})) { 
     
    10061019 
    10071020        if (defined $imdb->{writers}) { 
    1008                 foreach my $cast (keys %{($imdb->{writers})}) { 
     1021                foreach my $cast (ref($imdb->{writers}) eq "ARRAY" ? 
     1022                                map(@$_[0], @{$imdb->{writers}}) : sort keys %{$imdb->{writers}}) { 
    10091023                        my $found_cast = 0; 
    10101024                        if ((defined $prog->{credits}) && (defined $prog->{credits}->{writer})) { 
     
    10181032 
    10191033        if (defined $imdb->{directors}) { 
    1020                 foreach my $cast (keys %{($imdb->{directors})}) { 
     1034                foreach my $cast (ref($imdb->{directors}) eq "ARRAY" ? 
     1035                                map(@$_[0], @{$imdb->{directors}}) : sort keys %{$imdb->{directors}}) { 
    10211036                        my $found_cast = 0; 
    10221037                        if ((defined $prog->{credits}) && (defined $prog->{credits}->{director})) { 
  • status

    r842 r843  
    1515grabber         ten_website         1.01 
    1616reconciler      reconciler_mk2      0.32 
    17 postprocessor   imdb_augment_data   0.23 
     17postprocessor   imdb_augment_data   0.24 
    1818postprocessor   tvdb_augment_data   0.06 
    1919postprocessor   flag_aus_hdtv       0.18