def test_extensions(self):
        # Test default value
        actual = parse_config(self._modify_key("extensions", None))[0]
        expected = {".mpg", ".ts", ".mp4"}
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("extensions", "mpg, mpg")
        actual = parse_config(config_lines)[0]
        expected = {'.mpg'}
        self.assertEqual(actual, expected)
Exemplo n.º 2
0
    def test_mediainfo_path(self):
        # Test default value
        config_lines = self._modify_key("path", None)
        actual = parse_config(config_lines)[7]
        self.assertIsNone(actual)

        # Test custom value
        config_lines = self._modify_key("path", "/usr/bin/mediainfo")
        actual = parse_config(config_lines)[7]
        expected = "/usr/bin/mediainfo"
        self.assertEqual(actual, expected)
    def test_mediainfo_path(self):
        # Test default value
        config_lines = self._modify_key("path", None)
        actual = parse_config(config_lines)[7]
        self.assertIsNone(actual)

        # Test custom value
        config_lines = self._modify_key("path", "/usr/bin/mediainfo")
        actual = parse_config(config_lines)[7]
        expected = "/usr/bin/mediainfo"
        self.assertEqual(actual, expected)
Exemplo n.º 4
0
    def test_extensions(self):
        # Test default value
        actual = parse_config(self._modify_key("extensions", None))[0]
        expected = {".mpg", ".ts", ".mp4"}
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("extensions", "mpg, mpg")
        actual = parse_config(config_lines)[0]
        expected = {".mpg"}
        self.assertEqual(actual, expected)
    def test_ecn_2009(self):
        # Test default value
        config_lines = self._modify_key("ecn_2009", None)
        actual = parse_config(config_lines)[6]
        expected = False
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("ecn_2009", "True")
        actual = parse_config(config_lines)[6]
        expected = True
        self.assertEqual(actual, expected)
Exemplo n.º 6
0
    def test_ecn_2009(self):
        # Test default value
        config_lines = self._modify_key("ecn_2009", None)
        actual = parse_config(config_lines)[6]
        expected = False
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("ecn_2009", "True")
        actual = parse_config(config_lines)[6]
        expected = True
        self.assertEqual(actual, expected)
Exemplo n.º 7
0
    def __init__(self, xml_path, vod_config=None):
        # Retrieve configuration if it's not set already
        if vod_config is None:
            self.vod_config = parse_config(default_config_path)
        else:
            self.vod_config = vod_config

        # The ECN 2009 options are not always supported - check configuration
        # to see whether they should be added.
        if self.vod_config.ecn_2009:
            self.param_skip = set()
        else:
            self.param_skip = {"Resolution", "Frame_Rate", "Codec"}

        self.xml_path = xml_path
        self.tree = etree.parse(self.xml_path)

        # The CableLabs VOD Metadata 1.1 specification stores metadata in "AMS"
        # and "App_Data" tags. The files that are part of the package are
        # stored in "Content" tags.
        self.D_ams = {}
        self.D_app = {}
        self.D_content = {}

        ADI = self.tree.getroot()
        self._read_package(ADI)
        self._read_title(ADI)
        self._read_elements(ADI)

        self.has_preview = "preview" in self.D_ams
        self.has_poster = "poster" in self.D_ams
        self.has_box_cover = "box cover" in self.D_ams
        self.is_delete = self.D_ams.get("Verb", "") == "DELETE"
        self.is_update = self.D_ams["package"]["Version_Major"] != "1"
Exemplo n.º 8
0
    def __init__(self, xml_path, vod_config=None):
        # Retrieve configuration if it's not set already
        if vod_config is None:
            self.vod_config = parse_config(default_config_path)
        else:
            self.vod_config = vod_config

        # The ECN 2009 options are not always supported - check configuration
        # to see whether they should be added.
        if self.vod_config.ecn_2009:
            self.param_skip = set()
        else:
            self.param_skip = {"Resolution", "Frame_Rate", "Codec"}

        self.xml_path = xml_path
        self.tree = etree.parse(self.xml_path)

        # The CableLabs VOD Metadata 1.1 specification stores metadata in "AMS"
        # and "App_Data" tags. The files that are part of the package are
        # stored in "Content" tags.
        self.D_ams = {}
        self.D_app = {}
        self.D_content = {}

        ADI = self.tree.getroot()
        self._read_package(ADI)
        self._read_title(ADI)
        self._read_elements(ADI)

        self.has_preview = "preview" in self.D_ams
        self.has_poster = "poster" in self.D_ams
        self.has_box_cover = "box cover" in self.D_ams
        self.is_delete = self.D_ams.get("Verb", '') == "DELETE"
        self.is_update = self.D_ams["package"]["Version_Major"] != "1"
