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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: htmlplayer
3
- Version: 0.1.2
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
- ### calculate_window_size(width=None, height=None, scale=0.5)
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
- ### calculate_window_size(width=None, height=None, scale=0.5)
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
 
@@ -7,7 +7,7 @@ from .core import (
7
7
  calculate_window_size
8
8
  )
9
9
 
10
- __version__ = "0.1.2"
10
+ __version__ = "0.3.0"
11
11
  __all__ = [
12
12
  "play_video",
13
13
  "play_with_edge",
@@ -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=0.5):
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): 窗口相对于输入尺寸的缩放比例,默认0.5(即50%尺寸)
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
- 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
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 = max_height
61
- final_width = max_height * target_ratio
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
- if not url.startswith('http'):
86
- raise ValueError("url必须以http或https开头")
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"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,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"默认窗口大小: {int(width)}x{int(height)}")
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.1.2
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
- ### calculate_window_size(width=None, height=None, scale=0.5)
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
 
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "htmlplayer"
8
- version = "0.1.2"
8
+ version = "0.3.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.2",
6
+ version="0.3.0",
7
7
  packages=find_packages(),
8
8
  include_package_data=True,
9
9
  description="一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频",
File without changes
File without changes