~davewalker/xmltv/544522

« back to all changes in this revision

Viewing changes to lib/IMDB.pm

  • Committer: Bazaar Package Importer
  • Author(s): Mario Limonciello
  • Date: 2008-02-20 09:32:36 UTC
  • mfrom: (1.2.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080220093236-4e57hpj6ax3399hy
Tags: 0.5.51-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Fixes multiple broken grabbers (LP: #193703)
  - Update 06_grab_no.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
# $Id: IMDB.pm,v 1.53 2007/01/12 20:08:47 jveldhuis Exp $
 
2
# $Id: IMDB.pm,v 1.54 2007/11/30 00:28:19 jveldhuis Exp $
3
3
#
4
4
# The IMDB file contains two packages:
5
5
# 1. XMLTV::IMDB::Cruncher package which parses and manages IMDB "lists" files
33
33
 
34
34
package XMLTV::IMDB;
35
35
 
36
 
our $VERSION = '0.6';
 
36
#
 
37
# HISTORY
 
38
# .6 = what was here for the longest time
 
39
# .7 = fixed file size est calculations
 
40
#    = moviedb.info now includes _file_size_uncompressed values for each downloaded file
 
41
#
 
42
our $VERSION = '0.7';
37
43
 
38
44
sub new
39
45
{
1877
1883
    return(0);
1878
1884
}
1879
1885
 
1880
 
sub dbinfoCalcEstimate($$$)
 
1886
sub dbinfoGetFileSize($$)
1881
1887
{
1882
 
    my ($self, $key, $estimateSizePerEntry)=@_;
 
1888
    my ($self, $key)=@_;
1883
1889
    
1884
1890
    if ( !defined($self->{imdbListFiles}->{$key}) ) {
1885
1891
        die ("invalid call");
1890
1896
    if ( $self->{imdbListFiles}->{$key}=~m/.gz$/) {
1891
1897
        if ( open(my $fd, "gzip -l ".$self->{imdbListFiles}->{$key}."|") ) {
1892
1898
            # if parse fails, then defalt to wild ass guess of compression of 65%
1893
 
            $fileSize=int($fileSize*100)/(100-65);
 
1899
            $fileSize=int(($fileSize*100)/(100-65));
1894
1900
 
1895
1901
            while(<$fd>) {
1896
1902
                if ( m/^\s*\d+\s+(\d+)/ ) {
1901
1907
        }
1902
1908
        else {
1903
1909
            # wild ass guess of compression of 65%
1904
 
            $fileSize=int($fileSize*100)/(100-65);
 
1910
            $fileSize=int(($fileSize*100)/(100-65));
1905
1911
        }
1906
1912
    }
 
1913
    return($fileSize);
 
1914
}
 
1915
 
 
1916
sub dbinfoCalcEstimate($$$)
 
1917
{
 
1918
    my ($self, $key, $estimateSizePerEntry)=@_;
 
1919
 
 
1920
    my $fileSize=$self->dbinfoGetFileSize($key);
 
1921
 
1907
1922
    my $countEstimate=int($fileSize/$estimateSizePerEntry);
1908
 
 
 
1923
    
1909
1924
    $self->dbinfoAdd($key."_list_file", $self->{imdbListFiles}->{$key});
1910
 
    $self->dbinfoAdd($key."_list_file_size", $fileSize);
 
1925
    $self->dbinfoAdd($key."_list_file_size", int(-s "$self->{imdbListFiles}->{$key}"));
 
1926
    $self->dbinfoAdd($key."_list_file_size_uncompressed", $fileSize);
1911
1927
    $self->dbinfoAdd($key."_list_count_estimate", $countEstimate);
1912
1928
    return($countEstimate);
1913
1929
}
1914
1930
 
 
1931
sub dbinfoCalcBytesPerEntry($$$)
 
1932
{
 
1933
    my ($self, $key, $calcActualForThisNumber)=@_;
 
1934
 
 
1935
    my $fileSize=$self->dbinfoGetFileSize($key);
 
1936
    
 
1937
    return(int($fileSize/$calcActualForThisNumber));
 
1938
}
 
1939
 
1915
1940
sub invokeStage($$)
1916
1941
{
1917
1942
    my ($self, $stage)=@_;
1929
1954
            return(1);
1930
1955
        }
1931
1956
        elsif ( abs($num - $countEstimate) > $countEstimate*.05 ) {
1932
 
            $self->status("ARG estimate of $countEstimate for movies needs updating, found $num");
 
1957
            my $better=$self->dbinfoCalcBytesPerEntry("movies", $num);
 
1958
            $self->status("ARG estimate of $countEstimate for movies needs updating, found $num ($better bytes/entry)");
1933
1959
        }
1934
1960
        $self->dbinfoAdd("db_stat_movie_count", "$num");
1935
1961
 
1969
1995
    elsif ( $stage == 2 ) {
1970
1996
        $self->status("parsing Directors list for stage $stage..");
1971
1997
 
1972
 
        my $countEstimate=$self->dbinfoCalcEstimate("directors", 184);
 
1998
        my $countEstimate=$self->dbinfoCalcEstimate("directors", 204);
1973
1999
 
1974
2000
        my $num=$self->readCastOrDirectors("Directors", $countEstimate, "$self->{imdbListFiles}->{directors}");
1975
2001
        if ( $num < 0 ) {
1979
2005
            return(1);
1980
2006
        }
1981
2007
        elsif ( abs($num - $countEstimate) > $countEstimate*.05 ) {
1982
 
            $self->status("ARG estimate of $countEstimate for directors needs updating, found $num");
 
2008
            my $better=$self->dbinfoCalcBytesPerEntry("directors", $num);
 
2009
            $self->status("ARG estimate of $countEstimate for directors needs updating, found $num ($better bytes/entry)");
1983
2010
        }
1984
2011
        $self->dbinfoAdd("db_stat_director_count", "$num");
1985
2012
 
2035
2062
        $self->status("parsing Actors list for stage $stage..");
2036
2063
 
2037
2064
        #print "re-reading movies into memory for reverse lookup..\n";
2038
 
        my $countEstimate=$self->dbinfoCalcEstimate("actors", 349);
 
2065
        my $countEstimate=$self->dbinfoCalcEstimate("actors", 378);
2039
2066
 
2040
2067
        my $num=$self->readCastOrDirectors("Actors", $countEstimate, "$self->{imdbListFiles}->{actors}");
2041
2068
        if ( $num < 0 ) {
2045
2072
            return(1);
2046
2073
        }
2047
2074
        elsif ( abs($num - $countEstimate) > $countEstimate*.05 ) {
2048
 
            $self->status("ARG estimate of $countEstimate for actors needs updating, found $num");
 
2075
            my $better=$self->dbinfoCalcBytesPerEntry("actors", $num);
 
2076
            $self->status("ARG estimate of $countEstimate for actors needs updating, found $num ($better bytes/entry)");
2049
2077
        }
2050
2078
        $self->dbinfoAdd("db_stat_actor_count", "$num");
2051
2079
 
2085
2113
    elsif ( $stage == 4 ) {
2086
2114
        $self->status("parsing Actresses list for stage $stage..");
2087
2115
 
2088
 
        my $countEstimate=$self->dbinfoCalcEstimate("actresses", 311);
 
2116
        my $countEstimate=$self->dbinfoCalcEstimate("actresses", 349);
2089
2117
        my $num=$self->readCastOrDirectors("Actresses", $countEstimate, "$self->{imdbListFiles}->{actresses}");
2090
2118
        if ( $num < 0 ) {
2091
2119
            if ( $num == -2 ) {
2094
2122
            return(1);
2095
2123
        }
2096
2124
        elsif ( abs($num - $countEstimate) > $countEstimate*.05 ) {
2097
 
            $self->status("ARG estimate of $countEstimate for actresses needs updating, found $num");
 
2125
            my $better=$self->dbinfoCalcBytesPerEntry("actresses", $num);
 
2126
            $self->status("ARG estimate of $countEstimate for actresses needs updating, found $num ($better bytes/entry)");
2098
2127
        }
2099
2128
        $self->dbinfoAdd("db_stat_actress_count", "$num");
2100
2129
 
2143
2172
            return(1);
2144
2173
        }
2145
2174
        elsif ( abs($num - $countEstimate) > $countEstimate*.05 ) {
2146
 
            $self->status("ARG estimate of $countEstimate for genres needs updating, found $num");
 
2175
            my $better=$self->dbinfoCalcBytesPerEntry("genres", $num);
 
2176
            $self->status("ARG estimate of $countEstimate for genres needs updating, found $num ($better bytes/entry)");
2147
2177
        }
2148
2178
        $self->dbinfoAdd("db_stat_genres_count", "$num");
2149
2179
 
2192
2222
            return(1);
2193
2223
        }
2194
2224
        elsif ( abs($num - $countEstimate) > $countEstimate*.05 ) {
2195
 
            $self->status("ARG estimate of $countEstimate for ratings needs updating, found $num");
 
2225
            my $better=$self->dbinfoCalcBytesPerEntry("ratings", $num);
 
2226
            $self->status("ARG estimate of $countEstimate for ratings needs updating, found $num ($better bytes/entry)");
2196
2227
        }
2197
2228
        $self->dbinfoAdd("db_stat_ratings_count", "$num");
2198
2229