htmlplayer 0.1.0__tar.gz → 0.1.2__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.
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/PKG-INFO +5 -13
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/README.md +4 -12
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer/__init__.py +1 -1
- htmlplayer-0.1.2/htmlplayer/core.py +140 -0
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer/examples/advanced_example.py +3 -10
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer/examples/simple_example.py +3 -14
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer.egg-info/PKG-INFO +5 -13
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/pyproject.toml +1 -1
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/setup.py +1 -1
- htmlplayer-0.1.0/htmlplayer/core.py +0 -121
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/MANIFEST.in +0 -0
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer/examples/__init__.py +0 -0
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer.egg-info/SOURCES.txt +0 -0
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer.egg-info/dependency_links.txt +0 -0
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/htmlplayer.egg-info/top_level.txt +0 -0
- {htmlplayer-0.1.0 → htmlplayer-0.1.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: htmlplayer
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: 一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频
|
|
5
5
|
Home-page: https://github.com/yourusername/htmlplayer
|
|
6
6
|
Author: lenvy1
|
|
@@ -49,12 +49,6 @@ play_video('https://example.com/video.mp4')
|
|
|
49
49
|
play_video('https://example.com/video.mp4', width=1280, height=720)
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
### 指定视频宽高比
|
|
53
|
-
|
|
54
|
-
```python
|
|
55
|
-
play_video('https://example.com/video.mp4', video_aspect_ratio=21/9)
|
|
56
|
-
```
|
|
57
|
-
|
|
58
52
|
### 仅使用Edge浏览器
|
|
59
53
|
|
|
60
54
|
```python
|
|
@@ -73,7 +67,7 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
73
67
|
|
|
74
68
|
## API 文档
|
|
75
69
|
|
|
76
|
-
### play_video(url, width=None, height=None,
|
|
70
|
+
### play_video(url, width=None, height=None, use_edge=True, use_browser_fallback=True)
|
|
77
71
|
|
|
78
72
|
使用Edge浏览器或系统默认浏览器播放视频。
|
|
79
73
|
|
|
@@ -81,18 +75,17 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
81
75
|
- `url` (str): 视频URL地址
|
|
82
76
|
- `width` (int, optional): 窗口宽度
|
|
83
77
|
- `height` (int, optional): 窗口高度
|
|
84
|
-
- `video_aspect_ratio` (float): 视频宽高比,默认16:9
|
|
85
78
|
- `use_edge` (bool): 是否优先使用Edge浏览器,默认True
|
|
86
79
|
- `use_browser_fallback` (bool): Edge不可用时是否使用默认浏览器,默认True
|
|
87
80
|
|
|
88
81
|
**返回:**
|
|
89
82
|
- `bool`: 播放是否成功启动
|
|
90
83
|
|
|
91
|
-
### play_with_edge(url, width=None, height=None
|
|
84
|
+
### play_with_edge(url, width=None, height=None)
|
|
92
85
|
|
|
93
86
|
仅使用Edge浏览器播放视频。
|
|
94
87
|
|
|
95
|
-
### play_with_browser(url, width=None, height=None
|
|
88
|
+
### play_with_browser(url, width=None, height=None)
|
|
96
89
|
|
|
97
90
|
使用系统默认浏览器播放视频。
|
|
98
91
|
|
|
@@ -100,7 +93,7 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
100
93
|
|
|
101
94
|
查找Microsoft Edge浏览器的安装路径。
|
|
102
95
|
|
|
103
|
-
### calculate_window_size(
|
|
96
|
+
### calculate_window_size(width=None, height=None, scale=0.5)
|
|
104
97
|
|
|
105
98
|
计算合适的窗口大小。
|
|
106
99
|
|
|
@@ -129,4 +122,3 @@ python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(html
|
|
|
129
122
|
## 许可证
|
|
130
123
|
|
|
131
124
|
MIT License
|
|
132
|
-
|
|
@@ -25,12 +25,6 @@ play_video('https://example.com/video.mp4')
|
|
|
25
25
|
play_video('https://example.com/video.mp4', width=1280, height=720)
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
### 指定视频宽高比
|
|
29
|
-
|
|
30
|
-
```python
|
|
31
|
-
play_video('https://example.com/video.mp4', video_aspect_ratio=21/9)
|
|
32
|
-
```
|
|
33
|
-
|
|
34
28
|
### 仅使用Edge浏览器
|
|
35
29
|
|
|
36
30
|
```python
|
|
@@ -49,7 +43,7 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
49
43
|
|
|
50
44
|
## API 文档
|
|
51
45
|
|
|
52
|
-
### play_video(url, width=None, height=None,
|
|
46
|
+
### play_video(url, width=None, height=None, use_edge=True, use_browser_fallback=True)
|
|
53
47
|
|
|
54
48
|
使用Edge浏览器或系统默认浏览器播放视频。
|
|
55
49
|
|
|
@@ -57,18 +51,17 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
57
51
|
- `url` (str): 视频URL地址
|
|
58
52
|
- `width` (int, optional): 窗口宽度
|
|
59
53
|
- `height` (int, optional): 窗口高度
|
|
60
|
-
- `video_aspect_ratio` (float): 视频宽高比,默认16:9
|
|
61
54
|
- `use_edge` (bool): 是否优先使用Edge浏览器,默认True
|
|
62
55
|
- `use_browser_fallback` (bool): Edge不可用时是否使用默认浏览器,默认True
|
|
63
56
|
|
|
64
57
|
**返回:**
|
|
65
58
|
- `bool`: 播放是否成功启动
|
|
66
59
|
|
|
67
|
-
### play_with_edge(url, width=None, height=None
|
|
60
|
+
### play_with_edge(url, width=None, height=None)
|
|
68
61
|
|
|
69
62
|
仅使用Edge浏览器播放视频。
|
|
70
63
|
|
|
71
|
-
### play_with_browser(url, width=None, height=None
|
|
64
|
+
### play_with_browser(url, width=None, height=None)
|
|
72
65
|
|
|
73
66
|
使用系统默认浏览器播放视频。
|
|
74
67
|
|
|
@@ -76,7 +69,7 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
76
69
|
|
|
77
70
|
查找Microsoft Edge浏览器的安装路径。
|
|
78
71
|
|
|
79
|
-
### calculate_window_size(
|
|
72
|
+
### calculate_window_size(width=None, height=None, scale=0.5)
|
|
80
73
|
|
|
81
74
|
计算合适的窗口大小。
|
|
82
75
|
|
|
@@ -105,4 +98,3 @@ python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(html
|
|
|
105
98
|
## 许可证
|
|
106
99
|
|
|
107
100
|
MIT License
|
|
108
|
-
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
|
|
2
|
+
import subprocess
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def find_edge_browser():
|
|
7
|
+
edge_paths = [
|
|
8
|
+
r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe',
|
|
9
|
+
r'C:\Program Files\Microsoft\Edge\Application\msedge.exe',
|
|
10
|
+
os.path.expanduser(r'~\AppData\Local\Microsoft\Edge\Application\msedge.exe'),
|
|
11
|
+
]
|
|
12
|
+
for path in edge_paths:
|
|
13
|
+
if os.path.exists(path):
|
|
14
|
+
return path
|
|
15
|
+
return None
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def calculate_window_size(width, height, scale=0.5):
|
|
19
|
+
"""
|
|
20
|
+
根据输入的宽高计算合适的窗口大小(严格等比缩放)
|
|
21
|
+
|
|
22
|
+
参数:
|
|
23
|
+
width (int/float): 目标宽度(像素)
|
|
24
|
+
height (int/float): 目标高度(像素)
|
|
25
|
+
scale (float): 窗口相对于输入尺寸的缩放比例,默认0.5(即50%尺寸)
|
|
26
|
+
|
|
27
|
+
返回:
|
|
28
|
+
tuple: 包含窗口宽度和高度的元组 (final_width, final_height),均为真实的浮点数
|
|
29
|
+
"""
|
|
30
|
+
# 1. 跨平台自动检测屏幕分辨率
|
|
31
|
+
if width is None or height is None:
|
|
32
|
+
try:
|
|
33
|
+
import tkinter as tk
|
|
34
|
+
root = tk.Tk()
|
|
35
|
+
root.withdraw() # 隐藏主窗口,避免闪烁
|
|
36
|
+
width = root.winfo_screenwidth()
|
|
37
|
+
height = root.winfo_screenheight()
|
|
38
|
+
root.destroy()
|
|
39
|
+
except Exception as e:
|
|
40
|
+
raise RuntimeError(f"无法自动获取屏幕分辨率,请手动传入 screen_width 和 screen_height。错误信息: {e}")
|
|
41
|
+
# 2. 根据传入的宽高直接计算目标宽高比
|
|
42
|
+
target_ratio = width / height
|
|
43
|
+
|
|
44
|
+
# 3. 针对竖屏视频的视觉体验优化
|
|
45
|
+
# 竖屏视频(如 9:16,比例约为 0.56)若按默认比例缩放会导致画面过小,因此放大显示
|
|
46
|
+
if target_ratio <= 0.6:
|
|
47
|
+
scale = 0.9
|
|
48
|
+
|
|
49
|
+
# 4. 计算允许的最大边界
|
|
50
|
+
max_width = width * scale
|
|
51
|
+
max_height = height * scale
|
|
52
|
+
|
|
53
|
+
# 5. 核心等比缩放计算(取最小限制比例,确保不超出屏幕且保持绝对比例)
|
|
54
|
+
if max_width / target_ratio <= max_height:
|
|
55
|
+
# 宽度先触达边界,以宽度为基准计算高度
|
|
56
|
+
final_width = max_width
|
|
57
|
+
final_height = max_width / target_ratio
|
|
58
|
+
else:
|
|
59
|
+
# 高度先触达边界,以高度为基准计算宽度
|
|
60
|
+
final_height = max_height
|
|
61
|
+
final_width = max_height * target_ratio
|
|
62
|
+
|
|
63
|
+
return final_width, final_height
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def play_video(url, width=None, height=None,
|
|
67
|
+
use_edge=True, use_browser_fallback=True):
|
|
68
|
+
"""
|
|
69
|
+
使用Edge浏览器或系统默认浏览器播放视频
|
|
70
|
+
|
|
71
|
+
参数:
|
|
72
|
+
url (str): 视频URL地址
|
|
73
|
+
width (int, optional): 窗口宽度
|
|
74
|
+
height (int, optional): 窗口高度
|
|
75
|
+
use_edge (bool): 是否优先使用Edge浏览器,默认True
|
|
76
|
+
use_browser_fallback (bool): Edge不可用时是否使用默认浏览器,默认True
|
|
77
|
+
|
|
78
|
+
返回:
|
|
79
|
+
bool: 播放是否成功启动
|
|
80
|
+
"""
|
|
81
|
+
if not url or not isinstance(url, str):
|
|
82
|
+
raise ValueError("url参数无效,必须提供有效的URL字符串")
|
|
83
|
+
|
|
84
|
+
url = url.strip()
|
|
85
|
+
if not url.startswith('http'):
|
|
86
|
+
raise ValueError("url必须以http或https开头")
|
|
87
|
+
|
|
88
|
+
final_width, final_height = calculate_window_size(width=width, height=height)
|
|
89
|
+
|
|
90
|
+
edge_path = find_edge_browser() if use_edge else None
|
|
91
|
+
|
|
92
|
+
if edge_path:
|
|
93
|
+
subprocess.Popen([
|
|
94
|
+
edge_path,
|
|
95
|
+
'--app=' + url,
|
|
96
|
+
'--new-window',
|
|
97
|
+
f'--window-size={int(final_width)},{int(final_height)}',
|
|
98
|
+
'--disable-extensions',
|
|
99
|
+
'--disable-plugins',
|
|
100
|
+
'--inprivate'
|
|
101
|
+
])
|
|
102
|
+
return True
|
|
103
|
+
elif use_browser_fallback:
|
|
104
|
+
import webbrowser
|
|
105
|
+
webbrowser.open(url)
|
|
106
|
+
return True
|
|
107
|
+
else:
|
|
108
|
+
return False
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def play_with_edge(url, width=None, height=None):
|
|
112
|
+
"""
|
|
113
|
+
仅使用Edge浏览器播放视频
|
|
114
|
+
|
|
115
|
+
参数:
|
|
116
|
+
url (str): 视频URL地址
|
|
117
|
+
width (int, optional): 窗口宽度
|
|
118
|
+
height (int, optional): 窗口高度
|
|
119
|
+
|
|
120
|
+
返回:
|
|
121
|
+
bool: 播放是否成功启动
|
|
122
|
+
"""
|
|
123
|
+
return play_video(url, width, height, use_edge=True, use_browser_fallback=False)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def play_with_browser(url, width=None, height=None):
|
|
127
|
+
"""
|
|
128
|
+
使用系统默认浏览器播放视频
|
|
129
|
+
|
|
130
|
+
参数:
|
|
131
|
+
url (str): 视频URL地址
|
|
132
|
+
width (int, optional): 窗口宽度
|
|
133
|
+
height (int, optional): 窗口高度
|
|
134
|
+
|
|
135
|
+
返回:
|
|
136
|
+
bool: 播放是否成功启动
|
|
137
|
+
"""
|
|
138
|
+
return play_video(url, width, height,
|
|
139
|
+
use_edge=False, use_browser_fallback=True)
|
|
140
|
+
|
|
@@ -23,14 +23,9 @@ def demo_window_calculation():
|
|
|
23
23
|
print("\n窗口大小计算演示:")
|
|
24
24
|
print("-" * 30)
|
|
25
25
|
|
|
26
|
-
#
|
|
26
|
+
# 获取屏幕尺寸并计算默认窗口大小
|
|
27
27
|
width, height = calculate_window_size()
|
|
28
|
-
print(f"默认窗口大小: {width}x{height}")
|
|
29
|
-
|
|
30
|
-
# 不同宽高比
|
|
31
|
-
for aspect_ratio in [16/9, 21/9, 4/3, 9/16]:
|
|
32
|
-
w, h = calculate_window_size(video_aspect_ratio=aspect_ratio)
|
|
33
|
-
print(f"宽高比 {aspect_ratio:.2f}: {w}x{h}")
|
|
28
|
+
print(f"默认窗口大小: {int(width)}x{int(height)}")
|
|
34
29
|
|
|
35
30
|
|
|
36
31
|
def demo_different_configs():
|
|
@@ -38,14 +33,13 @@ def demo_different_configs():
|
|
|
38
33
|
print("\n不同配置演示:")
|
|
39
34
|
print("-" * 30)
|
|
40
35
|
|
|
41
|
-
# 这里只是示例,实际运行时可以取消注释
|
|
42
36
|
print("1. 仅Edge浏览器(无回退):")
|
|
43
37
|
print(" play_video(url, use_edge=True, use_browser_fallback=False)")
|
|
44
38
|
|
|
45
39
|
print("\n2. 强制使用系统浏览器:")
|
|
46
40
|
print(" play_video(url, use_edge=False, use_browser_fallback=True)")
|
|
47
41
|
|
|
48
|
-
print("\n3.
|
|
42
|
+
print("\n3. 自定义窗口大小:")
|
|
49
43
|
print(" play_video(url, width=1920, height=1080)")
|
|
50
44
|
|
|
51
45
|
|
|
@@ -63,4 +57,3 @@ def main():
|
|
|
63
57
|
|
|
64
58
|
if __name__ == '__main__':
|
|
65
59
|
main()
|
|
66
|
-
|
|
@@ -10,26 +10,18 @@ def main():
|
|
|
10
10
|
print("HTMLPlayer 视频播放库 - 简单示例")
|
|
11
11
|
print("=" * 50)
|
|
12
12
|
|
|
13
|
-
# 示例 1: 基础用法
|
|
14
13
|
print("\n1. 基础用法:")
|
|
15
14
|
print(" from htmlplayer import play_video")
|
|
16
15
|
print(" play_video('https://example.com/video.m3u8')")
|
|
17
16
|
|
|
18
|
-
# 示例 2: 指定窗口大小
|
|
19
17
|
print("\n2. 指定窗口大小:")
|
|
20
18
|
print(" play_video('https://example.com/video.m3u8', width=1280, height=720)")
|
|
21
19
|
|
|
22
|
-
|
|
23
|
-
print("\n3. 指定视频宽高比:")
|
|
24
|
-
print(" play_video('https://example.com/video.m3u8', video_aspect_ratio=21/9)")
|
|
25
|
-
|
|
26
|
-
# 示例 4: 仅使用Edge浏览器
|
|
27
|
-
print("\n4. 仅使用Edge浏览器:")
|
|
20
|
+
print("\n3. 仅使用Edge浏览器:")
|
|
28
21
|
print(" from htmlplayer import play_with_edge")
|
|
29
22
|
print(" play_with_edge('https://example.com/video.m3u8')")
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
print("\n5. 使用系统默认浏览器:")
|
|
24
|
+
print("\n4. 使用系统默认浏览器:")
|
|
33
25
|
print(" from htmlplayer import play_with_browser")
|
|
34
26
|
print(" play_with_browser('https://example.com/video.m3u8')")
|
|
35
27
|
|
|
@@ -39,10 +31,7 @@ def main():
|
|
|
39
31
|
|
|
40
32
|
# 实际演示(取消注释以运行)
|
|
41
33
|
# print("\n正在播放示例视频...")
|
|
42
|
-
# play_video(
|
|
43
|
-
# 'https://jx.xmflv.com/?url=https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',
|
|
44
|
-
# video_aspect_ratio=16/9
|
|
45
|
-
# )
|
|
34
|
+
# play_video('https://jx.xmflv.com/?url=https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8')
|
|
46
35
|
|
|
47
36
|
|
|
48
37
|
if __name__ == '__main__':
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: htmlplayer
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: 一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频
|
|
5
5
|
Home-page: https://github.com/yourusername/htmlplayer
|
|
6
6
|
Author: lenvy1
|
|
@@ -49,12 +49,6 @@ play_video('https://example.com/video.mp4')
|
|
|
49
49
|
play_video('https://example.com/video.mp4', width=1280, height=720)
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
### 指定视频宽高比
|
|
53
|
-
|
|
54
|
-
```python
|
|
55
|
-
play_video('https://example.com/video.mp4', video_aspect_ratio=21/9)
|
|
56
|
-
```
|
|
57
|
-
|
|
58
52
|
### 仅使用Edge浏览器
|
|
59
53
|
|
|
60
54
|
```python
|
|
@@ -73,7 +67,7 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
73
67
|
|
|
74
68
|
## API 文档
|
|
75
69
|
|
|
76
|
-
### play_video(url, width=None, height=None,
|
|
70
|
+
### play_video(url, width=None, height=None, use_edge=True, use_browser_fallback=True)
|
|
77
71
|
|
|
78
72
|
使用Edge浏览器或系统默认浏览器播放视频。
|
|
79
73
|
|
|
@@ -81,18 +75,17 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
81
75
|
- `url` (str): 视频URL地址
|
|
82
76
|
- `width` (int, optional): 窗口宽度
|
|
83
77
|
- `height` (int, optional): 窗口高度
|
|
84
|
-
- `video_aspect_ratio` (float): 视频宽高比,默认16:9
|
|
85
78
|
- `use_edge` (bool): 是否优先使用Edge浏览器,默认True
|
|
86
79
|
- `use_browser_fallback` (bool): Edge不可用时是否使用默认浏览器,默认True
|
|
87
80
|
|
|
88
81
|
**返回:**
|
|
89
82
|
- `bool`: 播放是否成功启动
|
|
90
83
|
|
|
91
|
-
### play_with_edge(url, width=None, height=None
|
|
84
|
+
### play_with_edge(url, width=None, height=None)
|
|
92
85
|
|
|
93
86
|
仅使用Edge浏览器播放视频。
|
|
94
87
|
|
|
95
|
-
### play_with_browser(url, width=None, height=None
|
|
88
|
+
### play_with_browser(url, width=None, height=None)
|
|
96
89
|
|
|
97
90
|
使用系统默认浏览器播放视频。
|
|
98
91
|
|
|
@@ -100,7 +93,7 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
100
93
|
|
|
101
94
|
查找Microsoft Edge浏览器的安装路径。
|
|
102
95
|
|
|
103
|
-
### calculate_window_size(
|
|
96
|
+
### calculate_window_size(width=None, height=None, scale=0.5)
|
|
104
97
|
|
|
105
98
|
计算合适的窗口大小。
|
|
106
99
|
|
|
@@ -129,4 +122,3 @@ python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(html
|
|
|
129
122
|
## 许可证
|
|
130
123
|
|
|
131
124
|
MIT License
|
|
132
|
-
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import subprocess
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def find_edge_browser():
|
|
7
|
-
edge_paths = [
|
|
8
|
-
r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe',
|
|
9
|
-
r'C:\Program Files\Microsoft\Edge\Application\msedge.exe',
|
|
10
|
-
os.path.expanduser(r'~\AppData\Local\Microsoft\Edge\Application\msedge.exe'),
|
|
11
|
-
]
|
|
12
|
-
for path in edge_paths:
|
|
13
|
-
if os.path.exists(path):
|
|
14
|
-
return path
|
|
15
|
-
return None
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def calculate_window_size(screen_width=None, screen_height=None,
|
|
19
|
-
video_aspect_ratio=16/9, scale=0.5):
|
|
20
|
-
if screen_width is None or screen_height is None:
|
|
21
|
-
import ctypes
|
|
22
|
-
user32 = ctypes.windll.user32
|
|
23
|
-
screen_width = user32.GetSystemMetrics(0)
|
|
24
|
-
screen_height = user32.GetSystemMetrics(1)
|
|
25
|
-
|
|
26
|
-
if video_aspect_ratio <= 0.6:
|
|
27
|
-
scale = 0.9
|
|
28
|
-
|
|
29
|
-
max_width = screen_width * scale
|
|
30
|
-
max_height = screen_height * scale
|
|
31
|
-
|
|
32
|
-
width = max_width
|
|
33
|
-
height = width / video_aspect_ratio
|
|
34
|
-
|
|
35
|
-
if height > max_height:
|
|
36
|
-
height = max_height
|
|
37
|
-
width = height * video_aspect_ratio
|
|
38
|
-
|
|
39
|
-
return int(width), int(height)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
def play_video(url, width=None, height=None, video_aspect_ratio=16/9,
|
|
43
|
-
use_edge=True, use_browser_fallback=True):
|
|
44
|
-
"""
|
|
45
|
-
使用Edge浏览器或系统默认浏览器播放视频
|
|
46
|
-
|
|
47
|
-
参数:
|
|
48
|
-
url (str): 视频URL地址
|
|
49
|
-
width (int, optional): 窗口宽度
|
|
50
|
-
height (int, optional): 窗口高度
|
|
51
|
-
video_aspect_ratio (float): 视频宽高比,默认16:9
|
|
52
|
-
use_edge (bool): 是否优先使用Edge浏览器,默认True
|
|
53
|
-
use_browser_fallback (bool): Edge不可用时是否使用默认浏览器,默认True
|
|
54
|
-
|
|
55
|
-
返回:
|
|
56
|
-
bool: 播放是否成功启动
|
|
57
|
-
"""
|
|
58
|
-
if not url or not isinstance(url, str):
|
|
59
|
-
raise ValueError("url参数无效,必须提供有效的URL字符串")
|
|
60
|
-
|
|
61
|
-
url = url.strip()
|
|
62
|
-
if not url.startswith('http'):
|
|
63
|
-
raise ValueError("url必须以http或https开头")
|
|
64
|
-
|
|
65
|
-
if width is None or height is None:
|
|
66
|
-
width, height = calculate_window_size(video_aspect_ratio=video_aspect_ratio)
|
|
67
|
-
|
|
68
|
-
edge_path = find_edge_browser() if use_edge else None
|
|
69
|
-
|
|
70
|
-
if edge_path:
|
|
71
|
-
subprocess.Popen([
|
|
72
|
-
edge_path,
|
|
73
|
-
'--app=' + url,
|
|
74
|
-
'--new-window',
|
|
75
|
-
f'--window-size={width},{height}',
|
|
76
|
-
'--disable-extensions',
|
|
77
|
-
'--disable-plugins',
|
|
78
|
-
'--inprivate'
|
|
79
|
-
])
|
|
80
|
-
return True
|
|
81
|
-
elif use_browser_fallback:
|
|
82
|
-
import webbrowser
|
|
83
|
-
webbrowser.open(url)
|
|
84
|
-
return True
|
|
85
|
-
else:
|
|
86
|
-
return False
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
def play_with_edge(url, width=None, height=None, video_aspect_ratio=16/9):
|
|
90
|
-
"""
|
|
91
|
-
仅使用Edge浏览器播放视频
|
|
92
|
-
|
|
93
|
-
参数:
|
|
94
|
-
url (str): 视频URL地址
|
|
95
|
-
width (int, optional): 窗口宽度
|
|
96
|
-
height (int, optional): 窗口高度
|
|
97
|
-
video_aspect_ratio (float): 视频宽高比,默认16:9
|
|
98
|
-
|
|
99
|
-
返回:
|
|
100
|
-
bool: 播放是否成功启动
|
|
101
|
-
"""
|
|
102
|
-
return play_video(url, width, height, video_aspect_ratio,
|
|
103
|
-
use_edge=True, use_browser_fallback=False)
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
def play_with_browser(url, width=None, height=None, video_aspect_ratio=16/9):
|
|
107
|
-
"""
|
|
108
|
-
使用系统默认浏览器播放视频
|
|
109
|
-
|
|
110
|
-
参数:
|
|
111
|
-
url (str): 视频URL地址
|
|
112
|
-
width (int, optional): 窗口宽度
|
|
113
|
-
height (int, optional): 窗口高度
|
|
114
|
-
video_aspect_ratio (float): 视频宽高比,默认16:9
|
|
115
|
-
|
|
116
|
-
返回:
|
|
117
|
-
bool: 播放是否成功启动
|
|
118
|
-
"""
|
|
119
|
-
return play_video(url, width, height, video_aspect_ratio,
|
|
120
|
-
use_edge=False, use_browser_fallback=True)
|
|
121
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|