htmlplayer 0.1.2__tar.gz → 0.3.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.
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/PKG-INFO +19 -3
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/README.md +18 -2
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer/__init__.py +1 -1
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer/core.py +57 -40
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer/examples/advanced_example.py +24 -10
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer/examples/simple_example.py +7 -8
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer.egg-info/PKG-INFO +19 -3
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/pyproject.toml +1 -1
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/setup.py +1 -1
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/MANIFEST.in +0 -0
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer/examples/__init__.py +0 -0
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer.egg-info/SOURCES.txt +0 -0
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer.egg-info/dependency_links.txt +0 -0
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/htmlplayer.egg-info/top_level.txt +0 -0
- {htmlplayer-0.1.2 → htmlplayer-0.3.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: htmlplayer
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: 一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频
|
|
5
5
|
Home-page: https://github.com/yourusername/htmlplayer
|
|
6
6
|
Author: lenvy1
|
|
@@ -93,9 +93,25 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
93
93
|
|
|
94
94
|
查找Microsoft Edge浏览器的安装路径。
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
**返回:**
|
|
97
|
+
- `str` or `None`: Edge浏览器的安装路径,若未找到返回None
|
|
98
|
+
|
|
99
|
+
### calculate_window_size(width=None, height=None, scale=None)
|
|
100
|
+
|
|
101
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
102
|
+
|
|
103
|
+
**参数:**
|
|
104
|
+
- `width` (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
105
|
+
- `height` (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
106
|
+
- `scale` (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
107
|
+
|
|
108
|
+
**返回:**
|
|
109
|
+
- `tuple`: 包含窗口宽度和高度的元组 (final_width, final_height)
|
|
97
110
|
|
|
98
|
-
|
|
111
|
+
**自动缩放规则:**
|
|
112
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
113
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
114
|
+
- 严格保持原视频纵横比
|
|
99
115
|
|
|
100
116
|
## 系统要求
|
|
101
117
|
|
|
@@ -69,9 +69,25 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
69
69
|
|
|
70
70
|
查找Microsoft Edge浏览器的安装路径。
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
**返回:**
|
|
73
|
+
- `str` or `None`: Edge浏览器的安装路径,若未找到返回None
|
|
74
|
+
|
|
75
|
+
### calculate_window_size(width=None, height=None, scale=None)
|
|
76
|
+
|
|
77
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
78
|
+
|
|
79
|
+
**参数:**
|
|
80
|
+
- `width` (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
81
|
+
- `height` (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
82
|
+
- `scale` (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
83
|
+
|
|
84
|
+
**返回:**
|
|
85
|
+
- `tuple`: 包含窗口宽度和高度的元组 (final_width, final_height)
|
|
73
86
|
|
|
74
|
-
|
|
87
|
+
**自动缩放规则:**
|
|
88
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
89
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
90
|
+
- 严格保持原视频纵横比
|
|
75
91
|
|
|
76
92
|
## 系统要求
|
|
77
93
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import subprocess
|
|
3
3
|
import os
|
|
4
|
+
from pathlib import Path
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
def find_edge_browser():
|
|
@@ -15,50 +16,66 @@ def find_edge_browser():
|
|
|
15
16
|
return None
|
|
16
17
|
|
|
17
18
|
|
|
18
|
-
def calculate_window_size(width, height, scale=
|
|
19
|
+
def calculate_window_size(width=None, height=None, scale=None):
|
|
19
20
|
"""
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
22
|
+
|
|
23
|
+
规则:
|
|
24
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
25
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
26
|
+
- 严格保持原视频纵横比
|
|
27
|
+
|
|
22
28
|
参数:
|
|
23
|
-
width (int/float):
|
|
24
|
-
height (int/float):
|
|
25
|
-
scale (float):
|
|
26
|
-
|
|
29
|
+
width (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
30
|
+
height (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
31
|
+
scale (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
32
|
+
|
|
27
33
|
返回:
|
|
28
34
|
tuple: 包含窗口宽度和高度的元组 (final_width, final_height),均为真实的浮点数
|
|
29
35
|
"""
|
|
30
|
-
# 1.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
# 2.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
if
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
36
|
+
# 1. 检测屏幕尺寸(作为缩放参考基准)
|
|
37
|
+
try:
|
|
38
|
+
import tkinter as tk
|
|
39
|
+
root = tk.Tk()
|
|
40
|
+
root.withdraw()
|
|
41
|
+
screen_width = root.winfo_screenwidth()
|
|
42
|
+
screen_height = root.winfo_screenheight()
|
|
43
|
+
root.destroy()
|
|
44
|
+
except Exception as e:
|
|
45
|
+
raise RuntimeError(f"无法自动获取屏幕分辨率,请手动传入 width 和 height。错误信息: {e}")
|
|
46
|
+
|
|
47
|
+
# 2. 确定视频尺寸:用户传入则用用户的,否则用屏幕尺寸作为参考
|
|
48
|
+
video_width = width if width is not None else screen_width
|
|
49
|
+
video_height = height if height is not None else screen_height
|
|
50
|
+
|
|
51
|
+
# 3. 判断横屏/竖屏并确定自动缩放比例
|
|
52
|
+
if scale is None:
|
|
53
|
+
if video_width >= video_height:
|
|
54
|
+
# 横屏视频 → 50% 屏幕
|
|
55
|
+
scale = 0.5
|
|
56
|
+
else:
|
|
57
|
+
# 竖屏视频 → 90% 屏幕
|
|
58
|
+
scale = 0.9
|
|
59
|
+
|
|
60
|
+
# 4. 目标区域:屏幕 * scale
|
|
61
|
+
target_width = screen_width * scale
|
|
62
|
+
target_height = screen_height * scale
|
|
63
|
+
|
|
64
|
+
# 5. 在目标区域内严格按原视频纵横比缩放(取较小边做基准,确保不溢出)
|
|
65
|
+
video_ratio = video_width / video_height
|
|
66
|
+
target_ratio = target_width / target_height
|
|
67
|
+
|
|
68
|
+
if video_ratio >= target_ratio:
|
|
69
|
+
# 视频更宽 → 以宽度为基准
|
|
70
|
+
final_width = target_width
|
|
71
|
+
final_height = target_width / video_ratio
|
|
58
72
|
else:
|
|
59
|
-
#
|
|
60
|
-
final_height =
|
|
61
|
-
final_width =
|
|
73
|
+
# 视频更高 → 以高度为基准
|
|
74
|
+
final_height = target_height
|
|
75
|
+
final_width = target_height * video_ratio
|
|
76
|
+
|
|
77
|
+
if video_width >= video_height:
|
|
78
|
+
final_height = final_height + 30
|
|
62
79
|
|
|
63
80
|
return final_width, final_height
|
|
64
81
|
|
|
@@ -82,8 +99,8 @@ def play_video(url, width=None, height=None,
|
|
|
82
99
|
raise ValueError("url参数无效,必须提供有效的URL字符串")
|
|
83
100
|
|
|
84
101
|
url = url.strip()
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
|
|
103
|
+
url = Path(url).absolute().as_uri()
|
|
87
104
|
|
|
88
105
|
final_width, final_height = calculate_window_size(width=width, height=height)
|
|
89
106
|
|
|
@@ -11,10 +11,10 @@ def check_edge_availability():
|
|
|
11
11
|
"""检查Edge浏览器是否可用"""
|
|
12
12
|
edge_path = find_edge_browser()
|
|
13
13
|
if edge_path:
|
|
14
|
-
print(f"
|
|
14
|
+
print(f"Edge浏览器可用: {edge_path}")
|
|
15
15
|
return True
|
|
16
16
|
else:
|
|
17
|
-
print("
|
|
17
|
+
print("Edge浏览器未找到")
|
|
18
18
|
return False
|
|
19
19
|
|
|
20
20
|
|
|
@@ -22,23 +22,37 @@ def demo_window_calculation():
|
|
|
22
22
|
"""演示窗口大小计算"""
|
|
23
23
|
print("\n窗口大小计算演示:")
|
|
24
24
|
print("-" * 30)
|
|
25
|
-
|
|
26
|
-
#
|
|
25
|
+
|
|
26
|
+
# 自动检测屏幕尺寸并计算默认窗口大小
|
|
27
27
|
width, height = calculate_window_size()
|
|
28
|
-
print(f"
|
|
28
|
+
print(f"默认(横屏参考): {int(width)}x{int(height)}")
|
|
29
|
+
|
|
30
|
+
# 横屏视频(50% 屏幕)
|
|
31
|
+
for test_w, test_h in [(1920, 1080), (1280, 720)]:
|
|
32
|
+
w, h = calculate_window_size(width=test_w, height=test_h)
|
|
33
|
+
print(f"横屏视频 {test_w}x{test_h} -> 50% 屏幕: {int(w)}x{int(h)}")
|
|
34
|
+
|
|
35
|
+
# 竖屏视频(80% 屏幕)
|
|
36
|
+
for test_w, test_h in [(1080, 1920), (720, 1280)]:
|
|
37
|
+
w, h = calculate_window_size(width=test_w, height=test_h)
|
|
38
|
+
print(f"竖屏视频 {test_w}x{test_h} -> 80% 屏幕: {int(w)}x{int(h)}")
|
|
39
|
+
|
|
40
|
+
# 指定自定义缩放比例(相对屏幕)
|
|
41
|
+
w, h = calculate_window_size(width=1920, height=1080, scale=0.3)
|
|
42
|
+
print(f"自定义缩放 scale=0.3: {int(w)}x{int(h)}")
|
|
29
43
|
|
|
30
44
|
|
|
31
45
|
def demo_different_configs():
|
|
32
46
|
"""演示不同配置的播放"""
|
|
33
47
|
print("\n不同配置演示:")
|
|
34
48
|
print("-" * 30)
|
|
35
|
-
|
|
49
|
+
|
|
36
50
|
print("1. 仅Edge浏览器(无回退):")
|
|
37
51
|
print(" play_video(url, use_edge=True, use_browser_fallback=False)")
|
|
38
|
-
|
|
52
|
+
|
|
39
53
|
print("\n2. 强制使用系统浏览器:")
|
|
40
54
|
print(" play_video(url, use_edge=False, use_browser_fallback=True)")
|
|
41
|
-
|
|
55
|
+
|
|
42
56
|
print("\n3. 自定义窗口大小:")
|
|
43
57
|
print(" play_video(url, width=1920, height=1080)")
|
|
44
58
|
|
|
@@ -46,11 +60,11 @@ def demo_different_configs():
|
|
|
46
60
|
def main():
|
|
47
61
|
print("HTMLPlayer 高级示例")
|
|
48
62
|
print("=" * 50)
|
|
49
|
-
|
|
63
|
+
|
|
50
64
|
check_edge_availability()
|
|
51
65
|
demo_window_calculation()
|
|
52
66
|
demo_different_configs()
|
|
53
|
-
|
|
67
|
+
|
|
54
68
|
print("\n" + "=" * 50)
|
|
55
69
|
print("提示:参考 simple_example.py 来运行实际的视频播放")
|
|
56
70
|
|
|
@@ -9,26 +9,26 @@ from htmlplayer import play_video, play_with_edge, play_with_browser
|
|
|
9
9
|
def main():
|
|
10
10
|
print("HTMLPlayer 视频播放库 - 简单示例")
|
|
11
11
|
print("=" * 50)
|
|
12
|
-
|
|
12
|
+
|
|
13
13
|
print("\n1. 基础用法:")
|
|
14
14
|
print(" from htmlplayer import play_video")
|
|
15
15
|
print(" play_video('https://example.com/video.m3u8')")
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
print("\n2. 指定窗口大小:")
|
|
18
18
|
print(" play_video('https://example.com/video.m3u8', width=1280, height=720)")
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
print("\n3. 仅使用Edge浏览器:")
|
|
21
21
|
print(" from htmlplayer import play_with_edge")
|
|
22
22
|
print(" play_with_edge('https://example.com/video.m3u8')")
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
print("\n4. 使用系统默认浏览器:")
|
|
25
25
|
print(" from htmlplayer import play_with_browser")
|
|
26
26
|
print(" play_with_browser('https://example.com/video.m3u8')")
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
print("\n" + "=" * 50)
|
|
29
|
-
print("
|
|
29
|
+
print("提示:取消下面代码的注释可以实际运行一个示例")
|
|
30
30
|
print("=" * 50)
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
# 实际演示(取消注释以运行)
|
|
33
33
|
# print("\n正在播放示例视频...")
|
|
34
34
|
# play_video('https://jx.xmflv.com/?url=https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8')
|
|
@@ -36,4 +36,3 @@ def main():
|
|
|
36
36
|
|
|
37
37
|
if __name__ == '__main__':
|
|
38
38
|
main()
|
|
39
|
-
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: htmlplayer
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: 一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频
|
|
5
5
|
Home-page: https://github.com/yourusername/htmlplayer
|
|
6
6
|
Author: lenvy1
|
|
@@ -93,9 +93,25 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
93
93
|
|
|
94
94
|
查找Microsoft Edge浏览器的安装路径。
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
**返回:**
|
|
97
|
+
- `str` or `None`: Edge浏览器的安装路径,若未找到返回None
|
|
98
|
+
|
|
99
|
+
### calculate_window_size(width=None, height=None, scale=None)
|
|
100
|
+
|
|
101
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
102
|
+
|
|
103
|
+
**参数:**
|
|
104
|
+
- `width` (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
105
|
+
- `height` (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
106
|
+
- `scale` (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
107
|
+
|
|
108
|
+
**返回:**
|
|
109
|
+
- `tuple`: 包含窗口宽度和高度的元组 (final_width, final_height)
|
|
97
110
|
|
|
98
|
-
|
|
111
|
+
**自动缩放规则:**
|
|
112
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
113
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
114
|
+
- 严格保持原视频纵横比
|
|
99
115
|
|
|
100
116
|
## 系统要求
|
|
101
117
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|