easyrip 3.13.2__py3-none-any.whl → 4.9.1__py3-none-any.whl

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.
Files changed (36) hide show
  1. easyrip/__init__.py +5 -1
  2. easyrip/__main__.py +124 -15
  3. easyrip/easyrip_command.py +457 -148
  4. easyrip/easyrip_config/config.py +269 -0
  5. easyrip/easyrip_config/config_key.py +28 -0
  6. easyrip/easyrip_log.py +120 -42
  7. easyrip/easyrip_main.py +509 -259
  8. easyrip/easyrip_mlang/__init__.py +20 -45
  9. easyrip/easyrip_mlang/global_lang_val.py +18 -16
  10. easyrip/easyrip_mlang/lang_en.py +1 -1
  11. easyrip/easyrip_mlang/lang_zh_Hans_CN.py +101 -77
  12. easyrip/easyrip_mlang/translator.py +12 -10
  13. easyrip/easyrip_prompt.py +73 -0
  14. easyrip/easyrip_web/__init__.py +2 -1
  15. easyrip/easyrip_web/http_server.py +56 -42
  16. easyrip/easyrip_web/third_party_api.py +60 -8
  17. easyrip/global_val.py +21 -1
  18. easyrip/ripper/media_info.py +10 -3
  19. easyrip/ripper/param.py +482 -0
  20. easyrip/ripper/ripper.py +260 -574
  21. easyrip/ripper/sub_and_font/__init__.py +10 -0
  22. easyrip/ripper/{font_subset → sub_and_font}/ass.py +95 -84
  23. easyrip/ripper/{font_subset → sub_and_font}/font.py +72 -79
  24. easyrip/ripper/{font_subset → sub_and_font}/subset.py +122 -81
  25. easyrip/utils.py +129 -27
  26. easyrip-4.9.1.dist-info/METADATA +92 -0
  27. easyrip-4.9.1.dist-info/RECORD +31 -0
  28. easyrip/easyrip_config.py +0 -198
  29. easyrip/ripper/__init__.py +0 -10
  30. easyrip/ripper/font_subset/__init__.py +0 -7
  31. easyrip-3.13.2.dist-info/METADATA +0 -89
  32. easyrip-3.13.2.dist-info/RECORD +0 -29
  33. {easyrip-3.13.2.dist-info → easyrip-4.9.1.dist-info}/WHEEL +0 -0
  34. {easyrip-3.13.2.dist-info → easyrip-4.9.1.dist-info}/entry_points.txt +0 -0
  35. {easyrip-3.13.2.dist-info → easyrip-4.9.1.dist-info}/licenses/LICENSE +0 -0
  36. {easyrip-3.13.2.dist-info → easyrip-4.9.1.dist-info}/top_level.txt +0 -0
easyrip/__init__.py CHANGED
@@ -14,10 +14,13 @@ from .easyrip_mlang import (
14
14
  Lang_tag_region,
15
15
  Lang_tag_script,
16
16
  )
17
- from .ripper import Ass, Media_info, Ripper
17
+ from .ripper.media_info import Media_info
18
+ from .ripper.ripper import Ripper
19
+ from .ripper.sub_and_font import Ass, Font, load_fonts
18
20
 
