htmlplayer 0.1.1__tar.gz → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htmlplayer
3
- Version: 0.1.1
3
+ Version: 0.2.0
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, video_aspect_ratio=16/9, use_edge=True, use_browser_fallback=True)
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, video_aspect_ratio=16/9)
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, video_aspect_ratio=16/9)
88
+ ### play_with_browser(url, width=None, height=None)
96
89
 
97
90
  使用系统默认浏览器播放视频。
98
91
 
@@ -100,9 +93,26 @@ play_with_browser('https://example.com/video.mp4')
100
93
 
101
94
  查找Microsoft Edge浏览器的安装路径。
102
95
 
103
- ### calculate_window_size(screen_width=None, screen_height=None, video_aspect_ratio=16/9, scale=0.5)
96
+ **返回:**
97
+ - `str` or `None`: Edge浏览器的安装路径,若未找到返回None
98
+
99
+ ### calculate_window_size(width=None, height=None, scale=None)
104
100
 
105
- 计算合适的窗口大小。
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)
110
+
111
+ **自动缩放规则:**
112
+ - 竖屏视频 (宽高比 <= 0.6): 自动使用 90% 尺寸
113
+ - 高度 >= 1080: 自动使用 50% 尺寸
114
+ - 高度 >= 720: 自动使用 60% 尺寸
115
+ - 高度 >= 480: 自动使用 100% 尺寸
106
116
 
107
117
  ## 系统要求
108
118
 
@@ -129,4 +139,3 @@ python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(html
129
139
  ## 许可证
130
140
 
131
141
  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, video_aspect_ratio=16/9, use_edge=True, use_browser_fallback=True)
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, video_aspect_ratio=16/9)
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, video_aspect_ratio=16/9)
64
+ ### play_with_browser(url, width=None, height=None)
72
65
 
73
66
  使用系统默认浏览器播放视频。
74
67
 
@@ -76,9 +69,26 @@ play_with_browser('https://example.com/video.mp4')
76
69
 
77
70
  查找Microsoft Edge浏览器的安装路径。
78
71
 
79
- ### calculate_window_size(screen_width=None, screen_height=None, video_aspect_ratio=16/9, scale=0.5)
72
+ **返回:**
73
+ - `str` or `None`: Edge浏览器的安装路径,若未找到返回None
74
+
75
+ ### calculate_window_size(width=None, height=None, scale=None)
80
76
 
81
- 计算合适的窗口大小。
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)
86
+
87
+ **自动缩放规则:**
88
+ - 竖屏视频 (宽高比 <= 0.6): 自动使用 90% 尺寸
89
+ - 高度 >= 1080: 自动使用 50% 尺寸
90
+ - 高度 >= 720: 自动使用 60% 尺寸
91
+ - 高度 >= 480: 自动使用 100% 尺寸
82
92
 
83
93
  ## 系统要求
84
94
 
@@ -105,4 +115,3 @@ python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(html
105
115
  ## 许可证
106
116
 
107
117
  MIT License
108
-
@@ -7,7 +7,7 @@ from .core import (
7
7
  calculate_window_size
8
8
  )
9
9
 
10
- __version__ = "0.1.1"
10
+ __version__ = "0.2.0"
11
11
  __all__ = [
12
12
  "play_video",
13
13
  "play_with_edge",
@@ -15,48 +15,51 @@ def find_edge_browser():
15
15
  return None
16
16
 
17
17
 
18
- def calculate_window_size(width, height, scale=0.5):
18
+ def calculate_window_size(width=None, height=None, scale=None):
19
19
  """
20
20
  根据输入的宽高计算合适的窗口大小(严格等比缩放)
21
-
21
+
22
22
  参数:
23
- width (int/float): 目标宽度(像素)
24
- height (int/float): 目标高度(像素)
25
- scale (float): 窗口相对于输入尺寸的缩放比例,默认0.5(即50%尺寸)
26
-
23
+ width (int/float, optional): 目标宽度(像素),不传则自动检测屏幕宽度
24
+ height (int/float, optional): 目标高度(像素),不传则自动检测屏幕高度
25
+ scale (float, optional): 窗口相对于输入尺寸的缩放比例,默认None表示自动计算
26
+
27
27
  返回:
28
28
  tuple: 包含窗口宽度和高度的元组 (final_width, final_height),均为真实的浮点数
29
29
  """
30
- # 1. 跨平台自动检测屏幕分辨率
31
30
  if width is None or height is None:
32
31
  try:
33
32
  import tkinter as tk
34
33
  root = tk.Tk()
35
- root.withdraw() # 隐藏主窗口,避免闪烁
34
+ root.withdraw()
36
35
  width = root.winfo_screenwidth()
37
36
  height = root.winfo_screenheight()
38
37
  root.destroy()
39
38
  except Exception as e:
40
- raise RuntimeError(f"无法自动获取屏幕分辨率,请手动传入 screen_widthscreen_height。错误信息: {e}")
41
- # 2. 根据传入的宽高直接计算目标宽高比
39
+ raise RuntimeError(f"无法自动获取屏幕分辨率,请手动传入 widthheight。错误信息: {e}")
40
+
42
41
  target_ratio = width / height
43
42
 
44
- # 3. 针对竖屏视频的视觉体验优化
45
- # 竖屏视频(如 9:16,比例约为 0.56)若按默认比例缩放会导致画面过小,因此放大显示
43
+ auto_scale = 0.5
46
44
  if target_ratio <= 0.6:
47
- scale = 0.9
45
+ auto_scale = 0.9
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
+
53
+ if scale is None:
54
+ scale = auto_scale
48
55
 
49
- # 4. 计算允许的最大边界
50
56
  max_width = width * scale
51
57
  max_height = height * scale
52
58
 
53
- # 5. 核心等比缩放计算(取最小限制比例,确保不超出屏幕且保持绝对比例)
54
59
  if max_width / target_ratio <= max_height:
55
- # 宽度先触达边界,以宽度为基准计算高度
56
60
  final_width = max_width
57
61
  final_height = max_width / target_ratio
58
62
  else:
59
- # 高度先触达边界,以高度为基准计算宽度
60
63
  final_height = max_height
61
64
  final_width = max_height * target_ratio
62
65
 
@@ -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"Edge浏览器可用: {edge_path}")
14
+ print(f"Edge浏览器可用: {edge_path}")
15
15
  return True
16
16
  else:
17
- print("Edge浏览器未找到")
17
+ print("Edge浏览器未找到")
18
18
  return False
19
19
 
20
20
 
@@ -22,45 +22,47 @@ 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"默认窗口大小: {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)}")
29
+
30
+ # 指定输入尺寸自动计算缩放
31
+ for test_w, test_h in [(1920, 1080), (1280, 720), (640, 480), (1080, 1920)]:
32
+ w, h = calculate_window_size(width=test_w, height=test_h)
33
+ print(f"输入 {test_w}x{test_h} -> 窗口 {int(w)}x{int(h)}")
34
+
35
+ # 指定自定义缩放比例
36
+ w, h = calculate_window_size(width=1920, height=1080, scale=0.3)
37
+ print(f"自定义缩放 scale=0.3: {int(w)}x{int(h)}")
34
38
 
