/* Copyright (C) 2020 Carl Hetherington This file is part of libdcp. libdcp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. libdcp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with libdcp. If not, see . In addition, as a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library under certain conditions as described in each individual source file, and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than OpenSSL. If you modify file(s) with this exception, you may extend this exception to your version of the file(s), but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. If you delete this exception statement from all source files in the program, then also delete it here. */ #include "common.h" #include "compose.hpp" #include "filesystem.h" #include "html_formatter.h" #ifdef LIBDCP_HAVE_HARU #include "pdf_formatter.h" #endif #include "raw_convert.h" #include "text_formatter.h" #include "verify.h" #include "verify_report.h" #include "version.h" #include #include #include #include #include #include using std::cerr; using std::cout; using std::list; using std::string; using std::vector; using boost::bind; using boost::optional; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif static void help (string n) { cerr << "Syntax: " << n << " [OPTION] \n" << " -V, --version show libdcp version\n" << " -h, --help show this help\n" << " --ignore-missing-assets don't give errors about missing assets\n" << " --ignore-bv21-smpte don't give the SMPTE Bv2.1 error about a DCP not being SMPTE\n" << " --no-asset-hash-check don't check asset hashes\n" << " --asset-hash-check-maximum-size only check hashes for assets smaller than this size (in MB)\n" << " --no-picture-details-check don't check details of picture assets (J2K bitstream etc.)\n" << " -o write report to filename " #ifdef LIBDCP_HAVE_HARU " (.txt, .htm, .html or .pdf)\n" #else " (.txt, .htm or .html)\n" #endif << " -q, --quiet don't report progress\n"; } int main (int argc, char* argv[]) { dcp::init (); bool ignore_missing_assets = false; bool ignore_bv21_smpte = false; bool quiet = false; boost::optional report_filename; dcp::VerificationOptions verification_options; int option_index = 0; while (true) { static struct option long_options[] = { { "version", no_argument, 0, 'V' }, { "help", no_argument, 0, 'h' }, { "ignore-missing-assets", no_argument, 0, 'A' }, { "ignore-bv21-smpte", no_argument, 0, 'B' }, { "no-asset-hash-check", no_argument, 0, 'C' }, { "no-picture-details-check", no_argument, 0, 'E' }, { "asset-hash-check-maximum-size", required_argument, 0, 'D' }, { "quiet", no_argument, 0, 'q' }, { 0, 0, 0, 0 } }; int c = getopt_long (argc, argv, "VhABCD:Eqo:", long_options, &option_index); if (c == -1) { break; } else if (c == '?' || c == ':') { exit(EXIT_FAILURE); } switch (c) { case 'V': cout << "dcpverify version " << dcp::version << "\n"; exit (EXIT_SUCCESS); case 'h': help(boost::filesystem::path(argv[0]).filename().string()); exit (EXIT_SUCCESS); case 'A': ignore_missing_assets = true; break; case 'B': ignore_bv21_smpte = true; break; case 'C': verification_options.check_asset_hashes = false; break; case 'D': verification_options.maximum_asset_size_for_hash_check = dcp::raw_convert(optarg) * 1000000LL; break; case 'E': verification_options.check_picture_details = false; break; case 'q': quiet = true; break; case 'o': report_filename = optarg; break; } } if (argc <= optind) { help (argv[0]); exit (EXIT_FAILURE); } if (!dcp::filesystem::exists(argv[optind])) { cerr << argv[0] << ": DCP " << argv[optind] << " not found.\n"; exit (EXIT_FAILURE); } auto stage = [quiet](string s, optional path) { if (quiet) { return; } if (path) { cout << s << ": " << path->string() << "\n"; } else { cout << s << "\n"; } }; auto progress = [quiet](float amount) { if (quiet) { return; } int const width = 60; int const index = std::rint(amount * width); cout << "["; for (int i = 0; i < width; ++i) { if (i < index) { std::cout << "="; } else if (i == index) { std::cout << ">"; } else { std::cout << " "; } } cout << "] " << std::rint(amount * 100) << "%\r"; cout.flush(); }; vector directories; directories.push_back (argv[optind]); auto result = dcp::verify(directories, {}, stage, progress, verification_options); result.notes = dcp::filter_notes(result.notes, ignore_missing_assets, ignore_bv21_smpte); if (!quiet) { cout << "\n"; } bool failed = false; bool bv21_failed = false; bool warned = false; for (auto i: result.notes) { switch (i.type()) { case dcp::VerificationNote::Type::OK: break; case dcp::VerificationNote::Type::ERROR: cout << "Error: " << note_to_string(i) << "\n"; failed = true; break; case dcp::VerificationNote::Type::BV21_ERROR: cout << "Bv2.1 error: " << note_to_string(i) << "\n"; bv21_failed = true; break; case dcp::VerificationNote::Type::WARNING: cout << "Warning: " << note_to_string(i) << "\n"; warned = true; break; } } if (!failed && !quiet) { if (bv21_failed && warned) { cout << "\nDCP verified OK (but with Bv2.1 errors and warnings).\n"; } else if (bv21_failed) { cout << "\nDCP verified OK (but with Bv2.1 errors).\n"; } else if (warned) { cout << "\nDCP verified OK (but with warnings).\n"; } else { cout << "DCP verified OK.\n"; } } if (report_filename) { if (report_filename->extension() == ".htm" || report_filename->extension() == ".html") { dcp::HTMLFormatter formatter(*report_filename); dcp::verify_report({ result }, formatter); #ifdef LIBDCP_HAVE_HARU } else if (report_filename->extension() == ".pdf") { dcp::PDFFormatter formatter(*report_filename); dcp::verify_report({ result }, formatter); #endif } else { dcp::TextFormatter formatter(*report_filename); dcp::verify_report({ result }, formatter); } } exit (failed ? EXIT_FAILURE : EXIT_SUCCESS); }