gecko-web-runtime-client 1.4.4__tar.gz → 1.4.6__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.
Files changed (106) hide show
  1. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/PACKAGE_README.md +50 -0
  2. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/PKG-INFO +52 -2
  3. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/__init__.py +3 -0
  4. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/__init__.py +4 -0
  5. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/client.py +46 -2
  6. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/tencent-video-host.json +77 -0
  7. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/package-lock.json +3 -5
  8. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/package.json +3 -4
  9. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/js_runtime/environment/tencent_video.js +98 -0
  10. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/js_runtime/environment/video_extract.js +38 -0
  11. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/resources/migration-manifest.json +28 -4
  12. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/runtime.py +1 -1
  13. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/media/__init__.py +5 -0
  14. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/media/downloader.py +239 -0
  15. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/media/extractor.py +65 -0
  16. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/media/models.py +79 -0
  17. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/media/mp4.py +95 -0
  18. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/media/tencent.py +129 -0
  19. gecko_web_runtime_client-1.4.6/gecko_web_runtime/integrations/wechat/media/transport.py +46 -0
  20. gecko_web_runtime_client-1.4.6/gecko_web_runtime/javascript/__init__.py +8 -0
  21. gecko_web_runtime_client-1.4.6/gecko_web_runtime/javascript/__main__.py +30 -0
  22. gecko_web_runtime_client-1.4.6/gecko_web_runtime/javascript/_network.py +56 -0
  23. gecko_web_runtime_client-1.4.6/gecko_web_runtime/javascript/context.py +436 -0
  24. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime_client.egg-info/PKG-INFO +52 -2
  25. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime_client.egg-info/SOURCES.txt +14 -0
  26. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime_client.egg-info/requires.txt +1 -1
  27. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/pyproject.toml +2 -2
  28. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/README.md +0 -0
  29. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/__main__.py +0 -0
  30. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/_leases.py +0 -0
  31. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/api/__init__.py +0 -0
  32. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/api/context.py +0 -0
  33. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/api/page.py +0 -0
  34. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/api/pool.py +0 -0
  35. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/api/runtime.py +0 -0
  36. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/data_plane.py +0 -0
  37. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/diagnostics/__init__.py +0 -0
  38. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/diagnostics/gc_cc.py +0 -0
  39. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/diagnostics/logging.py +0 -0
  40. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/diagnostics/memory.py +0 -0
  41. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/diagnostics/metrics.py +0 -0
  42. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/diagnostics/resources.py +0 -0
  43. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/http.py +0 -0
  44. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/installer.py +0 -0
  45. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/__init__.py +0 -0
  46. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/__main__.py +0 -0
  47. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_article.py +0 -0
  48. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_diagnostics.py +0 -0
  49. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_diagnostics_round.py +0 -0
  50. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_flow.py +0 -0
  51. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_frame_context.py +0 -0
  52. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_logging.py +0 -0
  53. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_manual_data.py +0 -0
  54. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_slider_image.py +0 -0
  55. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/_variant_resources.py +0 -0
  56. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/exceptions.py +0 -0
  57. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/__init__.py +0 -0
  58. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/capability_profile.json +0 -0
  59. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/computed-style.js +0 -0
  60. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/drag-control.js +0 -0
  61. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/drag-motion.js +0 -0
  62. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/drag-target.js +0 -0
  63. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/ft.module.js +0 -0
  64. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/host-timeline.js +0 -0
  65. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/input-events.js +0 -0
  66. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/layout_profile.json +0 -0
  67. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/manual-gesture.js +0 -0
  68. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/media_profile.json +0 -0
  69. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/native-gl-client.js +0 -0
  70. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/native-webgl.js +0 -0
  71. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/native_gl.py +0 -0
  72. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/native_gl_service.py +0 -0
  73. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/plugin_profile.json +0 -0
  74. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/rtproxy.js +0 -0
  75. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/sdk-handshake.js +0 -0
  76. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/tracker.module.js +0 -0
  77. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/var-speed-drag-control.js +0 -0
  78. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/webgl_profile.json +0 -0
  79. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/assets/window-message-bridge.js +0 -0
  80. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/environment/code.js +0 -0
  81. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/executor.py +0 -0
  82. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/native_gl_service.py +0 -0
  83. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/resources/frame-context-manifest.json +0 -0
  84. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/js_runtime/resources/var-speed-resource-manifest.json +0 -0
  85. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/models.py +0 -0
  86. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/integrations/wechat/transport.py +0 -0
  87. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/iocp_pipe.py +0 -0
  88. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/media_capture.py +0 -0
  89. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/media_downloader.py +0 -0
  90. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/models/__init__.py +0 -0
  91. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/models/navigation.py +0 -0
  92. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/network/__init__.py +0 -0
  93. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/network/_urls.py +0 -0
  94. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/network/client.py +0 -0
  95. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/network/exceptions.py +0 -0
  96. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/network/models.py +0 -0
  97. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/network/transport.py +0 -0
  98. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/pipe.py +0 -0
  99. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/session.py +0 -0
  100. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/workflows/__init__.py +0 -0
  101. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/workflows/turnstile.py +0 -0
  102. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/workflows/wechat.py +0 -0
  103. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime/workflows/wechat_challenge.py +0 -0
  104. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime_client.egg-info/dependency_links.txt +0 -0
  105. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/gecko_web_runtime_client.egg-info/top_level.txt +0 -0
  106. {gecko_web_runtime_client-1.4.4 → gecko_web_runtime_client-1.4.6}/setup.cfg +0 -0
