/scripts/mixed/ads_adactus/ads_adactus.pl
Perl | 932 lines | 836 code | 55 blank | 41 comment | 24 complexity | 472b8b667075aedc0413c172f652ed2e MD5 | raw file
- #!/usr/bin/perl -I/opt/CNNi/videoscripts/libraries/perl -I/home/dboardman/bitbucket/videoscripts/libraries/perl
- # Ivan Leon
- # Date: 01 NOV 2011
- # Script: ads_adactus.pl
- #
- # $Id:$
- # Libraries
- use strict;
- use DMT::Video_Logs;
- use DMT::cgi_parser;
- use DMT::vps_xml_parser;
- use DMT::directories_parser;
- use DMT::adactussystems_parser;
- use LWP::Simple;
- use LWP::UserAgent;
- use Net::FTP;
- use Date::Manip;
- # Start Logging
- log_setglobal_logfile('ads_adactus/ads_adactus');
- log_init();
- # Global Variables
- my $scripts_root_dir = &get_directory_path('scriptsroot');
- my $script_dir = $scripts_root_dir . "/mixed/ads_adactus";
- my $in_dir = $script_dir . "/in";
- my $done_dir = $script_dir . "/done";
- my $working_dir = $script_dir . "/working";
- my $ele_in_dir = &get_directory_path('videoproductionnews') . "/videoscripts/cnn_elemental/mixed_in";
- # Get current date values
- my $current_time = localtime;
- my $current_year = &UnixDate($current_time, "%Y");
- my $current_month = &UnixDate($current_time, "%m");
- my $current_day = &UnixDate($current_time, "%d");
- # Read IN directory - Agility notifications
- log_data("Reading directory (Agility): $in_dir");
- opendir(INDIR, $in_dir) || log_error("Couldn't open $in_dir : $!");
- my @cgi_files = grep (/^cgidata_/, sort(readdir(INDIR)));
- close(INDIR);
- # Move found CGI files to the working directory
- foreach my $agility_file (@cgi_files) {
- log_system("mv " . $in_dir . "/" . $agility_file . " " . $working_dir);
- }
- # Process published videos
- foreach my $cgi_file (@cgi_files) {
- log_data("Processing CGI file: $working_dir/$cgi_file");
-
- # Get job info from XML file
- (my $cms_job_id,
- my $cms_title,
- my $cms_description,
- my $cms_author,
- my $cms_copyright,
- my $cms_job_profile,
- my $cms_source_clip,
- my $cms_basename,
- my $cms_advertiser,
- my $cms_submit_machine,
- my $cms_tool_environment) = &get_job_info($working_dir . "/" . $cgi_file);
-
- log_data("Job ID: $cms_job_id");
- log_data("Job Title: $cms_title");
- log_data("Job Description: $cms_description");
- log_data("Job Author: $cms_author");
- log_data("Job Copyright: $cms_copyright");
- log_data("Job Profile: $cms_job_profile");
- log_data("Job Source Clip: $cms_source_clip");
- log_data("Job Basename: $cms_basename");
- log_data("Job Advertiser: $cms_advertiser");
- log_data("Job Submit Machine: $cms_submit_machine");
- log_data("Job CMS Tool Environment: $cms_tool_environment");
-
- # Get the Adactus source video file name
- my $adactus_source_video_name = &get_source_video($working_dir . "/" . $cgi_file);
-
- # Determine type of job and set job values
- my $job_host = '';
- my $job_new_host = '';
- my $job_ttnsports_host = '';
- my $job_ttnsports_new_host = '';
- my $job_ttnentertainment_host = '';
- my $job_ttnentertainment_new_host = '';
- my $job_property_site = '';
- my $job_provider = '';
- my $job_group = 'Advertisements';
- my $job_external_ref = '';
- my $video_finished_dir = '';
- if ($cms_job_profile =~ /nba_ads_/) { # NBA Ads job
- log_data("NBA Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'nba';
-
- # Set the provider
- $job_provider = 'NBA';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactussportsprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
- #$job_external_ref = $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($cms_job_profile =~ /nascarads_/) { # NASCAR Ads job
- log_data("NASCAR Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'nascar';
-
- # Set the provider
- $job_provider = 'NASCAR';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactussportsprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
- #$job_external_ref = $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($cms_job_profile =~ /ncaa_ads_/) { # NCAA Ads job
- log_data("NCAA Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'ncaa';
-
- # Set the provider
- $job_provider = 'NCAA';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactussportsprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
- #$job_external_ref = $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($cms_job_profile =~ /pga_/) { # PGA Ads job
- log_data("PGA Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'pga';
-
- # Set the provider
- $job_provider = 'PGA';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactussportsprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
- #$job_external_ref = $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($cms_job_profile =~ /^ads_/) { # CNN/Money Ads job
- log_data("CNN/Money Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'cnn';
-
- # Set the provider
- $job_provider = 'CNN';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactusnews');
- $job_new_host = &get_adactus_system('adactusnewsprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishednews');
-
- # Set the external reference
- $job_external_ref = "ads/advertiser/$cms_advertiser/" . $current_year . "/" . $current_month . "/" . $cms_basename;
- #$job_external_ref = $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($cms_job_profile =~ /^TBS_AD_/) { # TBS
- log_data("TBS Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'tbs';
-
- # Set the provider
- $job_provider = 'TBS';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($cms_job_profile =~ /^TNT_ADS_/) { # TBS
- log_data("TNT Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'tnt';
-
- # Set the provider
- $job_provider = 'TNT';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($cms_job_profile =~ /^ttn_/) { # TTN Ads job
- log_data("TTN Ads job: " . $cms_job_profile);
-
- # Set the property site
- $job_property_site = 'ttn';
-
- # Set the provider - for TTN, set the initial provider to CNN, process the rest below
- $job_provider = 'CNN';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactusnews');
- $job_new_host = &get_adactus_system('adactusnewsprod');
- $job_ttnsports_host = &get_adactus_system('adactussports');
- $job_ttnsports_new_host = &get_adactus_system('adactussportsprod');
- $job_ttnentertainment_host = &get_adactus_system('adactussports');
- $job_ttnentertainment_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishednews');
-
- # Set the external reference
- $job_external_ref = "ads/ttn/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
- #$job_external_ref = $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } else { # Unknown job
- log_error("Unknown job: " . $cms_job_profile);
-
- # Move CGI file to done directory
- log_system("mv $working_dir/$cgi_file $done_dir/$cgi_file");
-
- # Process next video
- next;
- }
-
- # Log job values
- log_data("Job Adactus Host: " . $job_host);
- log_data("Job Adactus New Host: " . $job_new_host);
- log_data("Job Property Site: " . $job_property_site);
- log_data("Job Provider: " . $job_provider);
- log_data("Job Group: " . $job_group);
- log_data("Job External Reference: " . $job_external_ref);
-
- # Check if the source video file exists
- my $adactus_source_video = $video_finished_dir . "/$job_property_site/videos_repository/ads/adactus/" . $adactus_source_video_name;
- if (-e $adactus_source_video) { # Source video file found
- log_data("Source video file found: " . $adactus_source_video);
-
- if ($cms_tool_environment eq 'PROD') { # For production only
- # Set the source video URL
- my $job_source_video = "http://io.cnn.net/$job_property_site/big/ads/adactus/" . $adactus_source_video_name;
- $job_source_video =~ s/ /%20/g;
- log_data("Job Source Video URL: " . $job_source_video);
-
- # Set the header
- my $job_header = $cms_basename;
- if ($cms_job_profile =~ /interstitial/) { # Interstitial job
- $job_header = $job_header . '.interstitial';
- }
- log_data("Job Header: " . $job_header);
-
- # Check if the source video URL is valid
- if (head($job_source_video)) { # URL is valid
- log_data("Source video URL is valid: " . $job_source_video);
-
- # Submit jobs to Adactus systems
- &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_host);
- &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_new_host);
-
- # Submit the Money job to Adactus system
- if ($job_provider eq 'CNN') {
- &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_host);
- &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_new_host);
- }
-
- # For TTN jobs we must also submit to the sports and entertainment providers
- if ($job_property_site eq 'ttn') {
- log_data("Submit video to *all* TTN networks");
-
- # NBA
- &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_host);
- &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_new_host);
-
- # NCAA
- &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_host);
- &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_new_host);
-
- # PGA
- &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_host);
- &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_new_host);
-
- # TBS
- &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_host);
- &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_new_host);
-
- # TNT
- &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_host);
- &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_new_host);
- }
- } else { # URL is invalid
- log_error("Source video URL is invalid: " . $job_source_video);
-
- # Move CGI file back to IN directory
- if (-e "$working_dir/$cgi_file") {
- log_system("mv $working_dir/$cgi_file $in_dir/$cgi_file");
- }
- }
- }
-
- # Move CGI file to DONE directory
- if (-e "$working_dir/$cgi_file") {
- log_system("mv $working_dir/$cgi_file $done_dir/$cgi_file");
- }
- } else { # Source video file not found
- log_error("Source video file not found: " . $adactus_source_video);
-
- # Move CGI file back to IN directory
- if (-e "$working_dir/$cgi_file") {
- log_system("mv $working_dir/$cgi_file $in_dir/$cgi_file");
- }
- }
-
- # Cleanup IN directory
- if (-e "$in_dir/$cgi_file") { # Check if file exists
- &cleanup_in_dir("$in_dir/$cgi_file", $done_dir);
- }
- }
- # Read IN directory - VPS notifications
- log_data("Reading directory (VPS): " . $in_dir);
- opendir(INDIRVPS, $in_dir) || log_error("Couldn't open $in_dir : $!");
- my @vps_xml_files = grep (/.vps.xml$/, sort(readdir(INDIRVPS)));
- close(INDIRVPS);
- # Move found VPS XML files to the working directory
- foreach my $vps_xml_file (@vps_xml_files) {
- log_system("mv " . $in_dir . "/" . $vps_xml_file . " " . $working_dir);
- }
- # Read Elemental IN directory - VPS notifications
- log_data("Reading Elemental directory (VPS): " . $ele_in_dir);
- opendir(INDIRVPS, $ele_in_dir) || log_error("Couldn't open $ele_in_dir : $!");
- my @ele_vps_xml_files = grep (/.vps.xml$/, sort(readdir(INDIRVPS)));
- close(INDIRVPS);
- # Move found VPS XML files to the working directory
- foreach my $vps_xml_file (@ele_vps_xml_files) {
- log_system("mv " . $ele_in_dir . "/" . $vps_xml_file . " " . $working_dir);
- }
- #Join the two arrays
- push(@vps_xml_files, @ele_vps_xml_files);
- # Process published videos
- foreach my $vps_xml_file (@vps_xml_files) {
- log_data("Processing VPS XML file: $working_dir/$vps_xml_file");
-
- # Get job info from XML file
- (my $vps_xml_title,
- my $vps_xml_description,
- my $vps_xml_author,
- my $vps_xml_copyright,
- my $vps_xml_slug,
- my $vps_xml_year,
- my $vps_xml_month,
- my $vps_xml_server,
- my $vps_xml_type,
- my $vps_xml_environment,
- my $vps_xml_id,
- my $vps_xml_profile,
- my $vps_xml_priority,
- my $vps_xml_aspect_ratio_adjust,
- my $vps_xml_source_file,
- my $vps_xml_source_file_width,
- my $vps_xml_source_file_height) = &get_vps_job_info("$working_dir/$vps_xml_file");
-
- log_data("VPS Title: " . $vps_xml_title);
- log_data("VPS Description: " . $vps_xml_description);
- log_data("VPS Author: " . $vps_xml_author);
- log_data("VPS Copyright: " . $vps_xml_copyright);
- log_data("VPS Slug: " . $vps_xml_slug);
- log_data("VPS Year: " . $vps_xml_year);
- log_data("VPS Month: " . $vps_xml_month);
- log_data("VPS Server: " . $vps_xml_server);
- log_data("VPS Type: " . $vps_xml_type);
- log_data("VPS Environment: " . $vps_xml_environment);
- log_data("VPS ID: " . $vps_xml_id);
- log_data("VPS Profile: " . $vps_xml_profile);
- log_data("VPS Priority: " . $vps_xml_priority);
- log_data("VPS Aspect Ratio Adjust: " . $vps_xml_aspect_ratio_adjust);
- log_data("VPS Source File: " . $vps_xml_source_file);
- log_data("VPS Source File Width: " . $vps_xml_source_file_width);
- log_data("VPS Source File Height: " . $vps_xml_source_file_height);
-
- # Determine type of job and set job values
- my $job_host = '';
- my $job_new_host = '';
- my $job_ttnsports_host = '';
- my $job_ttnsports_new_host = '';
- my $job_ttnentertainment_host = '';
- my $job_ttnentertainment_new_host = '';
- my $job_property_site = '';
- my $job_provider = '';
- my $job_group = 'Advertisements';
- my $job_external_ref = '';
- my $video_finished_dir = '';
- if ($vps_xml_profile =~ /tbs_ads/) { # TBS Ads job
- log_data("TBS Ads job: " . $vps_xml_profile);
-
- # Set the property site
- $job_property_site = 'tbs';
-
- # Set the provider
- $job_provider = 'TBS';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($vps_xml_profile =~ /tnt_ads/) { # TNT Ads job
- log_data("TNT Ads job: " . $vps_xml_profile);
-
- # Set the property site
- $job_property_site = 'tnt';
-
- # Set the provider
- $job_provider = 'TNT';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($vps_xml_profile =~ /ttn_ads/) { # TTN Ads job
- log_data("TTN Ads job: " . $vps_xml_profile);
-
- # Set the property site
- $job_property_site = 'ttn';
-
- # Set the provider - for TTN, set the initial provider to CNN, process the rest below
- $job_provider = 'CNN';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactusnews');
- $job_new_host = &get_adactus_system('adactusnewsprod');
- $job_ttnsports_host = &get_adactus_system('adactussports');
- $job_ttnsports_new_host = &get_adactus_system('adactussportsprod');
- $job_ttnentertainment_host = &get_adactus_system('adactussports');
- $job_ttnentertainment_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishednews');
-
- # Set the external reference
- $job_external_ref = "ads/ttn/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
- #$job_external_ref = $vps_xml_slug;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
-
- } elsif ($vps_xml_profile =~ /adultswim_ads/) { # AdultSwim Ads job
- log_data("AdultSwim Ads job: " . $vps_xml_profile);
-
- # Set the property site
- $job_property_site = 'adultswim';
-
- # Set the provider
- $job_provider = 'AdultSwim';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
- } elsif ($vps_xml_profile =~ /cartoon_ads/) { # Cartoon Ads job
- log_data("Cartoon Ads job: " . $vps_xml_profile);
-
- # Set the property site
- $job_property_site = 'toon';
-
- # Set the provider
- $job_provider = 'Cartoon';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
- } elsif ($vps_xml_profile =~ /tcm_ads/) { # TCM Ads job
- log_data("TCM Ads job: " . $vps_xml_profile);
-
- # Set the property site
- $job_property_site = 'tcm';
-
- # Set the provider
- $job_provider = 'TCM';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactussports');
- $job_new_host = &get_adactus_system('adactustegprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishedsports');
-
- # Set the external reference
- $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
- } elsif ($vps_xml_profile =~ /^cnn_ads_/) { # CNN/Money Ads job
- log_data("CNN/Money Ads job: " . $vps_xml_profile);
-
- # Set the property site
- $job_property_site = 'cnn';
-
- # Set the provider
- $job_provider = 'CNN';
-
- # Set the Adactus hosts
- $job_host = &get_adactus_system('adactusnews');
- $job_new_host = &get_adactus_system('adactusnewsprod');
-
- # Set the video finished directory
- $video_finished_dir = &get_directory_path('videofinishednews');
-
- # Get advertiser
- my $cms_advertiser = &get_vps_xml_data('meta-cms_advertiser', "$working_dir/$vps_xml_file");
-
- # Set the external reference
- $job_external_ref = "ads/advertiser/$cms_advertiser/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
- #$job_external_ref = $cms_basename;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_external_ref = $job_external_ref . '.interstitial';
- }
- } else { # Unknown job
- log_error("Unknown job: " . $vps_xml_profile);
-
- # Move CGI file to done directory
- log_system("mv $working_dir/$vps_xml_file $done_dir/$vps_xml_file");
-
- # Process next video
- next;
- }
-
- # Log job values
- log_data("Job Adactus Host: " . $job_host);
- log_data("Job Adactus New Host: " . $job_new_host);
- log_data("Job Property Site: " . $job_property_site);
- log_data("Job Provider: " . $job_provider);
- log_data("Job Group: " . $job_group);
- log_data("Job External Reference: " . $job_external_ref);
-
- if ($vps_xml_environment eq 'PROD') { # For production only
- # Set the source video URL
- my $job_source_video = "http://io.cnn.net/" . $job_property_site . "/big/ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug . ".adactus.mp4";
- if ($job_property_site =~ /ttn/) {
- $job_source_video = "http://io.cnn.net/" . $job_property_site . "/big/video/ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug . ".adactus.mp4";
- }
- #Note that CNN's xml description has an additional <meta-cms_advertiser> tag
- if ($job_property_site eq 'cnn'){
- my $xml_cms_advertiser = &get_vps_xml_data('meta-cms_advertiser', "$working_dir/$vps_xml_file");
- $job_source_video = "http://io.cnn.net/" . $job_property_site . "/big/ads/advertiser/" . $xml_cms_advertiser . "/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug . ".adactus.mp4";
- }
-
- $job_source_video =~ s/ /%20/g;
- log_data("Job Source Video URL: " . $job_source_video);
-
- # Set the header
- my $job_header = $vps_xml_slug;
- if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
- $job_header = $job_header . '.interstitial';
- }
- log_data("Job Header: " . $job_header);
-
- # Check if the source video URL is valid
- if (head($job_source_video)) { # URL is valid
- log_data("Source video URL is valid: " . $job_source_video);
-
- # Submit jobs to Adactus systems
- &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_host);
- &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_new_host);
-
- # Submit the Money job to Adactus system
- if ($job_provider eq 'CNN') {
- &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_host);
- &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_new_host);
- }
-
- # For TTN jobs we must also submit to the sports and entertainment providers
- if ($job_property_site eq 'ttn') {
- log_data("Submit video to *all* TTN networks");
-
- # NBA
- &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_host);
- &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_new_host);
-
- # NCAA
- &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_host);
- &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_new_host);
-
- # PGA
- &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_host);
- &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_new_host);
-
- # TBS
- &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
- &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
-
- # TNT
- &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
- &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
-
- # AdultSwim
- &adactus_rest_submit('AdultSwim', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
- &adactus_rest_submit('AdultSwim', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
-
- # Cartoon
- &adactus_rest_submit('Cartoon', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
- &adactus_rest_submit('Cartoon', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
-
- # TCM
- &adactus_rest_submit('TCM', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
- &adactus_rest_submit('TCM', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
- }
- } else { # URL is invalid
- log_error("Source video URL is invalid: " . $job_source_video);
-
- # Move CGI file back to IN directory
- if (-e "$working_dir/$vps_xml_file") {
- log_system("mv $working_dir/$vps_xml_file $in_dir/$vps_xml_file");
- }
- }
- }
-
- # Move CGI file to DONE directory
- if (-e "$working_dir/$vps_xml_file") {
- log_system("mv $working_dir/$vps_xml_file $done_dir/$vps_xml_file");
- }
-
- # Cleanup IN directory
- if (-e "$in_dir/$vps_xml_file") { # Check if file exists
- &cleanup_in_dir("$in_dir/$vps_xml_file", $done_dir);
- }
- }
- # Finish Logging
- log_complete();
- ###############
- # Subroutines #
- ###############
- sub get_job_info { # Get job info from XML file
- log_data("Subroutine: get_job_info");
-
- my $xml_file = shift;
- my $job_id = &get_xml_data('jobid', $xml_file);
- my $title = &get_xml_data('title', $xml_file);
- my $description = &get_xml_data('description', $xml_file);
- my $author = &get_xml_data('author', $xml_file);
- my $copyright = &get_xml_data('copyright', $xml_file);
- my $job_profile = &get_xml_data('job-profile', $xml_file);
- my $source_clip = &get_xml_data('source-clip', $xml_file);
- my $basename = &get_xml_data('basename', $xml_file);
- my $advertiser = &get_xml_data('udm-advertiser', $xml_file);
- my $udm_submit_machine = &get_xml_data('submit-machine', $xml_file);
- my $udm_tool_environment = '';
-
- # Set the tool environment variable
- if ((lc($udm_submit_machine) =~ /ecsnews04/)||(lc($udm_submit_machine) =~ /ecsnews05/)) { # News PROD ECS
- $udm_tool_environment = 'PROD';
- } elsif ((lc($udm_submit_machine) =~ /ecs-sports-01/)||(lc($udm_submit_machine) =~ /ecssports02/)||(lc($udm_submit_machine) =~ /ecssports03/)) { # Sports PROD ECS
- $udm_tool_environment = 'PROD';
- } elsif ((lc($udm_submit_machine) =~ /ecs-teg-01/)||(lc($udm_submit_machine) =~ /ecsteg02/)||(lc($udm_submit_machine) =~ /ecsteg03/)) { # TEG PROD ECS
- $udm_tool_environment = 'PROD';
- } else { # DEV ECS
- $udm_tool_environment = 'DEV';
- }
-
- return ($job_id, $title, $description, $author, $copyright, $job_profile, $source_clip, $basename, $advertiser, $udm_submit_machine, $udm_tool_environment);
- }
- sub get_vps_job_info { # Get job info from VPS XML file
- log_data("Subroutine: get_vps_job_info");
-
- my $xml_file = shift;
- my $xml_title = &get_vps_xml_data('meta-title', $xml_file);
- my $xml_description = &get_vps_xml_data('meta-description', $xml_file);
- my $xml_author = &get_vps_xml_data('meta-author', $xml_file);
- my $xml_copyright = &get_vps_xml_data('meta-copyright', $xml_file);
- my $xml_slug = &get_vps_xml_data('meta-slug', $xml_file);
- my $xml_year = &get_vps_xml_data('meta-year', $xml_file);
- my $xml_month = &get_vps_xml_data('meta-month', $xml_file);
- my $xml_server = &get_vps_xml_data('encoding-server', $xml_file);
- my $xml_type = &get_vps_xml_data('encoding-type', $xml_file);
- my $xml_environment = &get_vps_xml_data('encoding-environment', $xml_file);
- my $xml_id = &get_vps_xml_data('encoding-id', $xml_file);
- my $xml_profile = &get_vps_xml_data('encoding-profile', $xml_file);
- my $xml_priority = &get_vps_xml_data('encoding-priority', $xml_file);
- my $xml_aspect_ratio_adjust = &get_vps_xml_data('encoding-aspect_ratio_adjust', $xml_file);
- my $xml_source_file = &get_vps_xml_data('media-source_file', $xml_file);
- my $xml_source_file_width = &get_vps_xml_data('media-source_file_width', $xml_file);
- my $xml_source_file_height = &get_vps_xml_data('media-source_file_height', $xml_file);
-
- return ($xml_title, $xml_description, $xml_author, $xml_copyright, $xml_slug, $xml_year, $xml_month, $xml_server, $xml_type, $xml_environment, $xml_id, $xml_profile, $xml_priority, $xml_aspect_ratio_adjust, $xml_source_file, $xml_source_file_width, $xml_source_file_height);
- }
- sub get_source_video { # Get the source video file name
- log_data("Subroutine: get_source_video");
-
- my $xml_file = shift;
- my $source_video_filename = '';
-
- # Process task list
- log_data("Process task list");
- my $xs = XML::Simple->new();
- my $xml = $xs->XMLin($xml_file);
- my $task_hash = $xml->{'task-status'};
- foreach my $id_key (keys %$task_hash) {
- my $output_filename = $xml->{'task-status'}->{$id_key}->{'accounting'}->{'output-file-name'};
- if ($output_filename =~ /\\videos_repository\\ads\\adactus\\/) { # Get adactus source video
- log_data("Adactus source video found: " . $output_filename);
- ($source_video_filename) = ($output_filename =~ /\\videos_repository\\ads\\adactus\\(.+)/);
- log_data("Adactus source video file name: " . $source_video_filename);
- }
- }
-
- return $source_video_filename;
- }
- sub adactus_rest_submit { # Submit job to Adactus system
- log_data("Subroutine: adactus_rest_submit");
- my $xml_provider = shift;
- my $xml_group = shift;
- my $xml_external_ref = shift;
- my $xml_source_video = shift;
- my $xml_header = shift;
- my $xml_basename = shift;
- my $xml_job_profile = shift;
- my $host = shift;
- # Write XML document in the done directory
- log_data("Write XML document $done_dir/$xml_basename.$xml_job_profile.xml");
- open (XMLFILE, ">$done_dir/$xml_basename.$xml_job_profile.xml");
- print XMLFILE << "XMLDoc";
- <?xml version="1.0" encoding="UTF-8"?>
- <mod:MOD xmlns:mod="urn:adactus:mob:2006:01-MOD-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <!-- Name for the provider (Required = true) -->
- <mod:Provider>$xml_provider</mod:Provider>
- <!-- Name for the selected group (Required = true) -->
- <mod:Group>$xml_group</mod:Group>
- <!-- An external reference for the item (Required = false) -->
- <mod:ExternalRef>$xml_external_ref</mod:ExternalRef>
- <!-- Restriction of the content, true or false. Default set to false (Required = false) -->
- <mod:Restricted>false</mod:Restricted>
- <mod:DeleteSourceFiles>false</mod:DeleteSourceFiles>
- <mod:DeleteOriginalMediaResources>false</mod:DeleteOriginalMediaResources>
- <!-- Expire date for the item. Number of milliseconds since January 1st 1970 UTC (Required = false) -->
- <mod:ExpireDate>-1</mod:ExpireDate>
- <!-- Alert for the item. Only applicaple for MIDlets (Required = false) -->
- <mod:Alert priority="0" />
- <mod:ProviderInput>
- <mod:Content>
- <!-- Video minimum=0 maximum=1 -->
- <mod:Video mimeType="video/mp4" ref="$xml_source_video" adaptation="Video Mobile Download 16-9 AAC" />
- <!-- TextHeader minimum=0 maximum=1 -->
- <mod:TextHeader mimeType="text/plain">$xml_header</mod:TextHeader>
- </mod:Content>
- </mod:ProviderInput>
- </mod:MOD>
- XMLDoc
- close XMLFILE;
-
- # Read XML job planner
- log_data("Read XML job planner");
- open (JOBXML, "$done_dir/$xml_basename.$xml_job_profile.xml");
- my @job_submit_xml_contents = <JOBXML>;
- close JOBXML;
-
- # Build XML job planner
- log_data("Build XML job planner");
- my $job_submit_xml = '';
- foreach my $job_submit_xml_line (@job_submit_xml_contents) {
- $job_submit_xml = $job_submit_xml . $job_submit_xml_line;
- }
-
- log_data($job_submit_xml);
-
- # Submit job to Adactus system
- log_data("Submit job to Adactus system");
- my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)');
- my $req = HTTP::Request->new(POST => "http://$host/diactus/DiUploader");
- $req->content_type('text/xml');
- $req->content($job_submit_xml);
- my $rslt = $ua->request($req);
- if($rslt->is_success) {
- log_data("HTTP post successful:\n" . $rslt->content);
-
- my ($submit_job_id) = ($rslt->content =~ /<id>(\d+)<\/id>/);
-
- log_data("Submit Job ID: " . $submit_job_id);
-
- if ($submit_job_id) { # Submitted successfully
- log_data("Submitted successfully!");
- } else { # Submission failed
- log_error("Submission failed!");
- }
- } else {
- log_error("HTTP post failed:\n" . $rslt->status_line);
- }
- # 5 seconds delay
- sleep(5);
- }
- sub cleanup_in_dir { # Cleanup incoming directories
- log_data("Subroutine: cleanup_in_dir");
-
- my $cgi_file_path = shift;
- my $done_dir_path = shift;
-
- # Get the file's stats
- log_data("Get the file's stats: $cgi_file_path");
- my @file_stats = stat($cgi_file_path);
-
- # Get the modification time
- my $modification_time = $file_stats[9];
- log_data("Modification time: $modification_time " . localtime($modification_time));
-
- # Get the current time
- my $current_time = time;
- log_data("Current time: $current_time " . localtime($current_time));
-
- # Get the time difference
- my $time_difference = ($current_time - $modification_time)/3600;
- log_data("Time difference (hrs): $time_difference");
-
- if($time_difference > 24) { # File is older than 24 hours
- # Move the file to the done directory
- log_data("Move the file to the done directory");
- log_system("mv $cgi_file_path $done_dir_path");
- }
- }