)
{
$rt_direct_loop_count += 1;
if( $line =~ m/\/ )
{
LOG( "$gm_call_number posible rt image found" );
$rt_found += 1;
while( $line = )
{
last if( $line =~ m/img\s+ src/i );
XDB( "$gm_call_number skipping a line in $rt_file_direct" );
}
#XDB( "\$line = ||$line||" );
( $rt_img_url = $line ) =~ s/^.*src="([^"]+)".*$/$1/;
chomp( $rt_img_url );
XDB( "\$rt_img_url = ||$rt_img_url||" );
( $rt_img_type = $rt_img_url ) =~ s/^.*\.(\w+)$/$1/;
$rt_img_file = "$data_directory/$gm_call_number-rt.$rt_img_type";
getstore( $rt_img_url, $rt_img_file );
if( ! -f $rt_img_file )
{
BAD( "$gm_call_number no \"$rt_img_file\" file found, getstore failed?" );
}
else
{
LOG( "$gm_call_number got: $rt_img_url" );
$rt_img_found += 1;
}
}
elsif( $line =~ m/\(.*)\<\/span\>$/$1/;
$rt_synopsis =~ s/^\s*//;
$rt_synopsis =~ s/\<.*\>//;
chomp( $rt_synopsis );
LOG( "$gm_call_number rt synopsis found" );
XDB( $rt_synopsis );
}
else
{
next RT_LOOP_DIRECT;
}
}
XDB( "$gm_call_number rt direct loop count = $rt_direct_loop_count" );
close RT_DIRECT;
unlink $rt_file_direct;
}
}
close RT_TITLE;
unlink( $rt_file_title );
XDB( "$gm_call_number rt search loop count = $rt_search_loop_count" );
}
# let's grab a cover from freecovers.net
undef $fc_file; undef $fc_url; undef $fc_img_url; undef $fc_img_type; undef $fc_img_file;
DBG( "$gm_call_number trying freecovers.net search by title" );
$fc_url = "$fc_base_url" . uri_escape( $gm_title );
$fc_file = "fc-$gm_call_number.html";
getstore( $fc_url, $fc_file );
if( ! -f $fc_file )
{
BAD( "$gm_call_number no \"$fc_file\" file found, getstore failed?" );
}
else
{
LOG( "$gm_call_number got: $fc_url" );
$fc_found += 1;
$fc_xml_hash = eval { XMLin( $fc_file ) };
BAD( $@ ) if( $@ );
if( defined( $fc_xml_hash ) )
{
XDB( "\$fc_xml_hash is defined" );
if( defined( $fc_xml_hash->{'err'}->{'msg'} ) )
{
BAD( "$gm_call_number fc search - " . $fc_xml_hash->{'err'}->{'msg'} );
}
elsif( defined( $fc_xml_hash->{'title'} ) )
{
XDB( "\$fc_xml_hash->{'title'} is defined" );
if( defined( $fc_xml_hash->{'title'}->{$gm_title} ) )
{
XDB( "\$fc_xml_hash->{'title'}->{$gm_title} is defined" );
if( defined( $fc_xml_hash->{'title'}->{$gm_title}->{'image'} ) )
{
XDB( $fc_xml_hash->{'title'}->{$gm_title}->{'image'} );
$fc_img_url = $fc_xml_hash->{'title'}->{$gm_title}->{'image'};
( $fc_img_type = $fc_img_url ) =~ s/^.*\.(\w+)$/$1/;
$fc_img_file = "$data_directory/$gm_call_number-fc.$fc_img_type";
getstore( $fc_img_url, $fc_img_file );
if( ! -f $fc_img_file )
{
BAD( "$gm_call_number no \"$fc_img_file\" file found, getstore failed?" );
}
else
{
LOG( "$gm_call_number got: $fc_img_url" );
$fc_img_found += 1;
}
}
else
{
XDB( "\$fc_xml_hash->{'title'}->{$gm_title}->{'image'} is not defined" );
}
}
else
{
XDB( "\$fc_xml_hash->{'title'}->{$gm_title} is not defined" );
for $t ( sort keys %{$fc_xml_hash->{'title'}} )
{
XDB( "Title contained in array: \"$t\"" );
}
}
}
else
{
XDB( "\$fc_xml_hash->{'title'} is not defined" );
}
}
else
{
XDB( "\$fc_xml_hash is not defined" );
}
}
unlink( $fc_file );
undef $fc_xml_hash;
# save dvd info to file
open INFO, ">$info_file" or $err = "$gm_call_number I can't open \"$info_file\" to save dvd info\n" and BAD( $err ); # and croak $err;
if( length( $gm_call_number ) > 0 ) { $gm_call_number =~ s|'|\'|g; print INFO "\$gm_call_number = '$gm_call_number;\n"; }
if( length( $gm_title ) > 0 ) { $gm_title =~ s|'|\'|g; print INFO "\$gm_title = '$gm_title';\n"; }
if( length( $gm_alt_title ) > 0 ) { $gm_alt_title =~ s|'|\'|g; print INFO "\$gm_alt_title = '$gm_alt_title';\n"; }
if( length( $gm_sort_title ) > 0 ) { $gm_sort_title =~ s|'|\'|g; print INFO "\$gm_sort_title = '$gm_sort_title';\n"; }
if( length( $gm_sub_title ) > 0 ) { $gm_sub_title =~ s|'|\'|g; print INFO "\$gm_sub_title = '$gm_sub_title';\n"; }
if( length( $gm_author ) > 0 ) { $gm_author =~ s|'|\'|g; print INFO "\$gm_author = '$gm_author';\n"; }
if( length( $gm_id ) > 0 ) { $gm_id =~ s|'|\'|g; print INFO "\$gm_id = '$gm_id';\n"; }
if( length( $gm_url ) > 0 ) { $gm_url =~ s|'|\'|g; print INFO "\$gm_url = '$gm_url';\n"; }
if( length( $gm_synopsis ) > 0 ) { $gm_synopsis =~ s|'|\'|g; print INFO "\$gm_synopsis = '$gm_synopsis';\n"; }
if( length( $imdb_title ) > 0 ) { $imdb_title =~ s|'|\'|g; print INFO "\$imdb_title = '$imdb_title';\n"; }
if( length( $imdb_genre ) > 0 ) { $imdb_genre =~ s|'|\'|g; print INFO "\$imdb_genre = '$imdb_genre';\n"; }
if( length( $imdb_synopsis ) > 0 ) { $imdb_synopsis =~ s|'|\'|g; print INFO "\$imdb_synopsis = '$imdb_synopsis';\n"; }
if( length( $imdb_url_search ) > 0 ) { $imdb_url_search =~ s|'|\'|g; print INFO "\$imdb_url_search = '$imdb_url_search';\n"; }
if( length( $imdb_url ) > 0 ) { $imdb_url =~ s|'|\'|g; print INFO "\$imdb_url = '$imdb_url';\n"; }
if( length( $imdb_img_url ) > 0 ) { $imdb_img_url =~ s|'|\'|g; print INFO "\$imdb_img_url = '$imdb_img_url';\n"; }
if( length( $imdb_img_file ) > 0 ) { $imdb_img_file =~ s|'|\'|g; print INFO "\$imdb_img_file = '$imdb_img_file';\n"; }
if( length( $rt_title ) > 0 ) { $rt_title =~ s|'|\'|g; print INFO "\$rt_title = '$rt_title';\n"; }
if( length( $rt_url_title ) > 0 ) { $rt_url_title =~ s|'|\'|g; print INFO "\$rt_url_title = '$rt_url_title';\n"; }
if( length( $rt_url ) > 0 ) { $rt_url =~ s|'|\'|g; print INFO "\$rt_url = '$rt_url';\n"; }
if( length( $rt_img_url ) > 0 ) { $rt_img_url =~ s|'|\'|g; print INFO "\$rt_img_url = '$rt_img_url';\n"; }
if( length( $rt_img_file ) > 0 ) { $rt_img_file =~ s|'|\'|g; print INFO "\$rt_img_file = '$rt_img_file';\n"; }
if( length( $rt_synopsis ) > 0 ) { $rt_synopsis =~ s|'|\'|g; print INFO "\$rt_synopsis = '$rt_synopsis';\n"; }
if( length( $fc_img_url ) > 0 ) { $fc_img_url =~ s|'|\'|g; print INFO "\$fc_img_url = '$fc_img_url';\n"; }
if( length( $fc_img_file ) > 0 ) { $fc_img_file =~ s|'|\'|g; print INFO "\$fc_img_file = '$fc_img_file';\n"; }
close INFO;
# put it in the db
# use this line to clear all data from the relavent mysql tables in the drupal 62 database
# truncate table moviecontent_type_movie; truncate table movienode; truncate table movienode_revisions; truncate table moviefiles; truncate table movieterm_node; truncate table movieterm_data;
$query = "SELECT nid FROM moviecontent_type_movie WHERE field_dvdb_call_number_value='$gm_call_number'";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$result = $sth->fetchrow_hashref();
$sth->finish();
if( defined( $result->{field_dvdb_call_number_value} ) && $skip_if_already_in_db )
{
LOG( "$gm_call_number \"$gm_title\" already in database as nid " . $result->{nid} );
next MAIN_LOOP;
}
undef $next_nid; undef $next_fid;
$query = "SELECT MAX(nid) + 1 AS nid, MAX(fid) + 1 AS fid FROM movienode, moviefiles";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$result = $sth->fetchrow_hashref();
$sth->finish();
if( defined( $result->{nid} ) && $result->{nid} > 1 )
{
$next_nid = $result->{nid};
DBG( "$gm_call_number next nid: $next_nid (from database)" );
}
else
{
$next_nid = 10;
DBG( "$gm_call_number next nid: $next_nid (generated by script...)" );
}
if( defined( $result->{fid} ) && $result->{fid} > 1 )
{
$next_fid = $result->{fid};
DBG( "$gm_call_number next fid: $next_fid (from database)" );
}
else
{
$next_fid = 10;
DBG( "$gm_call_number next fid: $next_fid (generated by script...)" );
}
$query = "INSERT INTO movienode "
. "(nid, vid, type, language, title, uid, status, created, changed, comment, promote, moderate, sticky, tnid, translate) "
. "VALUES ($next_nid, $next_nid, 'movie', '', " . $dbh->quote( $gm_title ) . ", 1, 1, 0, 0, 0, 1, 0, 0, 0, 0)";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$sth->finish();
$query = "INSERT INTO movienode_revisions "
. "(nid, vid, uid, title, body, teaser, log, timestamp, format) "
. "VALUES($next_nid, $next_nid, 1, " . $dbh->quote( $gm_title ) . ", '', '', '', 0, 0)";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$sth->finish();
$query ="INSERT INTO moviecontent_type_movie "
. "(vid, nid, field_dvdb_alt_title_value, field_dvdb_sort_title_value, "
. "field_dvdb_imdb_code_value, field_dvdb_call_number_value, field_dvdb_short_summary_value, field_dvdb_long_summary_value, "
. "field_dvdb_cover_fid, field_dvdb_cover_list, field_dvdb_cover_data, field_dvdb_record_id_value, field_dvdb_rotten_tomatoes_code_value) "
. "VALUES ($next_nid, $next_nid, " . $dbh->quote( $gm_alt_title ) . ", " . $dbh->quote( $gm_sort_title ) . ", "
. "'$imdb_title', '$gm_call_number', " . $dbh->quote( $gm_sub_title ) . ", " . $dbh->quote( $gm_synopsis ) . ", "
. "$next_fid, '0', 'a:0:{}', " . $dbh->quote( $gm_id ) . ", " . $dbh->quote( $rt_url ) . " )";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$sth->finish();
undef $file_name;
if( -f $fc_img_file )
{
( $file_name = $fc_img_file ) =~ s/^$data_directory\///;
XDB( "$gm_call_number using free covers image $fc_img_file" );
}
elsif( -f $rt_img_file )
{
( $file_name = $rt_img_file ) =~ s/^$data_directory\///;
XDB( "$gm_call_number using rotten tomatoes image $rt_img_file" );
}
elsif( -f $imdb_img_file )
{
( $file_name = $imdb_img_file ) =~ s/^$data_directory\///;
XDB( "$gm_call_number using imdb image $imdb_img_file" );
}
else
{
$file_name = "nopic.png";
XDB( "$gm_call_number using default image $file_name" );
}
if( $file_name !~ m/^nopic.png$/ )
{
copy( "$data_directory/$file_name", "$drupal_directory/$file_name" );
DBG( "$gm_call_number copy( \"$data_directory/$file_name\", \"$drupal_directory/$file_name\" )" ) ;
}
$query = "INSERT INTO moviefiles "
. "(fid, uid, filename, filepath, filemime, filesize, status, timestamp) "
. "VALUES ($next_fid, 1, '$file_name', '$drupal_file_path/$file_name', '', '',1 , '')";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$sth->finish();
@genres = split( ' ', $imdb_genre );
foreach $genre ( @genres )
{
undef $next_tid;
$query = "SELECT tid as tid FROM movieterm_data WHERE name=" . $dbh->quote( $genre );
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$result = $sth->fetchrow_hashref();
$sth->finish();
if( defined( $result->{tid} ) && $result->{tid} > 0 )
{
LOG( "$gm_call_number genre \"$genre\" already in database" );
$next_tid = $result->{tid};
}
else
{
LOG( "$gm_call_number Adding genre \"$genre\" to database" );
$query = "INSERT INTO movieterm_data "
. "(tid, vid, name, description, weight) "
. "VALUES('', 1, " . $dbh->quote( $genre ) . ", " . $dbh->quote( $genre ) . ", 0)";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$sth->finish();
$query = "SELECT tid as tid FROM movieterm_data WHERE name=" . $dbh->quote( $genre );
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$result = $sth->fetchrow_hashref();
$sth->finish();
if( defined( $result->{tid} ) && $result->{tid} > 0 )
{
$next_tid = $result->{tid};
$query = "INSERT INTO movieterm_hierarchy "
. "(tid, parent) "
. "VALUES($next_tid, 0)";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$sth->finish();
}
else
{
BAD( "$gm_call_number I just added genre \"$genre\" to the database, but I can't find it there now?" );
}
}
$query = "INSERT INTO movieterm_node (nid, vid, tid) VALUES($next_nid, $next_nid, $next_tid)";
DBG( "$gm_call_number $query" );
$sth = $dbh->prepare( $query );
$sth->execute();
$sth->finish();
}
}
$dbh->commit();
XDB( "goldmine loop count = $goldmine_loop_count" );
LOG( "found $gm_found_current items on goldmine request $gm_search_num => $gm_search_url" );
# multiple matches happen in the goldmine file so we need to read the whole thing and close after the loop ends
close GOLDMINE_SEARCH;
unlink $gm_search_file;
}
$dbh->disconnect();
LOG( "$gm_search_num goldmine pages -> $gm_found_total items, " . ( $gm_found_total - $gm_found_had_already ) . " were new" );
LOG( "$imdb_found found in imdb, $imdb_img_found had images" );
LOG( "$rt_found found in rotten tomatoes, $rt_img_found had images" );
LOG( "$fc_found found on freecovers.net, $fc_img_found had images" );