Exemplo n.º 9
0
    def test_product(self):
        # Test default value
        config_lines = self._modify_key("product", None)
        actual = parse_config(config_lines)[1]
        expected = "MOD"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("product", "FOD")
        actual = parse_config(config_lines)[1]
        expected = "FOD"
        self.assertEqual(actual, expected)

        # Test incorrect value
        config_lines = self._modify_key("product", "x" * 21)
        with self.assertRaises(ConfigurationError):
            parse_config(config_lines)[1]
Exemplo n.º 10
0
    def test_provider(self):
        # Test default value
        config_lines = self._modify_key("provider", None)
        actual = parse_config(config_lines)[5]
        expected = "001"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("provider", "002")
        actual = parse_config(config_lines)[5]
        expected = "002"
        self.assertEqual(actual, expected)

        # Test incorrect value
        config_lines = self._modify_key("provider", "x" * 21)
        with self.assertRaises(ConfigurationError):
            parse_config(config_lines)[5]
Exemplo n.º 11
0
    def test_category(self):
        # Test default value
        config_lines = self._modify_key("title_category", None)
        actual = parse_config(config_lines)[4]
        expected = "Testing/Videos"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("title_category", "Testing/HD")
        actual = parse_config(config_lines)[4]
        expected = "Testing/HD"
        self.assertEqual(actual, expected)

        # Test incorrect value
        config_lines = self._modify_key("title_category", "x" * 21)
        with self.assertRaises(ConfigurationError):
            parse_config(config_lines)[4]
    def test_product(self):
        # Test default value
        config_lines = self._modify_key("product", None)
        actual = parse_config(config_lines)[1]
        expected = "MOD"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("product", "FOD")
        actual = parse_config(config_lines)[1]
        expected = "FOD"
        self.assertEqual(actual, expected)

        # Test incorrect value
        config_lines = self._modify_key("product", 'x' * 21)
        with self.assertRaises(ConfigurationError):
            parse_config(config_lines)[1]
    def test_category(self):
        # Test default value
        config_lines = self._modify_key("title_category", None)
        actual = parse_config(config_lines)[4]
        expected = "Testing/Videos"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("title_category", "Testing/HD")
        actual = parse_config(config_lines)[4]
        expected = "Testing/HD"
        self.assertEqual(actual, expected)

        # Test incorrect value
        config_lines = self._modify_key("title_category", 'x' * 21)
        with self.assertRaises(ConfigurationError):
            parse_config(config_lines)[4]
Exemplo n.º 14
0
    def test_prefix(self):
        # Test default value
        config_lines = self._modify_key("prefix", None)
        actual = parse_config(config_lines)[3]
        expected = "MSO"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("prefix", "ABC")
        actual = parse_config(config_lines)[3]
        expected = "ABC"
        self.assertEqual(actual, expected)

        # Test incorrect values
        incorrect_values = ["ABCD", "!!!"]  # Too many letters  # Not alphanumeric
        for value in incorrect_values:
            config_lines = self._modify_key("prefix", value)
            with self.assertRaises(ConfigurationError):
                parse_config(config_lines)[3]
    def test_prefix(self):
        # Test default value
        config_lines = self._modify_key("prefix", None)
        actual = parse_config(config_lines)[3]
        expected = "MSO"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("prefix", "ABC")
        actual = parse_config(config_lines)[3]
        expected = "ABC"
        self.assertEqual(actual, expected)

        # Test incorrect values
        incorrect_values = [
            "ABCD",  # Too many letters
            "!!!",  # Not alphanumeric
        ]
        for value in incorrect_values:
            config_lines = self._modify_key("prefix", value)
            with self.assertRaises(ConfigurationError):
                parse_config(config_lines)[3]
 def test_no_config(self):
     actual = parse_config([])
     expected = (
         {".mpg", ".ts", ".mp4"},
         "MOD",
         "example.com",
         "MSO",
         "Testing/Videos",
         "001",
         False,
         None,
     )
     self.assertEqual(actual, expected)
