htmlplayer 0.2.0__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.2.0
3
+ Version: 0.3.0
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): 窗口相对于输入尺寸的缩放比例,默认None表示自动计算
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
- - 竖屏视频 (宽高比 <= 0.6): 自动使用 90% 尺寸
113
- - 高度 >= 1080: 自动使用 50% 尺寸
114
- - 高度 >= 720: 自动使用 60% 尺寸
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): 窗口相对于输入尺寸的缩放比例,默认None表示自动计算
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
- - 竖屏视频 (宽高比 <= 0.6): 自动使用 90% 尺寸
89
- - 高度 >= 1080: 自动使用 50% 尺寸
90
- - 高度 >= 720: 自动使用 60% 尺寸
91
- - 高度 >= 480: 自动使用 100% 尺寸
88
+ - 横屏视频(宽 >= 高):缩放到屏幕的 50%
89
+ - 竖屏视频(宽 < 高):缩放到屏幕的 80%
90
+ - 严格保持原视频纵横比
92
91
 
93
92
  ## 系统要求
94
93
 
@@ -7,7 +7,7 @@ from .core import (
7
7
  calculate_window_size
8
8
  )
9
9
 
10
- __version__ = "0.2.0"
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():
@@ -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): 窗口相对于输入尺寸的缩放比例,默认None表示自动计算
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
- if width is None or height is None:
31
- try:
32
- import tkinter as tk
33
- root = tk.Tk()
34
- root.withdraw()
35
- width = root.winfo_screenwidth()
36
- height = root.winfo_screenheight()
37
- root.destroy()
38
- except Exception as e:
39
- raise RuntimeError(f"无法自动获取屏幕分辨率,请手动传入 width 和 height。错误信息: {e}")
40
-
41
- target_ratio = width / height
42
-
43
- auto_scale = 0.5
44
- if target_ratio <= 0.6:
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
-
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
- scale = auto_scale
55
-
56
- max_width = width * scale
57
- max_height = height * scale
58
-
59
- if max_width / target_ratio <= max_height:
60
- final_width = max_width
61
- final_height = max_width / target_ratio
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
- final_height = max_height
64
- 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
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
- if not url.startswith('http'):
89
- raise ValueError("url必须以http或https开头")
102
+
103
+ url = Path(url).absolute().as_uri()
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"默认窗口大小: {int(width)}x{int(height)}")
28
+ print(f"默认(横屏参考): {int(width)}x{int(height)}")
29
29
 
30
- # 指定输入尺寸自动计算缩放
31
- for test_w, test_h in [(1920, 1080), (1280, 720), (640, 480), (1080, 1920)]:
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"输入 {test_w}x{test_h} -> 窗口 {int(w)}x{int(h)}")
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.2.0
3
+ Version: 0.3.0
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): 窗口相对于输入尺寸的缩放比例,默认None表示自动计算
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
- - 竖屏视频 (宽高比 <= 0.6): 自动使用 90% 尺寸
113
- - 高度 >= 1080: 自动使用 50% 尺寸
114
- - 高度 >= 720: 自动使用 60% 尺寸
115
- - 高度 >= 480: 自动使用 100% 尺寸
112
+ - 横屏视频(宽 >= 高):缩放到屏幕的 50%
113
+ - 竖屏视频(宽 < 高):缩放到屏幕的 80%
114
+ - 严格保持原视频纵横比
116
115
 
117
116
  ## 系统要求
118
117
 
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "htmlplayer"
8
- version = "0.2.0"
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.2.0",
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