easyrip 4.11.3__tar.gz → 4.12.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {easyrip-4.11.3 → easyrip-4.12.0}/PKG-INFO +1 -1
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/__init__.py +1 -10
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_command.py +19 -9
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_main.py +33 -34
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_mlang/__init__.py +2 -11
- easyrip-4.12.0/easyrip/easyrip_mlang/global_lang_val.py +160 -0
- easyrip-4.12.0/easyrip/easyrip_mlang/lang_en.py +5 -0
- easyrip-4.11.3/easyrip/easyrip_mlang/global_lang_val.py → easyrip-4.12.0/easyrip/easyrip_mlang/lang_tag_val.py +1 -154
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_mlang/lang_zh_Hans_CN.py +12 -12
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_mlang/translator.py +24 -29
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/global_val.py +1 -1
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/ripper/param.py +57 -17
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/ripper/ripper.py +278 -203
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip.egg-info/PKG-INFO +1 -1
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip.egg-info/SOURCES.txt +1 -0
- easyrip-4.11.3/easyrip/easyrip_mlang/lang_en.py +0 -5
- {easyrip-4.11.3 → easyrip-4.12.0}/LICENSE +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/README.md +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/__main__.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_config/config.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_config/config_key.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_log.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_prompt.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_web/__init__.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_web/http_server.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/easyrip_web/third_party_api.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/ripper/media_info.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/ripper/sub_and_font/__init__.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/ripper/sub_and_font/ass.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/ripper/sub_and_font/font.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/ripper/sub_and_font/subset.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip/utils.py +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip.egg-info/dependency_links.txt +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip.egg-info/entry_points.txt +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip.egg-info/requires.txt +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/easyrip.egg-info/top_level.txt +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/pyproject.toml +0 -0
- {easyrip-4.11.3 → easyrip-4.12.0}/setup.cfg +0 -0
|
@@ -7,13 +7,7 @@ from .easyrip_main import (
|
|
|
7
7
|
init,
|
|
8
8
|
run_command,
|
|
9
9
|
)
|
|
10
|
-
from .easyrip_mlang import
|
|
11
|
-
Global_lang_val,
|
|
12
|
-
Lang_tag,
|
|
13
|
-
Lang_tag_language,
|
|
14
|
-
Lang_tag_region,
|
|
15
|
-
Lang_tag_script,
|
|
16
|
-
)
|
|
10
|
+
from .easyrip_mlang import Global_lang_val, Lang_tag
|
|
17
11
|
from .ripper.media_info import Media_info
|
|
18
12
|
from .ripper.ripper import Ripper
|
|
19
13
|
from .ripper.sub_and_font import Ass, Font, load_fonts
|
|
@@ -23,9 +17,6 @@ __all__ = [
|
|
|
23
17
|
"Font",
|
|
24
18
|
"Global_lang_val",
|
|
25
19
|
"Lang_tag",
|
|
26
|
-
"Lang_tag_language",
|
|
27
|
-
"Lang_tag_region",
|
|
28
|
-
"Lang_tag_script",
|
|
29
20
|
"Media_info",
|
|
30
21
|
"Ripper",
|
|
31
22
|
"check_env",
|
|
@@ -18,7 +18,7 @@ from prompt_toolkit.document import Document
|
|
|
18
18
|
|
|
19
19
|
from . import global_val
|
|
20
20
|
from .easyrip_config.config_key import Config_key
|
|
21
|
-
from .ripper.param import
|
|
21
|
+
from .ripper.param import Audio_codec, Muxer, Preset_name
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
@final
|
|
@@ -353,7 +353,8 @@ class Opt_type(enum.Enum):
|
|
|
353
353
|
param="<string>",
|
|
354
354
|
description=(
|
|
355
355
|
"Setting preset\n"
|
|
356
|
-
"
|
|
356
|
+
"\n" # .
|
|
357
|
+
"Preset name:\n"
|
|
357
358
|
f"{Preset_name.to_help_string(' ')}"
|
|
358
359
|
),
|
|
359
360
|
childs=(Cmd_type_val(tuple(Preset_name._value2member_map_)),),
|
|
@@ -486,7 +487,8 @@ class Opt_type(enum.Enum):
|
|
|
486
487
|
param="<string>",
|
|
487
488
|
description=(
|
|
488
489
|
"Setting audio encoder\n"
|
|
489
|
-
"
|
|
490
|
+
"\n" # .
|
|
491
|
+
"Audio encoder:\n"
|
|
490
492
|
f"{Audio_codec.to_help_string(' ')}"
|
|
491
493
|
),
|
|
492
494
|
childs=(Cmd_type_val(tuple(Audio_codec._value2member_map_)),),
|
|
@@ -501,11 +503,11 @@ class Opt_type(enum.Enum):
|
|
|
501
503
|
param="<string>",
|
|
502
504
|
description=(
|
|
503
505
|
"Setting muxer\n"
|
|
504
|
-
"
|
|
506
|
+
"\n" # .
|
|
505
507
|
"Muxer:\n"
|
|
506
|
-
"
|
|
507
|
-
" mkv\n"
|
|
508
|
+
f"{Audio_codec.to_help_string(' ')}"
|
|
508
509
|
),
|
|
510
|
+
childs=(Cmd_type_val(tuple(Muxer._value2member_map_)),),
|
|
509
511
|
)
|
|
510
512
|
_r = _fps = Cmd_type_val(
|
|
511
513
|
("-r", "-fps"),
|
|
@@ -789,8 +791,10 @@ class OptCompleter(Completer):
|
|
|
789
791
|
_preset_name = None
|
|
790
792
|
if _preset in Preset_name._member_map_:
|
|
791
793
|
_preset_name = Preset_name[_preset]
|
|
792
|
-
if _preset_name is not None
|
|
793
|
-
add_set: set[str] = {
|
|
794
|
+
if _preset_name is not None:
|
|
795
|
+
add_set: set[str] = {
|
|
796
|
+
f"-{n}" for n in _preset_name.get_param_name_set(set())
|
|
797
|
+
}
|
|
794
798
|
add_comp_words |= add_set
|
|
795
799
|
add_comp_meta_dict |= dict.fromkeys(add_set, f"{_preset} param")
|
|
796
800
|
|
|
@@ -859,7 +863,13 @@ class OptCompleter(Completer):
|
|
|
859
863
|
|
|
860
864
|
yield from merge_completers(
|
|
861
865
|
(
|
|
862
|
-
|
|
866
|
+
merge_completers(
|
|
867
|
+
(
|
|
868
|
+
_nested_dict_to_nc(new_nd),
|
|
869
|
+
FuzzyCompleter(_nested_dict_to_nc(new_nd), WORD=True),
|
|
870
|
+
),
|
|
871
|
+
deduplicate=True,
|
|
872
|
+
),
|
|
863
873
|
FuzzyCompleter(
|
|
864
874
|
WordCompleter(
|
|
865
875
|
words=tuple(opt_tree_pos_list[-1]),
|
|
@@ -30,14 +30,12 @@ from .easyrip_log import log
|
|
|
30
30
|
from .easyrip_mlang import (
|
|
31
31
|
Global_lang_val,
|
|
32
32
|
Lang_tag,
|
|
33
|
-
Lang_tag_language,
|
|
34
33
|
get_system_language,
|
|
35
34
|
gettext,
|
|
36
35
|
translate_subtitles,
|
|
37
36
|
)
|
|
38
37
|
from .easyrip_prompt import easyrip_prompt
|
|
39
38
|
from .ripper.media_info import Media_info
|
|
40
|
-
from .ripper.param import DEFAULT_PRESET_PARAMS, PRESET_OPT_NAME
|
|
41
39
|
from .ripper.ripper import Ripper
|
|
42
40
|
from .ripper.sub_and_font import load_fonts
|
|
43
41
|
from .utils import change_title, check_ver, read_text
|
|
@@ -419,40 +417,41 @@ def run_command(command: Iterable[str] | str) -> bool:
|
|
|
419
417
|
log.send(_want_doc_cmd_type.value.to_doc(), is_format=False)
|
|
420
418
|
elif cmd_list[2] in Ripper.Preset_name._value2member_map_:
|
|
421
419
|
_preset = Ripper.Preset_name(cmd_list[2])
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
):
|
|
426
|
-
if _preset in PRESET_OPT_NAME:
|
|
427
|
-
log.send(
|
|
428
|
-
"Params that can be directly used:\n{}",
|
|
429
|
-
textwrap.indent(
|
|
430
|
-
"\n".join(
|
|
431
|
-
f"-{n}"
|
|
432
|
-
for n in PRESET_OPT_NAME[_preset]
|
|
433
|
-
),
|
|
434
|
-
prefix=" ",
|
|
435
|
-
),
|
|
436
|
-
)
|
|
437
|
-
if _preset in DEFAULT_PRESET_PARAMS:
|
|
438
|
-
_default_params = DEFAULT_PRESET_PARAMS[_preset]
|
|
439
|
-
max_name_len = (
|
|
440
|
-
max(len(str(n)) for n in _default_params) + 1
|
|
441
|
-
)
|
|
442
|
-
log.send(
|
|
443
|
-
"Default val:\n{}",
|
|
444
|
-
textwrap.indent(
|
|
445
|
-
"\n".join(
|
|
446
|
-
f"{f'-{n}':>{max_name_len}} {v}"
|
|
447
|
-
for n, v in _default_params.items()
|
|
448
|
-
),
|
|
449
|
-
prefix=" ",
|
|
450
|
-
),
|
|
451
|
-
)
|
|
452
|
-
else:
|
|
420
|
+
_param_default_dict = _preset.get_param_default_dict()
|
|
421
|
+
_param_name_set = _preset.get_param_name_set()
|
|
422
|
+
if not any((_param_default_dict, _param_name_set)):
|
|
453
423
|
log.send(
|
|
454
424
|
"The preset '{}' has no separate help", cmd_list[2]
|
|
455
425
|
)
|
|
426
|
+
if _param_name_set:
|
|
427
|
+
log.send(
|
|
428
|
+
"Params that can be directly used:\n{}",
|
|
429
|
+
textwrap.indent(
|
|
430
|
+
"\n".join(f"-{n}" for n in _param_name_set),
|
|
431
|
+
prefix=" ",
|
|
432
|
+
),
|
|
433
|
+
)
|
|
434
|
+
if _param_default_dict:
|
|
435
|
+
max_name_len = (
|
|
436
|
+
max(len(str(n)) for n in _param_default_dict) + 1
|
|
437
|
+
)
|
|
438
|
+
log.send(
|
|
439
|
+
"Default val:\n{}",
|
|
440
|
+
textwrap.indent(
|
|
441
|
+
"\n".join(
|
|
442
|
+
f"{f'-{n}':>{max_name_len}} {v}"
|
|
443
|
+
for n, v in _param_default_dict.items()
|
|
444
|
+
),
|
|
445
|
+
prefix=" ",
|
|
446
|
+
),
|
|
447
|
+
)
|
|
448
|
+
log.send(
|
|
449
|
+
" FFmpeg format:\n {}",
|
|
450
|
+
":".join(
|
|
451
|
+
f"{n}={v}"
|
|
452
|
+
for n, v in _param_default_dict.items()
|
|
453
|
+
),
|
|
454
|
+
)
|
|
456
455
|
else:
|
|
457
456
|
log.error("'{}' is not a member of preset", cmd_list[2])
|
|
458
457
|
|
|
@@ -1156,7 +1155,7 @@ def init(is_first_run: bool = False) -> None:
|
|
|
1156
1155
|
|
|
1157
1156
|
if (
|
|
1158
1157
|
lang_tag := Lang_tag.from_str(file.stem[5:])
|
|
1159
|
-
).language is not
|
|
1158
|
+
).language is not Lang_tag.Language.Unknown:
|
|
1160
1159
|
easyrip_mlang.all_supported_lang_map[lang_tag] = lang_map
|
|
1161
1160
|
|
|
1162
1161
|
log.debug("Loading \"{}\" as '{}' language successfully", file, lang_tag)
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import locale
|
|
2
2
|
|
|
3
3
|
from . import lang_en, lang_zh_Hans_CN
|
|
4
|
-
from .global_lang_val import
|
|
5
|
-
|
|
6
|
-
Lang_tag,
|
|
7
|
-
Lang_tag_language,
|
|
8
|
-
Lang_tag_region,
|
|
9
|
-
Lang_tag_script,
|
|
10
|
-
Lang_tag_val,
|
|
11
|
-
)
|
|
4
|
+
from .global_lang_val import Global_lang_val, Lang_tag
|
|
5
|
+
from .lang_tag_val import Lang_tag_val
|
|
12
6
|
from .translator import translate_subtitles
|
|
13
7
|
|
|
14
8
|
__all__ = [
|
|
15
9
|
"Global_lang_val",
|
|
16
10
|
"Lang_tag",
|
|
17
|
-
"Lang_tag_language",
|
|
18
|
-
"Lang_tag_region",
|
|
19
|
-
"Lang_tag_script",
|
|
20
11
|
"Lang_tag_val",
|
|
21
12
|
"Mlang_exception",
|
|
22
13
|
"get_system_language",
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import enum
|
|
2
|
+
from collections.abc import Iterable
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
from typing import Self, final
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@final
|
|
8
|
+
@dataclass(slots=True, kw_only=True)
|
|
9
|
+
class Lang_tag:
|
|
10
|
+
from .lang_tag_val import Lang_tag_language as Language
|
|
11
|
+
from .lang_tag_val import Lang_tag_region as Region
|
|
12
|
+
from .lang_tag_val import Lang_tag_script as Script
|
|
13
|
+
|
|
14
|
+
language: Language = Language.Unknown
|
|
15
|
+
script: Script = Script.Unknown
|
|
16
|
+
region: Region = Region.Unknown
|
|
17
|
+
|
|
18
|
+
class Match_priority(enum.Enum):
|
|
19
|
+
script = enum.auto()
|
|
20
|
+
region = enum.auto()
|
|
21
|
+
|
|
22
|
+
def match(
|
|
23
|
+
self,
|
|
24
|
+
target_tags: Iterable[Self],
|
|
25
|
+
*,
|
|
26
|
+
is_incomplete_match: bool = True,
|
|
27
|
+
priority: Match_priority = Match_priority.script,
|
|
28
|
+
is_allow_mismatch_language: bool = False,
|
|
29
|
+
) -> Self | None:
|
|
30
|
+
"""启用不完整匹配时,找到最匹配的第一项"""
|
|
31
|
+
target_tags_tuple = tuple(target_tags)
|
|
32
|
+
del target_tags
|
|
33
|
+
|
|
34
|
+
matching_tags_tuple = tuple(
|
|
35
|
+
tag for tag in target_tags_tuple if tag.language is self.language
|
|
36
|
+
)
|
|
37
|
+
if not matching_tags_tuple:
|
|
38
|
+
if is_allow_mismatch_language:
|
|
39
|
+
matching_tags_tuple = target_tags_tuple
|
|
40
|
+
else:
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
if self in matching_tags_tuple:
|
|
44
|
+
return self
|
|
45
|
+
if not is_incomplete_match:
|
|
46
|
+
return None
|
|
47
|
+
|
|
48
|
+
same_region_tuple = tuple(
|
|
49
|
+
tag for tag in matching_tags_tuple if tag.region is self.region
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
same_script_tuple = tuple(
|
|
53
|
+
tag for tag in matching_tags_tuple if tag.script is self.script
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if priority_same_tuple := (
|
|
57
|
+
same_script_tuple + same_region_tuple
|
|
58
|
+
if priority is self.__class__.Match_priority.script
|
|
59
|
+
else same_region_tuple + same_script_tuple
|
|
60
|
+
):
|
|
61
|
+
return priority_same_tuple[0]
|
|
62
|
+
|
|
63
|
+
return matching_tags_tuple[0]
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def from_str(
|
|
67
|
+
cls,
|
|
68
|
+
str_tag: str,
|
|
69
|
+
) -> Self:
|
|
70
|
+
"""
|
|
71
|
+
输入语言标签字符串,输出标签对象
|
|
72
|
+
|
|
73
|
+
e.g. zh-Hans-CN -> Self(Language.zh, Script.Hans, Region.CN)
|
|
74
|
+
"""
|
|
75
|
+
from ..easyrip_mlang import gettext
|
|
76
|
+
|
|
77
|
+
str_tag_list = str_tag.split("-")
|
|
78
|
+
|
|
79
|
+
language: Lang_tag.Language = cls.Language.from_name(str_tag_list[0])
|
|
80
|
+
script: Lang_tag.Script = cls.Script.Unknown
|
|
81
|
+
region: Lang_tag.Region = cls.Region.Unknown
|
|
82
|
+
|
|
83
|
+
for i, s in enumerate(str_tag_list[1:]):
|
|
84
|
+
if s in cls.Script._member_map_:
|
|
85
|
+
if i != 0:
|
|
86
|
+
raise ValueError(
|
|
87
|
+
gettext("The input language tag string format is illegal")
|
|
88
|
+
)
|
|
89
|
+
script = cls.Script[s]
|
|
90
|
+
elif s in cls.Region._member_map_:
|
|
91
|
+
region = cls.Region[s]
|
|
92
|
+
|
|
93
|
+
return cls(
|
|
94
|
+
language=language,
|
|
95
|
+
script=script,
|
|
96
|
+
region=region,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def __str__(self) -> str:
|
|
100
|
+
"""返回语言标签字符串"""
|
|
101
|
+
if self.language == self.__class__.Language.Unknown:
|
|
102
|
+
raise Exception("The Language is Unknown")
|
|
103
|
+
|
|
104
|
+
res_str: str = self.language.name
|
|
105
|
+
if self.script != self.__class__.Script.Unknown:
|
|
106
|
+
res_str += f"-{self.script.name}"
|
|
107
|
+
if self.region != self.__class__.Region.Unknown:
|
|
108
|
+
res_str += f"-{self.region.name}"
|
|
109
|
+
|
|
110
|
+
return res_str
|
|
111
|
+
|
|
112
|
+
def __hash__(self) -> int:
|
|
113
|
+
return hash((self.language, self.script, self.region))
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class Global_lang_val:
|
|
117
|
+
gettext_target_lang: Lang_tag = Lang_tag()
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def language_tag_to_local_str(language_tag: str) -> str:
|
|
121
|
+
from ..easyrip_mlang import gettext
|
|
122
|
+
|
|
123
|
+
tag_list = language_tag.split("-")
|
|
124
|
+
tag_list_len = len(tag_list)
|
|
125
|
+
|
|
126
|
+
if tag_list_len == 0:
|
|
127
|
+
raise Exception(gettext("The input language tag string format is illegal"))
|
|
128
|
+
|
|
129
|
+
res_str_list: list[str] = [
|
|
130
|
+
_local_name
|
|
131
|
+
if (_org_name := tag_list[0]) in Lang_tag.Language._member_map_
|
|
132
|
+
and (_local_name := Lang_tag.Language[_org_name].value.local_name)
|
|
133
|
+
else _org_name
|
|
134
|
+
]
|
|
135
|
+
|
|
136
|
+
if tag_list_len >= 2:
|
|
137
|
+
_org_name = tag_list[1]
|
|
138
|
+
|
|
139
|
+
if _org_name in Lang_tag.Script.__members__:
|
|
140
|
+
_local_name = Lang_tag.Script[_org_name].value.local_name
|
|
141
|
+
elif _org_name in Lang_tag.Region._member_map_:
|
|
142
|
+
_local_name = Lang_tag.Region[_org_name].value.local_name
|
|
143
|
+
else:
|
|
144
|
+
_local_name = _org_name
|
|
145
|
+
|
|
146
|
+
res_str_list.append(_local_name)
|
|
147
|
+
|
|
148
|
+
if tag_list_len >= 3:
|
|
149
|
+
_org_name = tag_list[2]
|
|
150
|
+
|
|
151
|
+
if _org_name in Lang_tag.Region._member_map_:
|
|
152
|
+
_local_name = Lang_tag.Region[_org_name].value.local_name
|
|
153
|
+
else:
|
|
154
|
+
_local_name = _org_name
|
|
155
|
+
|
|
156
|
+
res_str_list.append(_local_name)
|
|
157
|
+
|
|
158
|
+
return (" - " if any(" " in s for s in res_str_list) else "-").join(
|
|
159
|
+
res_str_list
|
|
160
|
+
)
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import enum
|
|
2
|
-
from collections.abc import Iterable
|
|
3
2
|
from dataclasses import dataclass
|
|
4
|
-
from typing import
|
|
3
|
+
from typing import final
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
@final
|
|
@@ -144,155 +143,3 @@ class Lang_tag_region(enum.Enum):
|
|
|
144
143
|
return cls[name]
|
|
145
144
|
except KeyError:
|
|
146
145
|
return cls.Unknown
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
@final
|
|
150
|
-
@dataclass(slots=True, kw_only=True)
|
|
151
|
-
class Lang_tag:
|
|
152
|
-
language: Lang_tag_language = Lang_tag_language.Unknown
|
|
153
|
-
script: Lang_tag_script = Lang_tag_script.Unknown
|
|
154
|
-
region: Lang_tag_region = Lang_tag_region.Unknown
|
|
155
|
-
|
|
156
|
-
class Match_priority(enum.Enum):
|
|
157
|
-
script = enum.auto()
|
|
158
|
-
region = enum.auto()
|
|
159
|
-
|
|
160
|
-
def match(
|
|
161
|
-
self,
|
|
162
|
-
target_tags: Iterable[Self],
|
|
163
|
-
*,
|
|
164
|
-
is_incomplete_match: bool = True,
|
|
165
|
-
priority: Match_priority = Match_priority.script,
|
|
166
|
-
is_allow_mismatch_language: bool = False,
|
|
167
|
-
) -> Self | None:
|
|
168
|
-
"""启用不完整匹配时,找到最匹配的第一项"""
|
|
169
|
-
target_tags_tuple = tuple(target_tags)
|
|
170
|
-
del target_tags
|
|
171
|
-
|
|
172
|
-
matching_tags_tuple = tuple(
|
|
173
|
-
tag for tag in target_tags_tuple if tag.language is self.language
|
|
174
|
-
)
|
|
175
|
-
if not matching_tags_tuple:
|
|
176
|
-
if is_allow_mismatch_language:
|
|
177
|
-
matching_tags_tuple = target_tags_tuple
|
|
178
|
-
else:
|
|
179
|
-
return None
|
|
180
|
-
|
|
181
|
-
if self in matching_tags_tuple:
|
|
182
|
-
return self
|
|
183
|
-
if not is_incomplete_match:
|
|
184
|
-
return None
|
|
185
|
-
|
|
186
|
-
same_region_tuple = tuple(
|
|
187
|
-
tag for tag in matching_tags_tuple if tag.region is self.region
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
same_script_tuple = tuple(
|
|
191
|
-
tag for tag in matching_tags_tuple if tag.script is self.script
|
|
192
|
-
)
|
|
193
|
-
|
|
194
|
-
if priority_same_tuple := (
|
|
195
|
-
same_script_tuple + same_region_tuple
|
|
196
|
-
if priority is Lang_tag.Match_priority.script
|
|
197
|
-
else same_region_tuple + same_script_tuple
|
|
198
|
-
):
|
|
199
|
-
return priority_same_tuple[0]
|
|
200
|
-
|
|
201
|
-
return matching_tags_tuple[0]
|
|
202
|
-
|
|
203
|
-
@classmethod
|
|
204
|
-
def from_str(
|
|
205
|
-
cls,
|
|
206
|
-
str_tag: str,
|
|
207
|
-
) -> Self:
|
|
208
|
-
"""
|
|
209
|
-
输入语言标签字符串,输出标签对象
|
|
210
|
-
|
|
211
|
-
e.g. zh-Hans-CN -> Self(Language.zh, Script.Hans, Region.CN)
|
|
212
|
-
"""
|
|
213
|
-
from ..easyrip_mlang import gettext
|
|
214
|
-
|
|
215
|
-
str_tag_list = str_tag.split("-")
|
|
216
|
-
|
|
217
|
-
language = Lang_tag_language.from_name(str_tag_list[0])
|
|
218
|
-
script: Lang_tag_script = Lang_tag_script.Unknown
|
|
219
|
-
region: Lang_tag_region = Lang_tag_region.Unknown
|
|
220
|
-
|
|
221
|
-
for i, s in enumerate(str_tag_list[1:]):
|
|
222
|
-
if s in Lang_tag_script._member_map_:
|
|
223
|
-
if i != 0:
|
|
224
|
-
raise ValueError(
|
|
225
|
-
gettext("The input language tag string format is illegal")
|
|
226
|
-
)
|
|
227
|
-
script = Lang_tag_script[s]
|
|
228
|
-
elif s in Lang_tag_region._member_map_:
|
|
229
|
-
region = Lang_tag_region[s]
|
|
230
|
-
|
|
231
|
-
return cls(
|
|
232
|
-
language=language,
|
|
233
|
-
script=script,
|
|
234
|
-
region=region,
|
|
235
|
-
)
|
|
236
|
-
|
|
237
|
-
def __str__(self) -> str:
|
|
238
|
-
"""返回语言标签字符串"""
|
|
239
|
-
if self.language == Lang_tag_language.Unknown:
|
|
240
|
-
raise Exception("The Language is Unknown")
|
|
241
|
-
|
|
242
|
-
res_str: str = self.language.name
|
|
243
|
-
if self.script != Lang_tag_script.Unknown:
|
|
244
|
-
res_str += f"-{self.script.name}"
|
|
245
|
-
if self.region != Lang_tag_region.Unknown:
|
|
246
|
-
res_str += f"-{self.region.name}"
|
|
247
|
-
|
|
248
|
-
return res_str
|
|
249
|
-
|
|
250
|
-
def __hash__(self) -> int:
|
|
251
|
-
return hash((self.language, self.script, self.region))
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
class Global_lang_val:
|
|
255
|
-
gettext_target_lang: Lang_tag = Lang_tag()
|
|
256
|
-
|
|
257
|
-
@staticmethod
|
|
258
|
-
def language_tag_to_local_str(language_tag: str) -> str:
|
|
259
|
-
from ..easyrip_mlang import gettext
|
|
260
|
-
|
|
261
|
-
tag_list = language_tag.split("-")
|
|
262
|
-
tag_list_len = len(tag_list)
|
|
263
|
-
|
|
264
|
-
if tag_list_len == 0:
|
|
265
|
-
raise Exception(gettext("The input language tag string format is illegal"))
|
|
266
|
-
|
|
267
|
-
res_str_list: list[str] = [
|
|
268
|
-
_local_name
|
|
269
|
-
if (_org_name := tag_list[0]) in Lang_tag_language._member_map_
|
|
270
|
-
and (_local_name := Lang_tag_language[_org_name].value.local_name)
|
|
271
|
-
else _org_name
|
|
272
|
-
]
|
|
273
|
-
|
|
274
|
-
if tag_list_len >= 2:
|
|
275
|
-
_org_name = tag_list[1]
|
|
276
|
-
|
|
277
|
-
if _org_name in Lang_tag_script.__members__:
|
|
278
|
-
_local_name = Lang_tag_script[_org_name].value.local_name
|
|
279
|
-
elif _org_name in Lang_tag_region._member_map_:
|
|
280
|
-
_local_name = Lang_tag_region[_org_name].value.local_name
|
|
281
|
-
else:
|
|
282
|
-
_local_name = _org_name
|
|
283
|
-
|
|
284
|
-
res_str_list.append(_local_name)
|
|
285
|
-
|
|
286
|
-
if tag_list_len >= 3:
|
|
287
|
-
_org_name = tag_list[2]
|
|
288
|
-
|
|
289
|
-
if _org_name in Lang_tag_region._member_map_:
|
|
290
|
-
_local_name = Lang_tag_region[_org_name].value.local_name
|
|
291
|
-
else:
|
|
292
|
-
_local_name = _org_name
|
|
293
|
-
|
|
294
|
-
res_str_list.append(_local_name)
|
|
295
|
-
|
|
296
|
-
return (" - " if any(" " in s for s in res_str_list) else "-").join(
|
|
297
|
-
res_str_list
|
|
298
|
-
)
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
from ..easyrip_command import Audio_codec, Cmd_type, Opt_type, Preset_name
|
|
2
|
-
from .global_lang_val import
|
|
3
|
-
Lang_tag,
|
|
4
|
-
Lang_tag_language,
|
|
5
|
-
Lang_tag_region,
|
|
6
|
-
Lang_tag_script,
|
|
7
|
-
)
|
|
2
|
+
from .global_lang_val import Lang_tag
|
|
8
3
|
|
|
9
4
|
LANG_TAG = Lang_tag(
|
|
10
|
-
language=
|
|
11
|
-
script=
|
|
12
|
-
region=
|
|
5
|
+
language=Lang_tag.Language.zh,
|
|
6
|
+
script=Lang_tag.Script.Hans,
|
|
7
|
+
region=Lang_tag.Region.CN,
|
|
13
8
|
)
|
|
14
9
|
|
|
15
10
|
LANG_MAP: dict[str, str] = {
|
|
@@ -135,7 +130,8 @@ LANG_MAP: dict[str, str] = {
|
|
|
135
130
|
),
|
|
136
131
|
Opt_type._preset.value.description: (
|
|
137
132
|
"设置预设\n"
|
|
138
|
-
"
|
|
133
|
+
"\n" # .
|
|
134
|
+
"预设名:\n"
|
|
139
135
|
f"{Preset_name.to_help_string(' ')}"
|
|
140
136
|
),
|
|
141
137
|
Opt_type._pipe.value.description: (
|
|
@@ -199,13 +195,14 @@ LANG_MAP: dict[str, str] = {
|
|
|
199
195
|
),
|
|
200
196
|
Opt_type._c_a.value.description: (
|
|
201
197
|
"设置音频编码器\n"
|
|
202
|
-
"
|
|
198
|
+
"\n" # .
|
|
199
|
+
"音频编码器:\n"
|
|
203
200
|
f"{Audio_codec.to_help_string(' ')}"
|
|
204
201
|
),
|
|
205
202
|
Opt_type._b_a.value.description: "设置音频码率。默认值 '160k'",
|
|
206
203
|
Opt_type._muxer.value.description: (
|
|
207
204
|
"设置复用器\n"
|
|
208
|
-
"
|
|
205
|
+
"\n" # .
|
|
209
206
|
"可用的复用器:\n"
|
|
210
207
|
" mp4\n"
|
|
211
208
|
" mkv"
|
|
@@ -323,6 +320,9 @@ LANG_MAP: dict[str, str] = {
|
|
|
323
320
|
"Failed to add Ripper: {}": "添加 Ripper 失败: {}",
|
|
324
321
|
"'{}' is not a valid '{}', set to default value '{}'. Valid options are: {}": "'{}' 不存在于 '{}', 已设为默认值 '{}'。有以下值可用: {}",
|
|
325
322
|
"The preset custom must have custom:format or custom:template": "custom 预设必须要有 custom:format 或 custom:template",
|
|
323
|
+
"Run the following commands in order:\n{}": "按顺序执行以下命令:\n{}",
|
|
324
|
+
"Run the command {}": "执行命令 {}",
|
|
325
|
+
"Command run failed: status code {}\n Failed command: {}": "命令执行失败: 状态码 {}\n 失败的命令: {}",
|
|
326
326
|
"There have error in running": "执行时出错",
|
|
327
327
|
"{} param illegal": "{} 参数非法",
|
|
328
328
|
'The file "{}" already exists, skip translating it': '文件 "{}" 已存在, 跳过翻译',
|