Ejemplo n.º 1
0
 def test_absolute_video_path(self):
     create_test_directory(
         TestGetVideos.test_dir_structure1, parent_dir=TestGetVideos.test_dir,
     )
     videos = get_videos(path.join(TestGetVideos.test_dir, "sub1", "file1.mkv"))
     self.assertDictEqual(videos, TestGetVideos.desired_result2)
     videos = get_videos(path.join(TestGetVideos.test_dir, "file5.mkv"))
     self.assertDictEqual(videos, TestGetVideos.desired_result3)
     videos = get_videos(path.join(TestGetVideos.test_dir, "file6.mkv"))
     self.assertDictEqual(videos, TestGetVideos.desired_result4)
Ejemplo n.º 2
0
 def test_single_video_name(self):
     create_test_directory(
         TestGetVideos.test_dir_structure1,
         parent_dir=TestGetVideos.test_dir,
     )
     videos = get_videos("file5.mkv")
     self.assertDictEqual(videos, TestGetVideos.desired_result5)
Ejemplo n.º 3
0
 def test_invalid_store_path(self):
     create_test_directory(
         TestGetVideos.test_dir_structure1, parent_dir=TestGetVideos.test_dir,
     )
     videos = get_videos(
         TestGetVideos.test_dir,
         store_path=path.join(TestGetVideos.test_dir, "unexisted_dir"),
     )
     self.assertDictEqual(videos, (TestGetVideos.desired_result1))
Ejemplo n.º 4
0
 def test_store_path(self):
     create_test_directory(
         TestGetVideos.test_dir_structure2, parent_dir=TestGetVideos.test_dir,
     )
     videos = get_videos(
         TestGetVideos.test_dir,
         store_path=path.join(TestGetVideos.test_dir, "storepath"),
     )
     self.assertDictEqual(videos, (TestGetVideos.desired_result6))
Ejemplo n.º 5
0
 def test_directory_with_identifier(self):
     create_test_directory(
         TestGetVideos.test_dir_structure1, parent_dir=TestGetVideos.test_dir,
     )
     desired_result = copy.deepcopy(TestGetVideos.desired_result1)
     desired_result["file1.mkv"]["has_subtitle"] = False
     desired_result["file4.mkv"]["has_subtitle"] = True
     desired_result["file6.mkv"]["has_subtitle"] = True
     videos = get_videos(TestGetVideos.test_dir, identifier=".zh")
     self.assertDictEqual(videos, desired_result)
Ejemplo n.º 6
0
    def start(self):

        all_video_dict = get_videos(self.arg_name, self.sub_store_path,
                                    self.sub_identifier)

        for i, item in enumerate(all_video_dict.items()):

            one_video, video_info = item

            self.s_error = ""
            self.f_error = ""

            print("\n- Video:", one_video)  # 打印当前视频及其路径
            print("- Video Path:", video_info["video_path"])
            print("- Subtitles Store Path:", video_info["store_path"] + "\n")
            if video_info["has_subtitle"] and not self.over:
                print("subtitle already exists, add '-o' to replace it.")
                continue

            try:
                extract_sub_names, error = [], ""
                error, extract_sub_names = self.process_video(
                    one_video, video_info)
                self.s_error = error
            except rarfile.RarCannotExec:
                self.s_error += "Unrar not installed?"
            except Exception as e:
                self.s_error += str(e) + ". "
                self.f_error += format_exc()

            # no guessed subtitle in auto mode
            if not extract_sub_names and not error:
                self.s_error += " failed to guess one subtitle,"
                self.s_error += "use '-q' to try query mode."

            if self.s_error and not self.debug:
                self.s_error += "add --debug to get more info of the error"

            if self.s_error:
                self.failed_list.append({
                    "name": one_video,
                    "path": video_info["video_path"],
                    "error": self.s_error,
                    "trace_back": self.f_error,
                })
                print("ERROR:" + self.s_error)
            if i == len(all_video_dict) - 1:
                break
            print("\n========================================================")

        if len(self.failed_list):
            print("\n===============================", end="")
            print("FAILED LIST===============================\n")
            for i, one in enumerate(self.failed_list):
                print("%2s. name: %s" % (i + 1, one["name"]))
                print("%3s path: %s" % ("", one["path"]))
                print("%3s info: %s" % ("", one["error"]))
                if self.debug:
                    print("%3s TRACE_BACK: %s" % ("", one["trace_back"]))

        print("\ntotal: %s  success: %s  fail: %s\n" % (
            len(all_video_dict),
            len(all_video_dict) - len(self.failed_list),
            len(self.failed_list),
        ))

        return {
            "total": len(all_video_dict),
            "success": len(all_video_dict) - len(self.failed_list),
            "fail": len(self.failed_list),
            "fail_videos": self.failed_list,
        }