htmlplayer 0.2.0__tar.gz → 0.3.1__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.2.0 → htmlplayer-0.3.1}/PKG-INFO +8 -9
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/README.md +7 -8
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer/__init__.py +1 -1
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer/core.py +53 -39
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer/examples/advanced_example.py +10 -5
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer.egg-info/PKG-INFO +8 -9
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/pyproject.toml +1 -1
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/setup.py +1 -1
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/MANIFEST.in +0 -0
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer/examples/__init__.py +0 -0
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer/examples/simple_example.py +0 -0
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer.egg-info/SOURCES.txt +0 -0
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer.egg-info/dependency_links.txt +0 -0
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/htmlplayer.egg-info/top_level.txt +0 -0
- {htmlplayer-0.2.0 → htmlplayer-0.3.1}/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.1
|
|
4
4
|
Summary: 一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频
|
|
5
5
|
Home-page: https://github.com/yourusername/htmlplayer
|
|
6
6
|
Author: lenvy1
|
|
@@ -98,21 +98,20 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
98
98
|
|
|
99
99
|
### calculate_window_size(width=None, height=None, scale=None)
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
102
102
|
|
|
103
103
|
**参数:**
|
|
104
|
-
- `width` (int/float, optional):
|
|
105
|
-
- `height` (int/float, optional):
|
|
106
|
-
- `scale` (float, optional):
|
|
104
|
+
- `width` (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
105
|
+
- `height` (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
106
|
+
- `scale` (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
107
107
|
|
|
108
108
|
**返回:**
|
|
109
109
|
- `tuple`: 包含窗口宽度和高度的元组 (final_width, final_height)
|
|
110
110
|
|
|
111
111
|
**自动缩放规则:**
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
- 高度 >= 480: 自动使用 100% 尺寸
|
|
112
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
113
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
114
|
+
- 严格保持原视频纵横比
|
|
116
115
|
|
|
117
116
|
## 系统要求
|
|
118
117
|
|
|
@@ -74,21 +74,20 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
74
74
|
|
|
75
75
|
### calculate_window_size(width=None, height=None, scale=None)
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
78
78
|
|
|
79
79
|
**参数:**
|
|
80
|
-
- `width` (int/float, optional):
|
|
81
|
-
- `height` (int/float, optional):
|
|
82
|
-
- `scale` (float, optional):
|
|
80
|
+
- `width` (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
81
|
+
- `height` (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
82
|
+
- `scale` (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
83
83
|
|
|
84
84
|
**返回:**
|
|
85
85
|
- `tuple`: 包含窗口宽度和高度的元组 (final_width, final_height)
|
|
86
86
|
|
|
87
87
|
**自动缩放规则:**
|
|
88
|
-
-
|
|
89
|
-
-
|
|
90
|
-
-
|
|
91
|
-
- 高度 >= 480: 自动使用 100% 尺寸
|
|
88
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
89
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
90
|
+
- 严格保持原视频纵横比
|
|
92
91
|
|
|
93
92
|
## 系统要求
|
|
94
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():
|
|
@@ -17,51 +18,64 @@ def find_edge_browser():
|
|
|
17
18
|
|
|
18
19
|
def calculate_window_size(width=None, height=None, scale=None):
|
|
19
20
|
"""
|
|
20
|
-
|
|
21
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
22
|
+
|
|
23
|
+
规则:
|
|
24
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
25
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
26
|
+
- 严格保持原视频纵横比
|
|
21
27
|
|
|
22
28
|
参数:
|
|
23
|
-
width (int/float, optional):
|
|
24
|
-
height (int/float, optional):
|
|
25
|
-
scale (float, optional):
|
|
29
|
+
width (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
30
|
+
height (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
31
|
+
scale (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
26
32
|
|
|
27
33
|
返回:
|
|
28
34
|
tuple: 包含窗口宽度和高度的元组 (final_width, final_height),均为真实的浮点数
|
|
29
35
|
"""
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
elif height >= 1080:
|
|
47
|
-
auto_scale = 0.5
|
|
48
|
-
elif height >= 720:
|
|
49
|
-
auto_scale = 0.6
|
|
50
|
-
elif height >= 480:
|
|
51
|
-
auto_scale = 1.0
|
|
52
|
-
|
|
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. 判断横屏/竖屏并确定自动缩放比例
|
|
53
52
|
if scale is None:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
|
62
72
|
else:
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
65
79
|
|
|
66
80
|
return final_width, final_height
|
|
67
81
|
|
|
@@ -85,8 +99,8 @@ def play_video(url, width=None, height=None,
|
|
|
85
99
|
raise ValueError("url参数无效,必须提供有效的URL字符串")
|
|
86
100
|
|
|
87
101
|
url = url.strip()
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
|
|
103
|
+
url = Path(url).absolute().as_uri() if Path(url).exists() else url
|
|
90
104
|
|
|
91
105
|
final_width, final_height = calculate_window_size(width=width, height=height)
|
|
92
106
|
|
|
@@ -25,14 +25,19 @@ def demo_window_calculation():
|
|
|
25
25
|
|
|
26
26
|
# 自动检测屏幕尺寸并计算默认窗口大小
|
|
27
27
|
width, height = calculate_window_size()
|
|
28
|
-
print(f"
|
|
28
|
+
print(f"默认(横屏参考): {int(width)}x{int(height)}")
|
|
29
29
|
|
|
30
|
-
#
|
|
31
|
-
for test_w, test_h in [(1920, 1080), (1280, 720)
|
|
30
|
+
# 横屏视频(50% 屏幕)
|
|
31
|
+
for test_w, test_h in [(1920, 1080), (1280, 720)]:
|
|
32
32
|
w, h = calculate_window_size(width=test_w, height=test_h)
|
|
33
|
-
print(f"
|
|
33
|
+
print(f"横屏视频 {test_w}x{test_h} -> 50% 屏幕: {int(w)}x{int(h)}")
|
|
34
34
|
|
|
35
|
-
#
|
|
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
|
+
# 指定自定义缩放比例(相对屏幕)
|
|
36
41
|
w, h = calculate_window_size(width=1920, height=1080, scale=0.3)
|
|
37
42
|
print(f"自定义缩放 scale=0.3: {int(w)}x{int(h)}")
|
|
38
43
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: htmlplayer
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.1
|
|
4
4
|
Summary: 一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频
|
|
5
5
|
Home-page: https://github.com/yourusername/htmlplayer
|
|
6
6
|
Author: lenvy1
|
|
@@ -98,21 +98,20 @@ play_with_browser('https://example.com/video.mp4')
|
|
|
98
98
|
|
|
99
99
|
### calculate_window_size(width=None, height=None, scale=None)
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
根据视频宽高计算合适的窗口大小(严格等比缩放)。
|
|
102
102
|
|
|
103
103
|
**参数:**
|
|
104
|
-
- `width` (int/float, optional):
|
|
105
|
-
- `height` (int/float, optional):
|
|
106
|
-
- `scale` (float, optional):
|
|
104
|
+
- `width` (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
|
|
105
|
+
- `height` (int/float, optional): 视频高度(像素),不传则使用屏幕高度
|
|
106
|
+
- `scale` (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算
|
|
107
107
|
|
|
108
108
|
**返回:**
|
|
109
109
|
- `tuple`: 包含窗口宽度和高度的元组 (final_width, final_height)
|
|
110
110
|
|
|
111
111
|
**自动缩放规则:**
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
115
|
-
- 高度 >= 480: 自动使用 100% 尺寸
|
|
112
|
+
- 横屏视频(宽 >= 高):缩放到屏幕的 50%
|
|
113
|
+
- 竖屏视频(宽 < 高):缩放到屏幕的 80%
|
|
114
|
+
- 严格保持原视频纵横比
|
|
116
115
|
|
|
117
116
|
## 系统要求
|
|
118
117
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|