19
21
  __all__ = [
20
22
  "Ass",
23
+ "Font",
21
24
  "Global_lang_val",
22
25
  "Lang_tag",
23
26
  "Lang_tag_language",
@@ -30,6 +33,7 @@ __all__ = [
30
33
  "gettext",
31
34
  "global_val",
32
35
  "init",
36
+ "load_fonts",
33
37
  "log",
34
38
  "run_command",
35
39
  ]
easyrip/__main__.py CHANGED
@@ -1,41 +1,150 @@
1
1
  import sys
2
- from typing import NoReturn
2
+ from collections.abc import Coroutine, Iterable
3
+ from typing import Any, NoReturn
3
4
 
4
5
  import Crypto
5
6
  import fontTools
7
+ import prompt_toolkit
8
+ from prompt_toolkit import ANSI, prompt
9
+ from prompt_toolkit.completion import merge_completers
10
+ from prompt_toolkit.history import InMemoryHistory
11
+ from prompt_toolkit.input.ansi_escape_sequences import ANSI_SEQUENCES
12
+ from prompt_toolkit.key_binding import KeyBindings, KeyPressEvent
13
+ from prompt_toolkit.key_binding.bindings import named_commands
14
+ from prompt_toolkit.keys import Keys
6
15
 
16
+ from .easyrip_command import (
17
+ Cmd_type,
18
+ Cmd_type_val,
19
+ CmdCompleter,
20
+ Opt_type,
21
+ OptCompleter,
22
+ nested_dict,
23
+ )
24
+ from .easyrip_config.config import Config_key, config
7
25
  from .easyrip_main import Ripper, get_input_prompt, init, log, run_command
26
+ from .easyrip_prompt import ConfigFileHistory, SmartPathCompleter, easyrip_prompt
27
+ from .global_val import C_D, C_Z
8
28
 
9
29
 
10
30
  def run() -> NoReturn:
11
31
  init(True)
12
32
 
13
- log.debug(f"pycryptodome: v{Crypto.__version__}")
33
+ log.debug(f"Python: v{sys.version}")
34
+ log.debug(f"prompt-toolkit: v{prompt_toolkit.__version__}")
14
35
  log.debug(f"fonttools: v{fontTools.__version__}")
15
-
16
- Ripper.ripper_list = []
36
+ log.debug(f"pycryptodome: v{Crypto.__version__}")
17
37
 
18
38
  if len(sys.argv) > 1:
19
39
  run_command(sys.argv[1:])
20
40
  if len(Ripper.ripper_list) == 0:
21
- sys.exit()
41
+ sys.exit(0)
42
+
43
+ key_bindings = KeyBindings()
44
+
45
+ @key_bindings.add(Keys.ControlC)
46
+ def _(event: KeyPressEvent) -> None:
47
+ event.app.exit(exception=KeyboardInterrupt, style="class:exiting")
48
+
49
+ @key_bindings.add(Keys.ControlD)
50
+ def _(event: KeyPressEvent) -> None:
51
+ event.app.current_buffer.insert_text(C_D)
52
+
53
+ ANSI_SEQUENCES["\x08"] = Keys.F24
54
+
55
+ @key_bindings.add(Keys.F24)
56
+ def _(
57
+ event: KeyPressEvent,
58
+ ) -> object | Coroutine[Any, Any, object]:
59
+ return named_commands.get_by_name("unix-word-rubout").handler(event)
60
+
61
+ path_completer = SmartPathCompleter()
62
+
63
+ def _ctv_to_nc(ctvs: Iterable[Cmd_type_val]) -> CmdCompleter:
64
+ return CmdCompleter(
65
+ {
66
+ name: (
67
+ merge_completers(completer_tuple)
68
+ if (
69
+ completer_tuple := (
70
+ *((_ctv_to_nc(ctv.childs),) if ctv.childs else ()),
71
+ *(
72
+ (path_completer,)
73
+ if name
74
+ in {
75
+ *Cmd_type.cd.value.names,
76
+ *Cmd_type.mediainfo.value.names,
77
+ *Cmd_type.fontinfo.value.names,
78
+ }
79
+ else ()
80
+ ),
81
+ )
82
+ )
83
+ else None
84
+ )
85
+ for ctv in ctvs
86
+ for name in ctv.names
87
+ }
88
+ )
89
+
90
+ def _ctv_to_nd(ctvs: Iterable[Cmd_type_val]) -> nested_dict:
91
+ return {
92
+ name: (
93
+ merge_completers(
94
+ (OptCompleter(opt_tree=_ctv_to_nd(ctv.childs)), path_completer)
95
+ )
96
+ if name
97
+ in {
98
+ *Opt_type._i.value.names,
99
+ *Opt_type._o_dir.value.names,
100
+ *Opt_type._o.value.names,
101
+ *Opt_type._sub.value.names,
102
+ *Opt_type._only_mux_sub_path.value.names,
103
+ *Opt_type._soft_sub.value.names,
104
+ *Opt_type._subset_font_dir.value.names,
105
+ *Opt_type._chapters.value.names,
106
+ }
107
+ else _ctv_to_nd(ctv.childs)
108
+ )
109
+ for ctv in ctvs
110
+ for name in ctv.names
111
+ }
112
+
113
+ cmd_ctv_tuple = tuple(ct.value for ct in Cmd_type if ct != Cmd_type.Option)
114
+ prompt_history = (
115
+ ConfigFileHistory(easyrip_prompt.PROMPT_HISTORY_FILE)
116
+ if config.get_user_profile(Config_key.save_prompt_history)
117
+ else InMemoryHistory()
118
+ )
22
119
 
23
120
  while True:
24
121
  try:
25
- command = input(get_input_prompt(is_color=True))
26
- sys.stdout.flush()
27
- sys.stderr.flush()
28
- except KeyboardInterrupt:
29
- print(
30
- f"\033[{91 if log.default_background_color == 41 else 31}m^C\033[{log.default_foreground_color}m"
122
+ command = prompt(
123
+ ANSI(get_input_prompt(is_color=True)),
124
+ key_bindings=key_bindings,
125
+ completer=merge_completers(
126
+ (
127
+ _ctv_to_nc(cmd_ctv_tuple),
128
+ OptCompleter(opt_tree=_ctv_to_nd(ct.value for ct in Opt_type)),
129
+ )
130
+ ),
131
+ history=prompt_history,
132
+ complete_while_typing=True,
31
133
  )
134
+ if command.startswith(C_Z):
135
+ raise EOFError
136
+ except KeyboardInterrupt:
32
137
  continue
33
138
  except EOFError:
34
139
  log.debug("Manually force exit")
35
- sys.exit()
140
+ sys.exit(0)
36
141
 
37
- if not run_command(command):
38
- log.warning("Stop run command")
142
+ try:
143
+ if not run_command(command):
144
+ log.warning("Stop run command")
145
+ except KeyboardInterrupt:
146
+ log.warning("Manually stop run command")
39
147
 
40
148
 
41
- run()
149
+ if __name__ == "__main__":
150
+ run()