Exemple #1
0
    def process_video(self, video):

        extract_subs = []

        sub_dict = self.get_search_results(video)

        if len(sub_dict) == 0:
            error = "no search results. "
            return error, []

        # 遍历字幕包直到有猜测字幕
        while not extract_subs and len(sub_dict) > 0:
            exit, chosen_sub = choose_archive(sub_dict,
                                              sub_num=self.sub_num,
                                              query=self.query)
            if exit:
                break

            try:
                error, extract_subs = self.process_result(
                    video,
                    chosen_sub,
                    sub_dict[chosen_sub]["link"],
                    sub_dict[chosen_sub]["session"],
                )
                if error:
                    print("error: " + error + "\n")
            except Exception as e:
                print("error:" + str(e))
            finally:
                sub_dict.pop(chosen_sub)

        return "", extract_subs
Exemple #2
0
 def test_choose_archive_query_mode(self, mock_input):
     exit, choices = choose_archive(TestChoose.archive_dict, query=False)
     self.assertEqual((exit, choices), (False, "sub1"))
Exemple #3
0
 def test_choose_archive_sub_num(self, mock_input):
     exit, choices = choose_archive(TestChoose.archive_dict, sub_num=2)
     self.assertEqual(
         (exit, choices), (False, "sub2"),
     )
Exemple #4
0
 def test_choose_archive_out_of_range_choice(self, mock_input):
     exit, choices = choose_archive(TestChoose.archive_dict)
     self.assertEqual(
         (exit, choices), (False, "sub2"),
     )
Exemple #5
0
 def test_choose_archive_valid_input(self, mock_input):
     exit, choices = choose_archive(TestChoose.archive_dict)
     self.assertEqual((exit, choices), (False, "sub2"))
Exemple #6
0
 def test_choose_archive_exit(self, mock_input):
     exit, choices = choose_archive(TestChoose.archive_dict)
     self.assertEqual((exit, choices), (True, []))