@@ -4,6 +4,29 @@ Python page and browser client for a versioned Firefox-derived WPR runtime.
4
4
  It exposes pages, contexts, navigation, DOM access, screenshots, diagnostics,
5
5
  Turnstile and WeChat workflow adapters.
6
6
 
7
+ Version 1.4.6 also exposes persistent standalone `JSContext` and `AsyncJSContext`:
8
+
9
+ ```python
10
+ from gecko_web_runtime import JSContext
11
+ from gecko_web_runtime.javascript import NetworkConfig
12
+
13
+ with JSContext(network=NetworkConfig()) as ctx:
14
+ ctx.navigate("https://example.com/")
15
+ print(ctx.eval("({title:document.title,url:location.href})"))
16
+ ```
17
+
18
+ Install the matching private release products first:
19
+
20
+ ```powershell
21
+ python -m gecko_web_runtime.javascript install-runtime --product network --version 155.0.10
22
+ python -m gecko_web_runtime.javascript install-runtime --version 155.0.1
23
+ ```
24
+
25
+ The standalone host and self-implemented DOM/BOM remain in the native Runtime
26
+ repository. Both standalone JavaScript and `wpr-http` reuse the same network
27
+ product; no second network implementation is bundled. Separate Contexts can
28
+ run concurrently; operations within one Context are ordered.
29
+
7
30
  The native runtime is installed separately:
8
31
 
9
32
  ```powershell
@@ -56,6 +79,33 @@ can contain session-sensitive diagnostic data. Keep those directories outside
56
79
  source control. Site rejection is returned as a structured failure, not a
57
80
  promise that any verification will succeed.
58
81
 
82
+ ## WeChat article videos (1.4.5+)
83
+
84
+ The same `gecko-web-runtime-client[wechat]` installation now provides two
85
+ separate operations, without starting a browser Page:
86
+
87
+ ```python
88
+ from gecko_web_runtime.integrations.wechat import AsyncWechatClient, VideoDownloadOptions
89
+
90
+ async with AsyncWechatClient(proxy="") as client:
91
+ article = await client.get("ARTICLE_URL")
92
+ if article.ok:
93
+ downloads = await client.download_videos(
94
+ article, output_dir="./videos",
95
+ options=VideoDownloadOptions(quality="sd"),
96
+ )
97
+ for download in downloads:
98
+ print(download.summary())
99
+ ```
100
+
101
+ Article retrieval, WeChat video downloads, and current Tencent SDK resolution
102
+ share the caller's `wpr-http` session and proxy. Run `python -m
103
+ gecko_web_runtime.integrations.wechat install-js` after upgrading to prepare
104
+ the production Node dependencies. Downloads use validated Range requests,
105
+ conditional resume and verified-file skipping; completed files are not
106
+ overwritten. Servers ignoring Range still return buffered whole responses.
107
+ See `python/docs/wechat-video-download.md` for limits and recovery behavior.
108
+
59
109
  ## Media capture
60
110
 
61
111
  For a browser-played Widevine page, use `AsyncMediaDownloader`. It starts the
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gecko-web-runtime-client
3
- Version: 1.4.4
3
+ Version: 1.4.6
4
4
  Summary: Thin Python client for the Firefox-derived WPR Gecko Worker protocol
5
5
  Author: WPR project
6
6
  License: MPL-2.0-compatible client; see the runtime bundle notices
@@ -8,7 +8,7 @@ Project-URL: Repository, https://github.com/childclm/gecko-web-runtime-client
8
8
  Project-URL: Documentation, https://github.com/childclm/gecko-web-runtime-client/blob/main/README.md
9
9
  Requires-Python: >=3.10
10
10
  Description-Content-Type: text/markdown
11
- Requires-Dist: wpr-runtime-core<0.3,>=0.2.2
11
+ Requires-Dist: wpr-runtime-core<0.3,>=0.2.4
12
12
  Requires-Dist: wpr-http<0.3,>=0.2.0
13
13
  Provides-Extra: diagnostics
14
14
  Requires-Dist: loguru>=0.7.2; extra == "diagnostics"
@@ -25,6 +25,29 @@ Python page and browser client for a versioned Firefox-derived WPR runtime.
25
25
  It exposes pages, contexts, navigation, DOM access, screenshots, diagnostics,
26
26
  Turnstile and WeChat workflow adapters.
27
27
 
28
+ Version 1.4.6 also exposes persistent standalone `JSContext` and `AsyncJSContext`:
29
+
30
+ ```python
31
+ from gecko_web_runtime import JSContext
32
+ from gecko_web_runtime.javascript import NetworkConfig
33
+
34
+ with JSContext(network=NetworkConfig()) as ctx:
35
+ ctx.navigate("https://example.com/")
36
+ print(ctx.eval("({title:document.title,url:location.href})"))
37
+ ```
38
+
39
+ Install the matching private release products first:
40
+
41
+ ```powershell
42
+ python -m gecko_web_runtime.javascript install-runtime --product network --version 155.0.10
43
+ python -m gecko_web_runtime.javascript install-runtime --version 155.0.1
44
+ ```
45
+
46
+ The standalone host and self-implemented DOM/BOM remain in the native Runtime
47
+ repository. Both standalone JavaScript and `wpr-http` reuse the same network
48
+ product; no second network implementation is bundled. Separate Contexts can
49
+ run concurrently; operations within one Context are ordered.
50
+
28
51
  The native runtime is installed separately:
29
52
 
30
53
  ```powershell