35
39
 
36
40
  def demo_different_configs():
37
41
  """演示不同配置的播放"""
38
42
  print("\n不同配置演示:")
39
43
  print("-" * 30)
40
-
41
- # 这里只是示例,实际运行时可以取消注释
44
+
42
45
  print("1. 仅Edge浏览器(无回退):")
43
46
  print(" play_video(url, use_edge=True, use_browser_fallback=False)")
44
-
47
+
45
48
  print("\n2. 强制使用系统浏览器:")
46
49
  print(" play_video(url, use_edge=False, use_browser_fallback=True)")
47
-
48
- print("\n3. 自定义窗口:")
50
+
51
+ print("\n3. 自定义窗口大小:")
49
52
  print(" play_video(url, width=1920, height=1080)")
50
53
 
51
54
 
52
55
  def main():
53
56
  print("HTMLPlayer 高级示例")
54
57
  print("=" * 50)
55
-
58
+
56
59
  check_edge_availability()
57
60
  demo_window_calculation()
58
61
  demo_different_configs()
59
-
62
+
60
63
  print("\n" + "=" * 50)
61
64
  print("提示:参考 simple_example.py 来运行实际的视频播放")
62
65
 
63
66
 
64
67
  if __name__ == '__main__':
65
68
  main()
66
-
@@ -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.1.1
3
+ Version: 0.2.0
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, video_aspect_ratio=16/9, use_edge=True, use_browser_fallback=True)
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, video_aspect_ratio=16/9)
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, video_aspect_ratio=16/9)
88
+ ### play_with_browser(url, width=None, height=None)
96
89
 
97
90
  使用系统默认浏览器播放视频。
98
91
 
@@ -100,9 +93,26 @@ play_with_browser('https://example.com/video.mp4')
100
93
 
101
94
  查找Microsoft Edge浏览器的安装路径。
102
95
 
103
- ### calculate_window_size(screen_width=None, screen_height=None, video_aspect_ratio=16/9, scale=0.5)
96
+ **返回:**
97
+ - `str` or `None`: Edge浏览器的安装路径,若未找到返回None
98
+
99
+ ### calculate_window_size(width=None, height=None, scale=None)
104
100
 
105
- 计算合适的窗口大小。
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)
110
+
111
+ **自动缩放规则:**
112
+ - 竖屏视频 (宽高比 <= 0.6): 自动使用 90% 尺寸
113
+ - 高度 >= 1080: 自动使用 50% 尺寸
114
+ - 高度 >= 720: 自动使用 60% 尺寸
115
+ - 高度 >= 480: 自动使用 100% 尺寸
106
116
 
107
117
  ## 系统要求
108
118
 
@@ -129,4 +139,3 @@ python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(html
129
139
  ## 许可证
130
140
 
131
141
  MIT License
132
-
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "htmlplayer"
8
- version = "0.1.1"
8
+ version = "0.2.0"
9
9
  authors = [
10
10
  { name = "lenvy1", email = "lenvy1@163.com" }
11
11
  ]
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
3
3
 
4
4
  setup(
5
5
  name="htmlplayer",
6
- version="0.1.1",
6
+ version="0.2.0",
7
7
  packages=find_packages(),
8
8
  include_package_data=True,
9
9
  description="一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频",
File without changes
File without changes