Exemplo n.º 17
0
 def setUp(self, mock_random):
     self.temp_dir = mkdtemp()
     mock_random.randint.return_value = 1020
     timestamp = datetime(1999, 9, 9, 1, 2)
     vod_config = parse_config(find_data_file(default_config_path))
     self.vod_config = vod_config._replace(ecn_2009=True)
     self.vod_package = generate_metadata(reference_mp4, self.vod_config, timestamp=timestamp)
     self.ams_expected = {
         "Provider": "001",
         "Product": "MOD",
         "Version_Major": "1",
         "Version_Minor": "0",
         "Creation_Date": "1999-09-09",
         "Provider_ID": "example.com",
     }
    def test_provider_id(self):
        # Test default value
        config_lines = self._modify_key("provider_id", None)
        actual = parse_config(config_lines)[2]
        expected = "example.com"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("provider_id", "EXAMPLE.org")
        actual = parse_config(config_lines)[2]
        expected = "example.org"
        self.assertEqual(actual, expected)

        # Test incorrect values
        incorrect_values = [
            "{}.com".format("x" * 17),  # Too long
            "examplecom",  # Too few dots
            "www.example.com",  # Too many dots
            "example.c",  # The bit after the dot is too short
        ]
        for value in incorrect_values:
            config_lines = self._modify_key("provider_id", value)
            with self.assertRaises(ConfigurationError):
                parse_config(config_lines)[2]
Exemplo n.º 19
0
    def test_provider_id(self):
        # Test default value
        config_lines = self._modify_key("provider_id", None)
        actual = parse_config(config_lines)[2]
        expected = "example.com"
        self.assertEqual(actual, expected)

        # Test custom value
        config_lines = self._modify_key("provider_id", "EXAMPLE.org")
        actual = parse_config(config_lines)[2]
        expected = "example.org"
        self.assertEqual(actual, expected)

        # Test incorrect values
        incorrect_values = [
            "{}.com".format("x" * 17),  # Too long
            "examplecom",  # Too few dots
            "www.example.com",  # Too many dots
            "example.c",  # The bit after the dot is too short
        ]
        for value in incorrect_values:
            config_lines = self._modify_key("provider_id", value)
            with self.assertRaises(ConfigurationError):
                parse_config(config_lines)[2]
 def setUp(self, mock_random):
     self.temp_dir = mkdtemp()
     mock_random.randint.return_value = 1020
     timestamp = datetime(1999, 9, 9, 1, 2)
     vod_config = parse_config(find_data_file(default_config_path))
     self.vod_config = vod_config._replace(ecn_2009=True)
     self.vod_package = generate_metadata(
         reference_mp4, self.vod_config, timestamp=timestamp
     )
     self.ams_expected = {
         "Provider":  "001",
         "Product": "MOD",
         "Version_Major": '1',
         "Version_Minor": '0',
         "Creation_Date": "1999-09-09",
         "Provider_ID": "example.com",
     }
Exemplo n.º 21
0
# Accept arguments from the command line
parser = ArgumentParser()
parser.add_argument(
    '--video-dir', help='Specify the path to a directory of videos to process')
parser.add_argument('--mediainfo-path',
                    help='Specify the path to the MediaInfo executable')
parser.add_argument('--template-path',
                    help='Specify the path to the metadata template')
parser.add_argument('--config-path',
                    help='Specify the path to the configuration file')
args = parser.parse_args()

if __name__ == "__main__":
    # Retrieve the user's configuration, overriding with command line arguments
    config_path = args.config_path or default_config_path
    vod_config = parse_config(abspath(config_path))

    if args.mediainfo_path is not None:
        vod_config = vod_config._replace(mediainfo_path=args.mediainfo_path)

    template_path = args.template_path or default_template_path
    template_path = abspath(template_path)

    # If a directory was specified, switch to it
    if args.video_dir is not None:
        chdir(args.video_dir)

    for file_path in listdir(getcwd()):
        # Only process movie files (skip previews)
        file_name, file_ext = splitext(file_path)
        if file_ext not in vod_config.extensions:
Exemplo n.º 22
0
)
parser.add_argument(
    '--mediainfo-path', help='Specify the path to the MediaInfo executable'
)
parser.add_argument(
    '--template-path', help='Specify the path to the metadata template'
)
parser.add_argument(
    '--config-path', help='Specify the path to the configuration file'
)
args = parser.parse_args()

if __name__ == "__main__":
    # Retrieve the user's configuration, overriding with command line arguments
    config_path = args.config_path or default_config_path
    vod_config = parse_config(abspath(config_path))

    if args.mediainfo_path is not None:
        vod_config = vod_config._replace(mediainfo_path=args.mediainfo_path)

    template_path = args.template_path or default_template_path
    template_path = abspath(template_path)

    # If a directory was specified, switch to it
    if args.video_dir is not None:
        chdir(args.video_dir)

    for file_path in listdir(getcwd()):
        # Only process movie files (skip previews)
        file_name, file_ext = splitext(file_path)
        if file_ext not in vod_config.extensions:
Exemplo n.º 23
0
 def test_no_config(self):
     actual = parse_config([])
     expected = ({".mpg", ".ts", ".mp4"}, "MOD", "example.com", "MSO", "Testing/Videos", "001", False, None)
     self.assertEqual(actual, expected)