@@ -77,6 +100,33 @@ can contain session-sensitive diagnostic data. Keep those directories outside
77
100
  source control. Site rejection is returned as a structured failure, not a
78
101
  promise that any verification will succeed.
79
102
 
103
+ ## WeChat article videos (1.4.5+)
104
+
105
+ The same `gecko-web-runtime-client[wechat]` installation now provides two
106
+ separate operations, without starting a browser Page:
107
+
108
+ ```python
109
+ from gecko_web_runtime.integrations.wechat import AsyncWechatClient, VideoDownloadOptions
110
+
111
+ async with AsyncWechatClient(proxy="") as client:
112
+ article = await client.get("ARTICLE_URL")
113
+ if article.ok:
114
+ downloads = await client.download_videos(
115
+ article, output_dir="./videos",
116
+ options=VideoDownloadOptions(quality="sd"),
117
+ )
118
+ for download in downloads:
119
+ print(download.summary())
120
+ ```
121
+
122
+ Article retrieval, WeChat video downloads, and current Tencent SDK resolution
123
+ share the caller's `wpr-http` session and proxy. Run `python -m
124
+ gecko_web_runtime.integrations.wechat install-js` after upgrading to prepare
125
+ the production Node dependencies. Downloads use validated Range requests,
126
+ conditional resume and verified-file skipping; completed files are not
127
+ overwritten. Servers ignoring Range still return buffered whole responses.
128
+ See `python/docs/wechat-video-download.md` for limits and recovery behavior.
129
+
80
130
  ## Media capture
81
131
 
82
132
  For a browser-played Widevine page, use `AsyncMediaDownloader`. It starts the
@@ -24,6 +24,7 @@ from .http import (
24
24
  WprTransportError,
25
25
  )
26
26
  from .installer import install_runtime
27
+ from .javascript import JSContext, AsyncJSContext
27
28
  from .media_capture import package_media_capture
28
29
  from .media_downloader import AsyncMediaDownloader, MediaDownloadError
29
30
  from .models.navigation import TurnstileResult, WechatArticleResult
@@ -37,6 +38,8 @@ from .workflows.turnstile import TurnstileWorkflow
37
38
  from .workflows.wechat import WechatArticleWorkflow
38
39
 
39
40
  __all__ = [
41
+ "JSContext",
42
+ "AsyncJSContext",
40
43
  "AsyncGeckoRuntime",
41
44
  "AsyncGeckoWorkerPool",
42
45
  "AsyncGeckoWorkerSession",
@@ -3,10 +3,14 @@
3
3
  from .client import AsyncWechatClient
4
4
  from .exceptions import WechatDependencyError
5
5
  from .models import WechatArticle, WechatConfig
6
+ from .media.models import VideoDownload, VideoDownloadOptions, WechatVideo
6
7
 
7
8
  __all__ = [
8
9
  "AsyncWechatClient",
9
10
  "WechatArticle",
10
11
  "WechatConfig",
11
12
  "WechatDependencyError",
13
+ "WechatVideo",
14
+ "VideoDownload",
15
+ "VideoDownloadOptions",
12
16
  ]
@@ -1,11 +1,11 @@
1
1
  """WeChat article requests over wpr-http and optional local JavaScript."""
2
2
 
3
3
  import asyncio
4
+ import time
5
+ import uuid
4
6
  from dataclasses import replace
5
7
  from pathlib import Path
6
- import time
7
8
  from urllib.parse import urlsplit
8
- import uuid
9
9
 
10
10
  from .js_runtime.runtime import LocalJsRuntime
11
11
  from .models import WechatArticle, WechatConfig
@@ -74,6 +74,50 @@ class AsyncWechatClient:
74
74
  report=report,
75
75
  )
76
76
 
77
+ async def download_videos(self, article, *, output_dir, options=None):
78
+ """Resolve and download videos from an already retrieved article.
79
+
80
+ Reuses this client's HTTP session/proxy. Returns one result per video;
81
+ cancellation and extraction/resolution failures propagate to the caller.
82
+ No browser Page is created and no completed MP4 is overwritten.
83
+ """
84
+ if not self._opened:
85
+ raise RuntimeError("Use AsyncWechatClient inside an async with block")
86
+ if not isinstance(article, WechatArticle) or not article.ok or not article.html:
87
+ raise ValueError("download_videos requires a successful WechatArticle")
88
+ from .media.downloader import download_one
89
+ from .media.extractor import extract
90
+ from .media.models import VideoDownloadOptions
91
+ from .media.tencent import resolve
92
+
93
+ options = options or VideoDownloadOptions()
94
+ if not isinstance(options, VideoDownloadOptions):
95
+ raise TypeError("options must be VideoDownloadOptions")
96
+ async with self._lock:
97
+ if not self._opened:
98
+ raise RuntimeError("AsyncWechatClient is closed")
99
+
100
+ async def run():
101
+ videos, embeds = await extract(self._runtime, article, options.quality)
102
+ for embed in embeds:
103
+ videos.append(
104
+ await resolve(
105
+ self._transport.client,
106
+ self._runtime,
107
+ embed,
108
+ article.url,
109
+ options.quality,
110
+ )
111
+ )
112
+ return [
113
+ await download_one(
114
+ self._transport.client, video, output_dir, options
115
+ )
116
+ for video in videos
117
+ ]
118
+
119
+ return await asyncio.wait_for(run(), options.total_timeout)
120
+
77
121
  async def close(self):
78
122
  async with self._lock:
79
123
  if self._opened:
@@ -0,0 +1,77 @@
1
+ {
2
+ "source": "local blank page only; no target SDK, video URLs or signatures",
3
+ "navigator": {
4
+ "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:155.0) Gecko/20100101 Firefox/155.0",
5
+ "platform": "Win32",
6
+ "language": "en-US",
7
+ "languages": [
8
+ "en-US",
9
+ "en"
10
+ ],
11
+ "webdriver": false,
12
+ "vendor": "",
13
+ "appVersion": "5.0 (Windows)",
14
+ "hardwareConcurrency": 32,
15
+ "mimeTypes": [
16
+ {
17
+ "type": "application/pdf",
18
+ "suffixes": "pdf",
19
+ "description": "Portable Document Format"
20
+ },
21
+ {
22
+ "type": "text/pdf",
23
+ "suffixes": "pdf",
24
+ "description": "Portable Document Format"
25
+ }
26
+ ],
27
+ "plugins": [
28
+ {
29
+ "name": "PDF Viewer",
30
+ "filename": "internal-pdf-viewer",
31
+ "description": "Portable Document Format"
32
+ },
33
+ {
34
+ "name": "Chrome PDF Viewer",
35
+ "filename": "internal-pdf-viewer",
36
+ "description": "Portable Document Format"
37
+ },
38
+ {
39
+ "name": "Chromium PDF Viewer",
40
+ "filename": "internal-pdf-viewer",
41
+ "description": "Portable Document Format"
42
+ },
43
+ {
44
+ "name": "Microsoft Edge PDF Viewer",
45
+ "filename": "internal-pdf-viewer",
46
+ "description": "Portable Document Format"
47
+ },
48
+ {
49
+ "name": "WebKit built-in PDF",
50
+ "filename": "internal-pdf-viewer",
51
+ "description": "Portable Document Format"
52
+ }
53
+ ]
54
+ },
55
+ "window": {
56
+ "outerWidth": 1366,
57
+ "outerHeight": 768,
58
+ "innerWidth": 1366,
59
+ "innerHeight": 683,
60
+ "devicePixelRatio": 1
61
+ },
62
+ "screen": {
63
+ "width": 1366,
64
+ "height": 768,
65
+ "colorDepth": 24
66
+ },
67
+ "canPlayType": {
68
+ "video/mp4; codecs=\"avc1.42E01E\"": "probably",
69
+ "video/mp4; codecs=\"avc1.42E01E, mp4a.40.2\"": "probably",
70
+ "video/mp4;codecs=\"hvc1.1.6.L93.B0\"": "probably",
71
+ "video/mp4;codecs=\"hvc1.2.4.L120.90\"": "probably",
72
+ "video/webm; codecs=\"vp9\"": "probably",
73
+ "application/vnd.apple.mpegurl": "",
74
+ "video/mp4": "maybe",
75
+ "audio/mp4": "maybe"
76
+ }
77
+ }
@@ -1,16 +1,15 @@
1
1
  {
2
- "name": "微信公众号",
2
+ "name": "environment",
3
3
  "lockfileVersion": 3,
4
4
  "requires": true,
5
5
  "packages": {
6
6
  "": {
7
7
  "dependencies": {
8
8
  "@napi-rs/canvas": "^1.0.11",
9
+ "acorn": "^8.19.0",
9
10
  "cssom": "^0.5.0",
11
+ "entities": "^8.1.0",
10
12
  "htmlparser2": "^12.0.0"
11
- },
12
- "devDependencies": {
13
- "acorn": "^8.19.0"
14
13
  }
15
14
  },
16
15
  "node_modules/@napi-rs/canvas": {
@@ -281,7 +280,6 @@
281
280
  "version": "8.19.0",
282
281
  "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.19.0.tgz",
283
282
  "integrity": "sha512-oJlA3XiRm7Cyk6qFD2Jn8ak9B7jSy0qy00ADO3+8dpT0LSjFihQYv4C02LFCSYJV3Q37xYwwRy5m+IpIiUzqWw==",
284
- "dev": true,
285
283
  "license": "MIT",
286
284
  "bin": {
287
285
  "acorn": "bin/acorn"
@@ -2,9 +2,8 @@
2
2
  "dependencies": {
3
3
  "@napi-rs/canvas": "^1.0.11",
4
4
  "cssom": "^0.5.0",
5
- "htmlparser2": "^12.0.0"
6
- },
7
- "devDependencies": {
8
- "acorn": "^8.19.0"
5
+ "htmlparser2": "^12.0.0",
6
+ "acorn": "^8.19.0",
7
+ "entities": "^8.1.0"
9
8
  }
10
9
  }
@@ -0,0 +1,98 @@
1
+ // Official unmodified player SDK, with a small measured Node host.
2
+ const fs=require('fs'),path=require('path'),vm=require('vm');
3
+ const {performance}=require('perf_hooks');
4
+ const {webcrypto}=require('crypto');
5
+ const ROOT=__dirname;
6
+ async function run(input){
7
+ const timerHandles=new Set();
8
+ const timerHost={setTimeout(fn,ms,...args){const id=setTimeout(fn,ms,...args);timerHandles.add(id);return id},
9
+ clearTimeout(id){clearTimeout(id);timerHandles.delete(id)},
10
+ setInterval(fn,ms,...args){const id=setInterval(fn,ms,...args);timerHandles.add(id);return id},
11
+ clearInterval(id){clearInterval(id);timerHandles.delete(id)}};
12
+ try{
13
+ const facts=JSON.parse(fs.readFileSync(path.join(ROOT,'assets/tencent-video-host.json'),'utf8'));
14
+ let captureRequest;
15
+ const requestReady=new Promise(resolve=>{captureRequest=resolve});
16
+ const context=vm.createContext({require,process,console,URL,URLSearchParams,TextEncoder,TextDecoder,Event,EventTarget,
17
+ __timers:timerHost,__facts:facts,__input:input,__captureRequest:captureRequest,
18
+ __performance:performance,__crypto:webcrypto});
19
+ const helpers=vm.runInContext(`(()=>{
20
+ const names=new WeakMap(),original=Function.prototype.toString;
21
+ Function.prototype.toString=function toString(){return names.get(this)||original.call(this)};
22
+ return {rtwatch:value=>value,rt_log:()=>{},fun_to_native:fn=>{names.set(fn,'function '+fn.name+'() { [native code] }');return fn}};
23
+ })()`,context);
24
+ context.__helpers=helpers;
25
+ vm.runInContext(`(()=>{
26
+ const {rtwatch,rt_log,fun_to_native}=__helpers;
27
+ const facts=__facts,input=__input,timers=__timers;
28
+ const captureRequest=__captureRequest;delete globalThis.__captureRequest;
29
+ const winEvents=new EventTarget(),docEvents=new EventTarget();
30
+ class XMLHttpRequest extends EventTarget {
31
+ constructor(){super();this.readyState=0;this.status=0;this.response=null;this.responseText='';this.headers={};}
32
+ open(method,url,async=true){this.method=method;this.url=new URL(url,input.playerUrl).href;this.async=async;this.readyState=1;}
33
+ setRequestHeader(name,value){this.headers[name]=value;}
34
+ send(body){
35
+ if(typeof body==='string'&&!Object.keys(this.headers).some(k=>k.toLowerCase()==='content-type'))this.headers['Content-Type']='text/plain;charset=UTF-8';
36
+ rt_log('XMLHttpRequest.send',{method:this.method,url:this.url,headers:this.headers,body});
37
+ captureRequest({method:this.method,url:this.url,headers:{...this.headers},body,withCredentials:this.withCredentials});}
38
+ abort(){this.readyState=0;this.dispatchEvent(new Event('abort'));if(typeof this.onabort==='function')this.onabort(new Event('abort'));}
39
+ }
40
+ class HTMLVideoElement extends EventTarget {
41
+ canPlayType(type){rt_log('video.canPlayType',type);
42
+ if(!Object.hasOwn(facts.canPlayType,type))throw Error('Unmeasured media type: '+type);
43
+ return facts.canPlayType[type];}
44
+ }
45
+ const document=rtwatch({
46
+ addEventListener:function addEventListener(...args){rt_log('document.addEventListener',args);return docEvents.addEventListener(...args)},
47
+ removeEventListener:function removeEventListener(...args){return docEvents.removeEventListener(...args)},
48
+ dispatchEvent:function dispatchEvent(...args){return docEvents.dispatchEvent(...args)},
49
+ createElement:function createElement(tag){rt_log('document.createElement',tag);if(tag==='video')return new HTMLVideoElement();throw Error('Unimplemented element: '+tag)}
50
+ },'video.document');
51
+ const navigator=rtwatch({...facts.navigator},'video.navigator');
52
+ const pageUrl=new URL(input.playerUrl);
53
+ const location=rtwatch({get href(){return pageUrl.href},set href(value){pageUrl.href=value},
54
+ get origin(){return pageUrl.origin},get host(){return pageUrl.host},get hostname(){return pageUrl.hostname},
55
+ get protocol(){return pageUrl.protocol},get pathname(){return pageUrl.pathname},get search(){return pageUrl.search},
56
+ get hash(){return pageUrl.hash},get port(){return pageUrl.port},toString(){return pageUrl.href}},'video.location');
57
+ const screen=rtwatch({...facts.screen},'video.screen');
58
+ const window=rtwatch({...facts.window,document,navigator,location,screen,XMLHttpRequest,
59
+ addEventListener:function addEventListener(...args){rt_log('window.addEventListener',args);return winEvents.addEventListener(...args)},
60
+ removeEventListener:function removeEventListener(...args){return winEvents.removeEventListener(...args)},
61
+ dispatchEvent:function dispatchEvent(...args){return winEvents.dispatchEvent(...args)}
62
+ },'video.window');
63
+ for(const object of [window,document])for(const key of Object.keys(object))if(typeof object[key]==='function')fun_to_native(object[key]);
64
+ Object.assign(globalThis,{window,self:window,document,navigator,location,screen,
65
+ performance:__performance,crypto:__crypto,HTMLVideoElement,HTMLMediaElement:HTMLVideoElement,XMLHttpRequest,
66
+ setTimeout:timers.setTimeout,clearTimeout:timers.clearTimeout,setInterval:timers.setInterval,clearInterval:timers.clearInterval});
67
+ delete globalThis.require;delete globalThis.process;delete globalThis.__helpers;delete globalThis.__facts;delete globalThis.__input;
68
+ })()`,context,{filename:'tencent-video-host.js'});
69
+ // 目标js:current official SDK is evaluated without rewriting its bytes.
70
+ const sdkSource=fs.readFileSync(input.sdkPath,'utf8');
71
+ vm.runInContext(sdkSource,context,{timeout:15000,filename:'official-superplayer.js'});
72
+ const sdk=context.SuperPlayerExport;
73
+ const player=context.window.SuperPlayer||sdk.default;
74
+ if(input.requestParams){
75
+ const Getinfo=player.prototype.selectGetinfoModule({type:'vod',enableTVK:true});
76
+ const config={...sdk.defaultSuperConfig,type:'vod',instanceId:input.instanceId,
77
+ businessConfig:{...sdk.defaultVodBusinessConfig},getinfoConfig:{}};
78
+ const common=new Map(Object.entries({...sdk.defaultVodBusinessConfig,appVer:'1.0.0.0',guid:input.guid,
79
+ flowid:input.flowid,topUrl:input.playerUrl,ua:facts.navigator.userAgent}));
80
+ const instance=new Getinfo(config,{getCommonKv:key=>common.get(key),pluginMsg:new sdk.EvtEmitter()});
81
+ const result=await instance.vodGetinfo.getReqParams(input.vid,{dtype:1,defn:'sd',otype:'ojson',...input.params});
82
+ if(result.error||!result.reqParams?.cKey||!result.reqParams?.tm)throw Error('SDK failed to generate current video request parameters');
83
+ if(input.buildRequest){
84
+ const pending=instance.proxyHttp.request(undefined,result.reqParams);
85
+ const request=await Promise.race([requestReady,pending.then(()=>{throw Error('SDK completed without a transport request')}),
86
+ new Promise((_,reject)=>timerHost.setTimeout(()=>reject(Error('No SDK transport request within 10 seconds')),10000))]);
87
+ instance.abort();return {loaded:true,generated:true,result,request};
88
+ }
89
+ return {loaded:true,generated:true,result};
90
+ }
91
+ throw Error('Tencent video runtime requires requestParams=true');
92
+ }finally{for(const id of timerHandles){clearTimeout(id);clearInterval(id)}}
93
+ }
94
+ if(require.main===module){
95
+ const input=JSON.parse(fs.readFileSync(0,'utf8'));
96
+ run(input).then(result=>console.log(JSON.stringify(result))).catch(error=>{console.log(JSON.stringify({loaded:false,error:{type:error.name,message:error.message,stack:error.stack}}));process.exitCode=1;});
97
+ }
98
+ module.exports={run};
@@ -0,0 +1,38 @@
1
+ // Parse only current HTTP HTML input; no browser, stored responses or JS execution.
2
+ const fs=require('fs'),acorn=require('acorn'),{parseDocument}=require('htmlparser2'),{decodeHTML}=require('entities');
3
+ const input=JSON.parse(fs.readFileSync(0,'utf8')),dom=parseDocument(input.html),scripts=[],embeds=[];
4
+ function walkDom(n){
5
+ if(n.name==='script')scripts.push((n.children||[]).map(x=>x.data||'').join(''));
6
+ if(n.name==='iframe'){
7
+ const a=n.attribs||{},src=decodeHTML(a['data-src']||a.src||'');
8
+ try{const u=new URL(src,input.url),vid=a['data-mpvid']||u.searchParams.get('vid');
9
+ if(vid && u.hostname==='v.qq.com')embeds.push({provider:'tencent_video',vid,playerUrl:u.href});}catch(_){}
10
+ }
11
+ for(const c of n.children||[])walkDom(c);
12
+ }
13
+ function literal(n){
14
+ if(n.type==='Literal')return n.value;
15
+ if(n.type==='ArrayExpression')return n.elements.map(literal);
16
+ if(n.type==='ObjectExpression')return Object.fromEntries(n.properties.map(p=>[p.key.name||p.key.value,literal(p.value)]));
17
+ if(n.type==='BinaryExpression'&&n.operator==='*')return literal(n.left)*literal(n.right);
18
+ if(n.type==='UnaryExpression'&&n.operator==='-')return -literal(n.argument);
19
+ throw Error('Nonconstant video config: '+n.type);
20
+ }
21
+ const videos=[],errors=[];
22
+ function walkAst(n){
23
+ if(!n||typeof n!=='object')return;
24
+ if(n.type==='Property'&&(n.key.name||n.key.value)==='video_page_infos'){
25
+ try{for(const video of literal(n.value)){
26
+ const variants=(video.mp_video_trans_info||[]).filter(x=>x.url).map(x=>({url:decodeHTML(x.url),
27
+ width:x.width,height:x.height,duration:x.vDuration||x.aDuration,formatId:x.format_id}));
28
+ if(variants.length){variants.sort((a,b)=>b.width*b.height-a.width*a.height);videos.push({provider:'wechat_video',vid:video.video_id,...variants[0],variants});}
29
+ }}catch(e){errors.push(e.message);}
30
+ }
31
+ for(const [k,v] of Object.entries(n))if(k!=='start'&&k!=='end'){
32
+ if(Array.isArray(v))v.forEach(walkAst);else if(v&&typeof v==='object')walkAst(v);
33
+ }
34
+ }
35
+ walkDom(dom);
36
+ for(const script of scripts){if(!script.includes('video_page_infos'))continue;
37
+ try{walkAst(acorn.parse(script,{ecmaVersion:'latest',allowReturnOutsideFunction:true}));}catch(e){errors.push(e.message);}}
38
+ console.log(JSON.stringify({mode:'node-current-http-html-constant-extraction',embeds,videos,errors}));
@@ -217,15 +217,15 @@
217
217
  "source": "package-lock.json",
218
218
  "path": "js_runtime/environment/package-lock.json",
219
219
  "source_sha256": "a03644d140d95c2e68dfbefa453faaffd799ef549ba97e234ad075154a7b78af",
220
- "sha256": "a03644d140d95c2e68dfbefa453faaffd799ef549ba97e234ad075154a7b78af",
221
- "adapted": false
220
+ "sha256": "3ee140877c4eed2f5cf99c100d6da8ad220a6088e5446429a2ac486583b8396b",
221
+ "adapted": true
222
222
  },
223
223
  {
224
224
  "source": "package.json",
225
225
  "path": "js_runtime/environment/package.json",
226
226
  "source_sha256": "bc59a58d971152d8a7192c18b750c5c8490f562a879ee2b81cd74794bcbac706",
227
- "sha256": "bc59a58d971152d8a7192c18b750c5c8490f562a879ee2b81cd74794bcbac706",
228
- "adapted": false
227
+ "sha256": "b9a6d8dbefa455cdead9cfd6374e0650864dd764813224d948015242edc007b3",
228
+ "adapted": true
229
229
  },
230
230
  {
231
231
  "source": "round_diagnostics.py",
@@ -254,6 +254,30 @@
254
254
  "source_sha256": "da27380d3fd3936d5941f9fe54d67447e2dddd78fc40bad1adb25a6320df0a1a",
255
255
  "sha256": "d6642d125466591f4c1b6a73db8817ceb4270215d88df2fa3f01562df48e58e8",
256
256
  "adapted": true
257
+ },
258
+ {
259
+ "source": "node_video_extract.js",
260
+ "path": "js_runtime/environment/video_extract.js",
261
+ "sha256": "b65dd12829e039b8e9277372addd299aa25b9e5c4375bb17870777633b488bf8",
262
+ "adapted": true
263
+ },
264
+ {
265
+ "source": "runtime/tencent_video.code.js",
266
+ "path": "js_runtime/environment/tencent_video.js",
267
+ "sha256": "dd400b64da20216a40d7eac90051c25bb9016ebca1b0cd600b0d49a3ad3262c9",
268
+ "adapted": true
269
+ },
270
+ {
271
+ "source": "assets/tencent-video-host.json",
272
+ "path": "js_runtime/environment/assets/tencent-video-host.json",
273
+ "sha256": "4d858caefb8dc953b534bf68a529a106059cc8ecbf49c5270221b5a0f2f1c242",
274
+ "adapted": false
275
+ },
276
+ {
277
+ "source": "download_article_video.py (MP4 inspection only)",
278
+ "path": "media/mp4.py",
279
+ "sha256": "de04250e74893514035680a894f44811be62794693633e4bacae9370dc1a154f",
280
+ "adapted": true
257
281
  }
258
282
  ]
259
283
  }
@@ -75,7 +75,7 @@ class LocalJsRuntime:
75
75
  [
76
76
  self.node,
77
77
  "-e",
78
- "for(const m of ['@napi-rs/canvas','cssom','htmlparser2'])require(m);process.stdout.write('ok')",
78
+ "for(const m of ['@napi-rs/canvas','cssom','htmlparser2','acorn','entities'])require(m);process.stdout.write('ok')",
79
79
  ],
80
80
  cwd=self.root,
81
81
  env=environment,
@@ -0,0 +1,5 @@
1
+ """Article video extraction, resolution and validated HTTP downloads."""
2
+
3
+ from .models import VideoDownload, VideoDownloadOptions, WechatVideo
4
+
5
+ __all__ = ["VideoDownload", "VideoDownloadOptions", "WechatVideo"]