PageRenderTime 61ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/mixed/ads_adactus/ads_adactus.pl

https://bitbucket.org/vps/videoscripts
Perl | 932 lines | 836 code | 55 blank | 41 comment | 24 complexity | 472b8b667075aedc0413c172f652ed2e MD5 | raw file
  1. #!/usr/bin/perl -I/opt/CNNi/videoscripts/libraries/perl -I/home/dboardman/bitbucket/videoscripts/libraries/perl
  2. # Ivan Leon
  3. # Date: 01 NOV 2011
  4. # Script: ads_adactus.pl
  5. #
  6. # $Id:$
  7. # Libraries
  8. use strict;
  9. use DMT::Video_Logs;
  10. use DMT::cgi_parser;
  11. use DMT::vps_xml_parser;
  12. use DMT::directories_parser;
  13. use DMT::adactussystems_parser;
  14. use LWP::Simple;
  15. use LWP::UserAgent;
  16. use Net::FTP;
  17. use Date::Manip;
  18. # Start Logging
  19. log_setglobal_logfile('ads_adactus/ads_adactus');
  20. log_init();
  21. # Global Variables
  22. my $scripts_root_dir = &get_directory_path('scriptsroot');
  23. my $script_dir = $scripts_root_dir . "/mixed/ads_adactus";
  24. my $in_dir = $script_dir . "/in";
  25. my $done_dir = $script_dir . "/done";
  26. my $working_dir = $script_dir . "/working";
  27. my $ele_in_dir = &get_directory_path('videoproductionnews') . "/videoscripts/cnn_elemental/mixed_in";
  28. # Get current date values
  29. my $current_time = localtime;
  30. my $current_year = &UnixDate($current_time, "%Y");
  31. my $current_month = &UnixDate($current_time, "%m");
  32. my $current_day = &UnixDate($current_time, "%d");
  33. # Read IN directory - Agility notifications
  34. log_data("Reading directory (Agility): $in_dir");
  35. opendir(INDIR, $in_dir) || log_error("Couldn't open $in_dir : $!");
  36. my @cgi_files = grep (/^cgidata_/, sort(readdir(INDIR)));
  37. close(INDIR);
  38. # Move found CGI files to the working directory
  39. foreach my $agility_file (@cgi_files) {
  40. log_system("mv " . $in_dir . "/" . $agility_file . " " . $working_dir);
  41. }
  42. # Process published videos
  43. foreach my $cgi_file (@cgi_files) {
  44. log_data("Processing CGI file: $working_dir/$cgi_file");
  45. # Get job info from XML file
  46. (my $cms_job_id,
  47. my $cms_title,
  48. my $cms_description,
  49. my $cms_author,
  50. my $cms_copyright,
  51. my $cms_job_profile,
  52. my $cms_source_clip,
  53. my $cms_basename,
  54. my $cms_advertiser,
  55. my $cms_submit_machine,
  56. my $cms_tool_environment) = &get_job_info($working_dir . "/" . $cgi_file);
  57. log_data("Job ID: $cms_job_id");
  58. log_data("Job Title: $cms_title");
  59. log_data("Job Description: $cms_description");
  60. log_data("Job Author: $cms_author");
  61. log_data("Job Copyright: $cms_copyright");
  62. log_data("Job Profile: $cms_job_profile");
  63. log_data("Job Source Clip: $cms_source_clip");
  64. log_data("Job Basename: $cms_basename");
  65. log_data("Job Advertiser: $cms_advertiser");
  66. log_data("Job Submit Machine: $cms_submit_machine");
  67. log_data("Job CMS Tool Environment: $cms_tool_environment");
  68. # Get the Adactus source video file name
  69. my $adactus_source_video_name = &get_source_video($working_dir . "/" . $cgi_file);
  70. # Determine type of job and set job values
  71. my $job_host = '';
  72. my $job_new_host = '';
  73. my $job_ttnsports_host = '';
  74. my $job_ttnsports_new_host = '';
  75. my $job_ttnentertainment_host = '';
  76. my $job_ttnentertainment_new_host = '';
  77. my $job_property_site = '';
  78. my $job_provider = '';
  79. my $job_group = 'Advertisements';
  80. my $job_external_ref = '';
  81. my $video_finished_dir = '';
  82. if ($cms_job_profile =~ /nba_ads_/) { # NBA Ads job
  83. log_data("NBA Ads job: " . $cms_job_profile);
  84. # Set the property site
  85. $job_property_site = 'nba';
  86. # Set the provider
  87. $job_provider = 'NBA';
  88. # Set the Adactus hosts
  89. $job_host = &get_adactus_system('adactussports');
  90. $job_new_host = &get_adactus_system('adactussportsprod');
  91. # Set the video finished directory
  92. $video_finished_dir = &get_directory_path('videofinishedsports');
  93. # Set the external reference
  94. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
  95. #$job_external_ref = $cms_basename;
  96. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  97. $job_external_ref = $job_external_ref . '.interstitial';
  98. }
  99. } elsif ($cms_job_profile =~ /nascarads_/) { # NASCAR Ads job
  100. log_data("NASCAR Ads job: " . $cms_job_profile);
  101. # Set the property site
  102. $job_property_site = 'nascar';
  103. # Set the provider
  104. $job_provider = 'NASCAR';
  105. # Set the Adactus hosts
  106. $job_host = &get_adactus_system('adactussports');
  107. $job_new_host = &get_adactus_system('adactussportsprod');
  108. # Set the video finished directory
  109. $video_finished_dir = &get_directory_path('videofinishedsports');
  110. # Set the external reference
  111. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
  112. #$job_external_ref = $cms_basename;
  113. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  114. $job_external_ref = $job_external_ref . '.interstitial';
  115. }
  116. } elsif ($cms_job_profile =~ /ncaa_ads_/) { # NCAA Ads job
  117. log_data("NCAA Ads job: " . $cms_job_profile);
  118. # Set the property site
  119. $job_property_site = 'ncaa';
  120. # Set the provider
  121. $job_provider = 'NCAA';
  122. # Set the Adactus hosts
  123. $job_host = &get_adactus_system('adactussports');
  124. $job_new_host = &get_adactus_system('adactussportsprod');
  125. # Set the video finished directory
  126. $video_finished_dir = &get_directory_path('videofinishedsports');
  127. # Set the external reference
  128. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
  129. #$job_external_ref = $cms_basename;
  130. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  131. $job_external_ref = $job_external_ref . '.interstitial';
  132. }
  133. } elsif ($cms_job_profile =~ /pga_/) { # PGA Ads job
  134. log_data("PGA Ads job: " . $cms_job_profile);
  135. # Set the property site
  136. $job_property_site = 'pga';
  137. # Set the provider
  138. $job_provider = 'PGA';
  139. # Set the Adactus hosts
  140. $job_host = &get_adactus_system('adactussports');
  141. $job_new_host = &get_adactus_system('adactussportsprod');
  142. # Set the video finished directory
  143. $video_finished_dir = &get_directory_path('videofinishedsports');
  144. # Set the external reference
  145. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
  146. #$job_external_ref = $cms_basename;
  147. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  148. $job_external_ref = $job_external_ref . '.interstitial';
  149. }
  150. } elsif ($cms_job_profile =~ /^ads_/) { # CNN/Money Ads job
  151. log_data("CNN/Money Ads job: " . $cms_job_profile);
  152. # Set the property site
  153. $job_property_site = 'cnn';
  154. # Set the provider
  155. $job_provider = 'CNN';
  156. # Set the Adactus hosts
  157. $job_host = &get_adactus_system('adactusnews');
  158. $job_new_host = &get_adactus_system('adactusnewsprod');
  159. # Set the video finished directory
  160. $video_finished_dir = &get_directory_path('videofinishednews');
  161. # Set the external reference
  162. $job_external_ref = "ads/advertiser/$cms_advertiser/" . $current_year . "/" . $current_month . "/" . $cms_basename;
  163. #$job_external_ref = $cms_basename;
  164. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  165. $job_external_ref = $job_external_ref . '.interstitial';
  166. }
  167. } elsif ($cms_job_profile =~ /^TBS_AD_/) { # TBS
  168. log_data("TBS Ads job: " . $cms_job_profile);
  169. # Set the property site
  170. $job_property_site = 'tbs';
  171. # Set the provider
  172. $job_provider = 'TBS';
  173. # Set the Adactus hosts
  174. $job_host = &get_adactus_system('adactussports');
  175. $job_new_host = &get_adactus_system('adactustegprod');
  176. # Set the video finished directory
  177. $video_finished_dir = &get_directory_path('videofinishedsports');
  178. # Set the external reference
  179. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $cms_basename;
  180. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  181. $job_external_ref = $job_external_ref . '.interstitial';
  182. }
  183. } elsif ($cms_job_profile =~ /^TNT_ADS_/) { # TBS
  184. log_data("TNT Ads job: " . $cms_job_profile);
  185. # Set the property site
  186. $job_property_site = 'tnt';
  187. # Set the provider
  188. $job_provider = 'TNT';
  189. # Set the Adactus hosts
  190. $job_host = &get_adactus_system('adactussports');
  191. $job_new_host = &get_adactus_system('adactustegprod');
  192. # Set the video finished directory
  193. $video_finished_dir = &get_directory_path('videofinishedsports');
  194. # Set the external reference
  195. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $cms_basename;
  196. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  197. $job_external_ref = $job_external_ref . '.interstitial';
  198. }
  199. } elsif ($cms_job_profile =~ /^ttn_/) { # TTN Ads job
  200. log_data("TTN Ads job: " . $cms_job_profile);
  201. # Set the property site
  202. $job_property_site = 'ttn';
  203. # Set the provider - for TTN, set the initial provider to CNN, process the rest below
  204. $job_provider = 'CNN';
  205. # Set the Adactus hosts
  206. $job_host = &get_adactus_system('adactusnews');
  207. $job_new_host = &get_adactus_system('adactusnewsprod');
  208. $job_ttnsports_host = &get_adactus_system('adactussports');
  209. $job_ttnsports_new_host = &get_adactus_system('adactussportsprod');
  210. $job_ttnentertainment_host = &get_adactus_system('adactussports');
  211. $job_ttnentertainment_new_host = &get_adactus_system('adactustegprod');
  212. # Set the video finished directory
  213. $video_finished_dir = &get_directory_path('videofinishednews');
  214. # Set the external reference
  215. $job_external_ref = "ads/ttn/" . $current_year . "/" . $current_month . "/" . $current_day . "/" . $cms_basename;
  216. #$job_external_ref = $cms_basename;
  217. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  218. $job_external_ref = $job_external_ref . '.interstitial';
  219. }
  220. } else { # Unknown job
  221. log_error("Unknown job: " . $cms_job_profile);
  222. # Move CGI file to done directory
  223. log_system("mv $working_dir/$cgi_file $done_dir/$cgi_file");
  224. # Process next video
  225. next;
  226. }
  227. # Log job values
  228. log_data("Job Adactus Host: " . $job_host);
  229. log_data("Job Adactus New Host: " . $job_new_host);
  230. log_data("Job Property Site: " . $job_property_site);
  231. log_data("Job Provider: " . $job_provider);
  232. log_data("Job Group: " . $job_group);
  233. log_data("Job External Reference: " . $job_external_ref);
  234. # Check if the source video file exists
  235. my $adactus_source_video = $video_finished_dir . "/$job_property_site/videos_repository/ads/adactus/" . $adactus_source_video_name;
  236. if (-e $adactus_source_video) { # Source video file found
  237. log_data("Source video file found: " . $adactus_source_video);
  238. if ($cms_tool_environment eq 'PROD') { # For production only
  239. # Set the source video URL
  240. my $job_source_video = "http://io.cnn.net/$job_property_site/big/ads/adactus/" . $adactus_source_video_name;
  241. $job_source_video =~ s/ /%20/g;
  242. log_data("Job Source Video URL: " . $job_source_video);
  243. # Set the header
  244. my $job_header = $cms_basename;
  245. if ($cms_job_profile =~ /interstitial/) { # Interstitial job
  246. $job_header = $job_header . '.interstitial';
  247. }
  248. log_data("Job Header: " . $job_header);
  249. # Check if the source video URL is valid
  250. if (head($job_source_video)) { # URL is valid
  251. log_data("Source video URL is valid: " . $job_source_video);
  252. # Submit jobs to Adactus systems
  253. &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_host);
  254. &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_new_host);
  255. # Submit the Money job to Adactus system
  256. if ($job_provider eq 'CNN') {
  257. &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_host);
  258. &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_new_host);
  259. }
  260. # For TTN jobs we must also submit to the sports and entertainment providers
  261. if ($job_property_site eq 'ttn') {
  262. log_data("Submit video to *all* TTN networks");
  263. # NBA
  264. &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_host);
  265. &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_new_host);
  266. # NCAA
  267. &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_host);
  268. &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_new_host);
  269. # PGA
  270. &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_host);
  271. &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnsports_new_host);
  272. # TBS
  273. &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_host);
  274. &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_new_host);
  275. # TNT
  276. &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_host);
  277. &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $cms_basename, $cms_job_profile, $job_ttnentertainment_new_host);
  278. }
  279. } else { # URL is invalid
  280. log_error("Source video URL is invalid: " . $job_source_video);
  281. # Move CGI file back to IN directory
  282. if (-e "$working_dir/$cgi_file") {
  283. log_system("mv $working_dir/$cgi_file $in_dir/$cgi_file");
  284. }
  285. }
  286. }
  287. # Move CGI file to DONE directory
  288. if (-e "$working_dir/$cgi_file") {
  289. log_system("mv $working_dir/$cgi_file $done_dir/$cgi_file");
  290. }
  291. } else { # Source video file not found
  292. log_error("Source video file not found: " . $adactus_source_video);
  293. # Move CGI file back to IN directory
  294. if (-e "$working_dir/$cgi_file") {
  295. log_system("mv $working_dir/$cgi_file $in_dir/$cgi_file");
  296. }
  297. }
  298. # Cleanup IN directory
  299. if (-e "$in_dir/$cgi_file") { # Check if file exists
  300. &cleanup_in_dir("$in_dir/$cgi_file", $done_dir);
  301. }
  302. }
  303. # Read IN directory - VPS notifications
  304. log_data("Reading directory (VPS): " . $in_dir);
  305. opendir(INDIRVPS, $in_dir) || log_error("Couldn't open $in_dir : $!");
  306. my @vps_xml_files = grep (/.vps.xml$/, sort(readdir(INDIRVPS)));
  307. close(INDIRVPS);
  308. # Move found VPS XML files to the working directory
  309. foreach my $vps_xml_file (@vps_xml_files) {
  310. log_system("mv " . $in_dir . "/" . $vps_xml_file . " " . $working_dir);
  311. }
  312. # Read Elemental IN directory - VPS notifications
  313. log_data("Reading Elemental directory (VPS): " . $ele_in_dir);
  314. opendir(INDIRVPS, $ele_in_dir) || log_error("Couldn't open $ele_in_dir : $!");
  315. my @ele_vps_xml_files = grep (/.vps.xml$/, sort(readdir(INDIRVPS)));
  316. close(INDIRVPS);
  317. # Move found VPS XML files to the working directory
  318. foreach my $vps_xml_file (@ele_vps_xml_files) {
  319. log_system("mv " . $ele_in_dir . "/" . $vps_xml_file . " " . $working_dir);
  320. }
  321. #Join the two arrays
  322. push(@vps_xml_files, @ele_vps_xml_files);
  323. # Process published videos
  324. foreach my $vps_xml_file (@vps_xml_files) {
  325. log_data("Processing VPS XML file: $working_dir/$vps_xml_file");
  326. # Get job info from XML file
  327. (my $vps_xml_title,
  328. my $vps_xml_description,
  329. my $vps_xml_author,
  330. my $vps_xml_copyright,
  331. my $vps_xml_slug,
  332. my $vps_xml_year,
  333. my $vps_xml_month,
  334. my $vps_xml_server,
  335. my $vps_xml_type,
  336. my $vps_xml_environment,
  337. my $vps_xml_id,
  338. my $vps_xml_profile,
  339. my $vps_xml_priority,
  340. my $vps_xml_aspect_ratio_adjust,
  341. my $vps_xml_source_file,
  342. my $vps_xml_source_file_width,
  343. my $vps_xml_source_file_height) = &get_vps_job_info("$working_dir/$vps_xml_file");
  344. log_data("VPS Title: " . $vps_xml_title);
  345. log_data("VPS Description: " . $vps_xml_description);
  346. log_data("VPS Author: " . $vps_xml_author);
  347. log_data("VPS Copyright: " . $vps_xml_copyright);
  348. log_data("VPS Slug: " . $vps_xml_slug);
  349. log_data("VPS Year: " . $vps_xml_year);
  350. log_data("VPS Month: " . $vps_xml_month);
  351. log_data("VPS Server: " . $vps_xml_server);
  352. log_data("VPS Type: " . $vps_xml_type);
  353. log_data("VPS Environment: " . $vps_xml_environment);
  354. log_data("VPS ID: " . $vps_xml_id);
  355. log_data("VPS Profile: " . $vps_xml_profile);
  356. log_data("VPS Priority: " . $vps_xml_priority);
  357. log_data("VPS Aspect Ratio Adjust: " . $vps_xml_aspect_ratio_adjust);
  358. log_data("VPS Source File: " . $vps_xml_source_file);
  359. log_data("VPS Source File Width: " . $vps_xml_source_file_width);
  360. log_data("VPS Source File Height: " . $vps_xml_source_file_height);
  361. # Determine type of job and set job values
  362. my $job_host = '';
  363. my $job_new_host = '';
  364. my $job_ttnsports_host = '';
  365. my $job_ttnsports_new_host = '';
  366. my $job_ttnentertainment_host = '';
  367. my $job_ttnentertainment_new_host = '';
  368. my $job_property_site = '';
  369. my $job_provider = '';
  370. my $job_group = 'Advertisements';
  371. my $job_external_ref = '';
  372. my $video_finished_dir = '';
  373. if ($vps_xml_profile =~ /tbs_ads/) { # TBS Ads job
  374. log_data("TBS Ads job: " . $vps_xml_profile);
  375. # Set the property site
  376. $job_property_site = 'tbs';
  377. # Set the provider
  378. $job_provider = 'TBS';
  379. # Set the Adactus hosts
  380. $job_host = &get_adactus_system('adactussports');
  381. $job_new_host = &get_adactus_system('adactustegprod');
  382. # Set the video finished directory
  383. $video_finished_dir = &get_directory_path('videofinishedsports');
  384. # Set the external reference
  385. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
  386. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  387. $job_external_ref = $job_external_ref . '.interstitial';
  388. }
  389. } elsif ($vps_xml_profile =~ /tnt_ads/) { # TNT Ads job
  390. log_data("TNT Ads job: " . $vps_xml_profile);
  391. # Set the property site
  392. $job_property_site = 'tnt';
  393. # Set the provider
  394. $job_provider = 'TNT';
  395. # Set the Adactus hosts
  396. $job_host = &get_adactus_system('adactussports');
  397. $job_new_host = &get_adactus_system('adactustegprod');
  398. # Set the video finished directory
  399. $video_finished_dir = &get_directory_path('videofinishedsports');
  400. # Set the external reference
  401. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
  402. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  403. $job_external_ref = $job_external_ref . '.interstitial';
  404. }
  405. } elsif ($vps_xml_profile =~ /ttn_ads/) { # TTN Ads job
  406. log_data("TTN Ads job: " . $vps_xml_profile);
  407. # Set the property site
  408. $job_property_site = 'ttn';
  409. # Set the provider - for TTN, set the initial provider to CNN, process the rest below
  410. $job_provider = 'CNN';
  411. # Set the Adactus hosts
  412. $job_host = &get_adactus_system('adactusnews');
  413. $job_new_host = &get_adactus_system('adactusnewsprod');
  414. $job_ttnsports_host = &get_adactus_system('adactussports');
  415. $job_ttnsports_new_host = &get_adactus_system('adactussportsprod');
  416. $job_ttnentertainment_host = &get_adactus_system('adactussports');
  417. $job_ttnentertainment_new_host = &get_adactus_system('adactustegprod');
  418. # Set the video finished directory
  419. $video_finished_dir = &get_directory_path('videofinishednews');
  420. # Set the external reference
  421. $job_external_ref = "ads/ttn/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
  422. #$job_external_ref = $vps_xml_slug;
  423. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  424. $job_external_ref = $job_external_ref . '.interstitial';
  425. }
  426. } elsif ($vps_xml_profile =~ /adultswim_ads/) { # AdultSwim Ads job
  427. log_data("AdultSwim Ads job: " . $vps_xml_profile);
  428. # Set the property site
  429. $job_property_site = 'adultswim';
  430. # Set the provider
  431. $job_provider = 'AdultSwim';
  432. # Set the Adactus hosts
  433. $job_host = &get_adactus_system('adactussports');
  434. $job_new_host = &get_adactus_system('adactustegprod');
  435. # Set the video finished directory
  436. $video_finished_dir = &get_directory_path('videofinishedsports');
  437. # Set the external reference
  438. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
  439. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  440. $job_external_ref = $job_external_ref . '.interstitial';
  441. }
  442. } elsif ($vps_xml_profile =~ /cartoon_ads/) { # Cartoon Ads job
  443. log_data("Cartoon Ads job: " . $vps_xml_profile);
  444. # Set the property site
  445. $job_property_site = 'toon';
  446. # Set the provider
  447. $job_provider = 'Cartoon';
  448. # Set the Adactus hosts
  449. $job_host = &get_adactus_system('adactussports');
  450. $job_new_host = &get_adactus_system('adactustegprod');
  451. # Set the video finished directory
  452. $video_finished_dir = &get_directory_path('videofinishedsports');
  453. # Set the external reference
  454. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
  455. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  456. $job_external_ref = $job_external_ref . '.interstitial';
  457. }
  458. } elsif ($vps_xml_profile =~ /tcm_ads/) { # TCM Ads job
  459. log_data("TCM Ads job: " . $vps_xml_profile);
  460. # Set the property site
  461. $job_property_site = 'tcm';
  462. # Set the provider
  463. $job_provider = 'TCM';
  464. # Set the Adactus hosts
  465. $job_host = &get_adactus_system('adactussports');
  466. $job_new_host = &get_adactus_system('adactustegprod');
  467. # Set the video finished directory
  468. $video_finished_dir = &get_directory_path('videofinishedsports');
  469. # Set the external reference
  470. $job_external_ref = "ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
  471. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  472. $job_external_ref = $job_external_ref . '.interstitial';
  473. }
  474. } elsif ($vps_xml_profile =~ /^cnn_ads_/) { # CNN/Money Ads job
  475. log_data("CNN/Money Ads job: " . $vps_xml_profile);
  476. # Set the property site
  477. $job_property_site = 'cnn';
  478. # Set the provider
  479. $job_provider = 'CNN';
  480. # Set the Adactus hosts
  481. $job_host = &get_adactus_system('adactusnews');
  482. $job_new_host = &get_adactus_system('adactusnewsprod');
  483. # Set the video finished directory
  484. $video_finished_dir = &get_directory_path('videofinishednews');
  485. # Get advertiser
  486. my $cms_advertiser = &get_vps_xml_data('meta-cms_advertiser', "$working_dir/$vps_xml_file");
  487. # Set the external reference
  488. $job_external_ref = "ads/advertiser/$cms_advertiser/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug;
  489. #$job_external_ref = $cms_basename;
  490. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  491. $job_external_ref = $job_external_ref . '.interstitial';
  492. }
  493. } else { # Unknown job
  494. log_error("Unknown job: " . $vps_xml_profile);
  495. # Move CGI file to done directory
  496. log_system("mv $working_dir/$vps_xml_file $done_dir/$vps_xml_file");
  497. # Process next video
  498. next;
  499. }
  500. # Log job values
  501. log_data("Job Adactus Host: " . $job_host);
  502. log_data("Job Adactus New Host: " . $job_new_host);
  503. log_data("Job Property Site: " . $job_property_site);
  504. log_data("Job Provider: " . $job_provider);
  505. log_data("Job Group: " . $job_group);
  506. log_data("Job External Reference: " . $job_external_ref);
  507. if ($vps_xml_environment eq 'PROD') { # For production only
  508. # Set the source video URL
  509. my $job_source_video = "http://io.cnn.net/" . $job_property_site . "/big/ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug . ".adactus.mp4";
  510. if ($job_property_site =~ /ttn/) {
  511. $job_source_video = "http://io.cnn.net/" . $job_property_site . "/big/video/ads/" . $current_year . "/" . $current_month . "/" . $vps_xml_slug . ".adactus.mp4";
  512. }
  513. #Note that CNN's xml description has an additional <meta-cms_advertiser> tag
  514. if ($job_property_site eq 'cnn'){
  515. my $xml_cms_advertiser = &get_vps_xml_data('meta-cms_advertiser', "$working_dir/$vps_xml_file");
  516. $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";
  517. }
  518. $job_source_video =~ s/ /%20/g;
  519. log_data("Job Source Video URL: " . $job_source_video);
  520. # Set the header
  521. my $job_header = $vps_xml_slug;
  522. if ($vps_xml_profile =~ /interstitial/) { # Interstitial job
  523. $job_header = $job_header . '.interstitial';
  524. }
  525. log_data("Job Header: " . $job_header);
  526. # Check if the source video URL is valid
  527. if (head($job_source_video)) { # URL is valid
  528. log_data("Source video URL is valid: " . $job_source_video);
  529. # Submit jobs to Adactus systems
  530. &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_host);
  531. &adactus_rest_submit($job_provider, $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_new_host);
  532. # Submit the Money job to Adactus system
  533. if ($job_provider eq 'CNN') {
  534. &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_host);
  535. &adactus_rest_submit('CNNMoney', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_new_host);
  536. }
  537. # For TTN jobs we must also submit to the sports and entertainment providers
  538. if ($job_property_site eq 'ttn') {
  539. log_data("Submit video to *all* TTN networks");
  540. # NBA
  541. &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_host);
  542. &adactus_rest_submit('NBA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_new_host);
  543. # NCAA
  544. &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_host);
  545. &adactus_rest_submit('NCAA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_new_host);
  546. # PGA
  547. &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_host);
  548. &adactus_rest_submit('PGA', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnsports_new_host);
  549. # TBS
  550. &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
  551. &adactus_rest_submit('TBS', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
  552. # TNT
  553. &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
  554. &adactus_rest_submit('TNT', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
  555. # AdultSwim
  556. &adactus_rest_submit('AdultSwim', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
  557. &adactus_rest_submit('AdultSwim', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
  558. # Cartoon
  559. &adactus_rest_submit('Cartoon', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
  560. &adactus_rest_submit('Cartoon', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
  561. # TCM
  562. &adactus_rest_submit('TCM', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_host);
  563. &adactus_rest_submit('TCM', $job_group, $job_external_ref, $job_source_video, $job_header, $vps_xml_slug, $vps_xml_profile, $job_ttnentertainment_new_host);
  564. }
  565. } else { # URL is invalid
  566. log_error("Source video URL is invalid: " . $job_source_video);
  567. # Move CGI file back to IN directory
  568. if (-e "$working_dir/$vps_xml_file") {
  569. log_system("mv $working_dir/$vps_xml_file $in_dir/$vps_xml_file");
  570. }
  571. }
  572. }
  573. # Move CGI file to DONE directory
  574. if (-e "$working_dir/$vps_xml_file") {
  575. log_system("mv $working_dir/$vps_xml_file $done_dir/$vps_xml_file");
  576. }
  577. # Cleanup IN directory
  578. if (-e "$in_dir/$vps_xml_file") { # Check if file exists
  579. &cleanup_in_dir("$in_dir/$vps_xml_file", $done_dir);
  580. }
  581. }
  582. # Finish Logging
  583. log_complete();
  584. ###############
  585. # Subroutines #
  586. ###############
  587. sub get_job_info { # Get job info from XML file
  588. log_data("Subroutine: get_job_info");
  589. my $xml_file = shift;
  590. my $job_id = &get_xml_data('jobid', $xml_file);
  591. my $title = &get_xml_data('title', $xml_file);
  592. my $description = &get_xml_data('description', $xml_file);
  593. my $author = &get_xml_data('author', $xml_file);
  594. my $copyright = &get_xml_data('copyright', $xml_file);
  595. my $job_profile = &get_xml_data('job-profile', $xml_file);
  596. my $source_clip = &get_xml_data('source-clip', $xml_file);
  597. my $basename = &get_xml_data('basename', $xml_file);
  598. my $advertiser = &get_xml_data('udm-advertiser', $xml_file);
  599. my $udm_submit_machine = &get_xml_data('submit-machine', $xml_file);
  600. my $udm_tool_environment = '';
  601. # Set the tool environment variable
  602. if ((lc($udm_submit_machine) =~ /ecsnews04/)||(lc($udm_submit_machine) =~ /ecsnews05/)) { # News PROD ECS
  603. $udm_tool_environment = 'PROD';
  604. } elsif ((lc($udm_submit_machine) =~ /ecs-sports-01/)||(lc($udm_submit_machine) =~ /ecssports02/)||(lc($udm_submit_machine) =~ /ecssports03/)) { # Sports PROD ECS
  605. $udm_tool_environment = 'PROD';
  606. } elsif ((lc($udm_submit_machine) =~ /ecs-teg-01/)||(lc($udm_submit_machine) =~ /ecsteg02/)||(lc($udm_submit_machine) =~ /ecsteg03/)) { # TEG PROD ECS
  607. $udm_tool_environment = 'PROD';
  608. } else { # DEV ECS
  609. $udm_tool_environment = 'DEV';
  610. }
  611. return ($job_id, $title, $description, $author, $copyright, $job_profile, $source_clip, $basename, $advertiser, $udm_submit_machine, $udm_tool_environment);
  612. }
  613. sub get_vps_job_info { # Get job info from VPS XML file
  614. log_data("Subroutine: get_vps_job_info");
  615. my $xml_file = shift;
  616. my $xml_title = &get_vps_xml_data('meta-title', $xml_file);
  617. my $xml_description = &get_vps_xml_data('meta-description', $xml_file);
  618. my $xml_author = &get_vps_xml_data('meta-author', $xml_file);
  619. my $xml_copyright = &get_vps_xml_data('meta-copyright', $xml_file);
  620. my $xml_slug = &get_vps_xml_data('meta-slug', $xml_file);
  621. my $xml_year = &get_vps_xml_data('meta-year', $xml_file);
  622. my $xml_month = &get_vps_xml_data('meta-month', $xml_file);
  623. my $xml_server = &get_vps_xml_data('encoding-server', $xml_file);
  624. my $xml_type = &get_vps_xml_data('encoding-type', $xml_file);
  625. my $xml_environment = &get_vps_xml_data('encoding-environment', $xml_file);
  626. my $xml_id = &get_vps_xml_data('encoding-id', $xml_file);
  627. my $xml_profile = &get_vps_xml_data('encoding-profile', $xml_file);
  628. my $xml_priority = &get_vps_xml_data('encoding-priority', $xml_file);
  629. my $xml_aspect_ratio_adjust = &get_vps_xml_data('encoding-aspect_ratio_adjust', $xml_file);
  630. my $xml_source_file = &get_vps_xml_data('media-source_file', $xml_file);
  631. my $xml_source_file_width = &get_vps_xml_data('media-source_file_width', $xml_file);
  632. my $xml_source_file_height = &get_vps_xml_data('media-source_file_height', $xml_file);
  633. 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);
  634. }
  635. sub get_source_video { # Get the source video file name
  636. log_data("Subroutine: get_source_video");
  637. my $xml_file = shift;
  638. my $source_video_filename = '';
  639. # Process task list
  640. log_data("Process task list");
  641. my $xs = XML::Simple->new();
  642. my $xml = $xs->XMLin($xml_file);
  643. my $task_hash = $xml->{'task-status'};
  644. foreach my $id_key (keys %$task_hash) {
  645. my $output_filename = $xml->{'task-status'}->{$id_key}->{'accounting'}->{'output-file-name'};
  646. if ($output_filename =~ /\\videos_repository\\ads\\adactus\\/) { # Get adactus source video
  647. log_data("Adactus source video found: " . $output_filename);
  648. ($source_video_filename) = ($output_filename =~ /\\videos_repository\\ads\\adactus\\(.+)/);
  649. log_data("Adactus source video file name: " . $source_video_filename);
  650. }
  651. }
  652. return $source_video_filename;
  653. }
  654. sub adactus_rest_submit { # Submit job to Adactus system
  655. log_data("Subroutine: adactus_rest_submit");
  656. my $xml_provider = shift;
  657. my $xml_group = shift;
  658. my $xml_external_ref = shift;
  659. my $xml_source_video = shift;
  660. my $xml_header = shift;
  661. my $xml_basename = shift;
  662. my $xml_job_profile = shift;
  663. my $host = shift;
  664. # Write XML document in the done directory
  665. log_data("Write XML document $done_dir/$xml_basename.$xml_job_profile.xml");
  666. open (XMLFILE, ">$done_dir/$xml_basename.$xml_job_profile.xml");
  667. print XMLFILE << "XMLDoc";
  668. <?xml version="1.0" encoding="UTF-8"?>
  669. <mod:MOD xmlns:mod="urn:adactus:mob:2006:01-MOD-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  670. <!-- Name for the provider (Required = true) -->
  671. <mod:Provider>$xml_provider</mod:Provider>
  672. <!-- Name for the selected group (Required = true) -->
  673. <mod:Group>$xml_group</mod:Group>
  674. <!-- An external reference for the item (Required = false) -->
  675. <mod:ExternalRef>$xml_external_ref</mod:ExternalRef>
  676. <!-- Restriction of the content, true or false. Default set to false (Required = false) -->
  677. <mod:Restricted>false</mod:Restricted>
  678. <mod:DeleteSourceFiles>false</mod:DeleteSourceFiles>
  679. <mod:DeleteOriginalMediaResources>false</mod:DeleteOriginalMediaResources>
  680. <!-- Expire date for the item. Number of milliseconds since January 1st 1970 UTC (Required = false) -->
  681. <mod:ExpireDate>-1</mod:ExpireDate>
  682. <!-- Alert for the item. Only applicaple for MIDlets (Required = false) -->
  683. <mod:Alert priority="0" />
  684. <mod:ProviderInput>
  685. <mod:Content>
  686. <!-- Video minimum=0 maximum=1 -->
  687. <mod:Video mimeType="video/mp4" ref="$xml_source_video" adaptation="Video Mobile Download 16-9 AAC" />
  688. <!-- TextHeader minimum=0 maximum=1 -->
  689. <mod:TextHeader mimeType="text/plain">$xml_header</mod:TextHeader>
  690. </mod:Content>
  691. </mod:ProviderInput>
  692. </mod:MOD>
  693. XMLDoc
  694. close XMLFILE;
  695. # Read XML job planner
  696. log_data("Read XML job planner");
  697. open (JOBXML, "$done_dir/$xml_basename.$xml_job_profile.xml");
  698. my @job_submit_xml_contents = <JOBXML>;
  699. close JOBXML;
  700. # Build XML job planner
  701. log_data("Build XML job planner");
  702. my $job_submit_xml = '';
  703. foreach my $job_submit_xml_line (@job_submit_xml_contents) {
  704. $job_submit_xml = $job_submit_xml . $job_submit_xml_line;
  705. }
  706. log_data($job_submit_xml);
  707. # Submit job to Adactus system
  708. log_data("Submit job to Adactus system");
  709. my $ua = LWP::UserAgent->new(agent => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)');
  710. my $req = HTTP::Request->new(POST => "http://$host/diactus/DiUploader");
  711. $req->content_type('text/xml');
  712. $req->content($job_submit_xml);
  713. my $rslt = $ua->request($req);
  714. if($rslt->is_success) {
  715. log_data("HTTP post successful:\n" . $rslt->content);
  716. my ($submit_job_id) = ($rslt->content =~ /<id>(\d+)<\/id>/);
  717. log_data("Submit Job ID: " . $submit_job_id);
  718. if ($submit_job_id) { # Submitted successfully
  719. log_data("Submitted successfully!");
  720. } else { # Submission failed
  721. log_error("Submission failed!");
  722. }
  723. } else {
  724. log_error("HTTP post failed:\n" . $rslt->status_line);
  725. }
  726. # 5 seconds delay
  727. sleep(5);
  728. }
  729. sub cleanup_in_dir { # Cleanup incoming directories
  730. log_data("Subroutine: cleanup_in_dir");
  731. my $cgi_file_path = shift;
  732. my $done_dir_path = shift;
  733. # Get the file's stats
  734. log_data("Get the file's stats: $cgi_file_path");
  735. my @file_stats = stat($cgi_file_path);
  736. # Get the modification time
  737. my $modification_time = $file_stats[9];
  738. log_data("Modification time: $modification_time " . localtime($modification_time));
  739. # Get the current time
  740. my $current_time = time;
  741. log_data("Current time: $current_time " . localtime($current_time));
  742. # Get the time difference
  743. my $time_difference = ($current_time - $modification_time)/3600;
  744. log_data("Time difference (hrs): $time_difference");
  745. if($time_difference > 24) { # File is older than 24 hours
  746. # Move the file to the done directory
  747. log_data("Move the file to the done directory");
  748. log_system("mv $cgi_file_path $done_dir_path");
  749. }
  750. }