Пример #1
0
    def process_result(self, video_name, video_info, chosen_sub, link,
                       session):

        # download archive
        choice_prefix = chosen_sub[:chosen_sub.find("]") + 1]
        downloader = DownloaderManager.get_downloader_by_choice_prefix(
            choice_prefix)
        datatype, archive_data, error = downloader.download_file(
            chosen_sub, link, session=session)
        if error:
            return error, []

        # process archive
        error, extract_sub_names = process_archive(
            video_name,
            video_info,
            archive_data,
            datatype,
            self.both,
            self.single,
            self.sub_identifier,
        )
        if error:
            return error, []

        # save original archive
        if self.more:
            archive_path = path.join(video_info["store_path"],
                                     chosen_sub + datatype)
            with open(archive_path, "wb") as f:
                f.write(archive_data)
            print("save original file.")

        return "", extract_sub_names
Пример #2
0
 def test_choose_subtitle(self, mock_input):
     create_test_directory(
         TestProcessArchive.test_dir_structure,
         parent_dir=TestProcessArchive.test_dir,
     )
     with open(path.join(assets_path, "archive.zip"), "rb") as f:
         data = f.read()
     err, subnames = process_archive(
         "sub1.mkv", TestProcessArchive.test_video_info, data, ".zip", choose=True,
     )
     self.assertEqual((err, subnames), ("", [["dir1/sub1.ass", ".ass"]]))
Пример #3
0
 def test_save_both_subtitles_fail(self):
     create_test_directory(
         TestProcessArchive.test_dir_structure,
         parent_dir=TestProcessArchive.test_dir,
     )
     with open(path.join(assets_path, "archive.zip"), "rb") as f:
         data = f.read()
     err, subnames = process_archive(
         "sub1.mkv", TestProcessArchive.test_video_info, data, ".zip", both=True,
     )
     self.assertTrue(
         "sub1.ass" in os.listdir(TestProcessArchive.test_dir)
         and "sub1.srt" not in os.listdir(TestProcessArchive.test_dir)
     )
Пример #4
0
 def test_delete_existed_subtitles(self):
     dir_structure = copy.copy(TestProcessArchive.test_dir_structure)
     dir_structure["sub1.ass"] = None
     dir_structure["sub1.srt"] = None
     create_test_directory(
         dir_structure, parent_dir=TestProcessArchive.test_dir,
     )
     with open(path.join(assets_path, "archive.zip"), "rb") as f:
         data = f.read()
     err, subnames = process_archive(
         "sub1.mkv", TestProcessArchive.test_video_info, data, ".zip", both=True,
     )
     self.assertTrue(
         "sub1.ass" in os.listdir(TestProcessArchive.test_dir)
         and "sub1.srt" not in os.listdir(TestProcessArchive.test_dir)
     )
Пример #5
0
 def test_fail_guess(self):
     with open(path.join(assets_path, "archive.zip"), "rb") as f:
         data = f.read()
     err, subnames = process_archive("test.mkv", {}, data, ".zip")
     self.assertEqual((err, subnames), ("no guess result in auto mode", []))
Пример #6
0
 def test_empty_archive(self):
     with open(path.join(assets_path, "empty.zip"), "rb") as f:
         data = f.read()
     err, subnames = process_archive("", {}, data, ".zip")
     self.assertEqual((err, subnames), ("no subtitle in this archive", []))
Пример #7
0
 def test_unsupported_archive(self):
     err, subnames = process_archive("", {}, b"", ".tar")
     self.assertEqual((err, subnames), ("unsupported file type .tar", []))