htmlplayer 0.1.0__py3-none-any.whl

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/__init__.py ADDED
@@ -0,0 +1,18 @@
1
+
2
+ from .core import (
3
+ play_video,
4
+ play_with_edge,
5
+ play_with_browser,
6
+ find_edge_browser,
7
+ calculate_window_size
8
+ )
9
+
10
+ __version__ = "0.1.0"
11
+ __all__ = [
12
+ "play_video",
13
+ "play_with_edge",
14
+ "play_with_browser",
15
+ "find_edge_browser",
16
+ "calculate_window_size"
17
+ ]
18
+
htmlplayer/core.py ADDED
@@ -0,0 +1,121 @@
1
+
2
+ import subprocess
3
+ import os
4
+
5
+
6
+ def find_edge_browser():
7
+ edge_paths = [
8
+ r'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe',
9
+ r'C:\Program Files\Microsoft\Edge\Application\msedge.exe',
10
+ os.path.expanduser(r'~\AppData\Local\Microsoft\Edge\Application\msedge.exe'),
11
+ ]
12
+ for path in edge_paths:
13
+ if os.path.exists(path):
14
+ return path
15
+ return None
16
+
17
+
18
+ def calculate_window_size(screen_width=None, screen_height=None,
19
+ video_aspect_ratio=16/9, scale=0.5):
20
+ if screen_width is None or screen_height is None:
21
+ import ctypes
22
+ user32 = ctypes.windll.user32
23
+ screen_width = user32.GetSystemMetrics(0)
24
+ screen_height = user32.GetSystemMetrics(1)
25
+
26
+ if video_aspect_ratio <= 0.6:
27
+ scale = 0.9
28
+
29
+ max_width = screen_width * scale
30
+ max_height = screen_height * scale
31
+
32
+ width = max_width
33
+ height = width / video_aspect_ratio
34
+
35
+ if height > max_height:
36
+ height = max_height
37
+ width = height * video_aspect_ratio
38
+
39
+ return int(width), int(height)
40
+
41
+
42
+ def play_video(url, width=None, height=None, video_aspect_ratio=16/9,
43
+ use_edge=True, use_browser_fallback=True):
44
+ """
45
+ 使用Edge浏览器或系统默认浏览器播放视频
46
+
47
+ 参数:
48
+ url (str): 视频URL地址
49
+ width (int, optional): 窗口宽度
50
+ height (int, optional): 窗口高度
51
+ video_aspect_ratio (float): 视频宽高比,默认16:9
52
+ use_edge (bool): 是否优先使用Edge浏览器,默认True
53
+ use_browser_fallback (bool): Edge不可用时是否使用默认浏览器,默认True
54
+
55
+ 返回:
56
+ bool: 播放是否成功启动
57
+ """
58
+ if not url or not isinstance(url, str):
59
+ raise ValueError("url参数无效,必须提供有效的URL字符串")
60
+
61
+ url = url.strip()
62
+ if not url.startswith('http'):
63
+ raise ValueError("url必须以http或https开头")
64
+
65
+ if width is None or height is None:
66
+ width, height = calculate_window_size(video_aspect_ratio=video_aspect_ratio)
67
+
68
+ edge_path = find_edge_browser() if use_edge else None
69
+
70
+ if edge_path:
71
+ subprocess.Popen([
72
+ edge_path,
73
+ '--app=' + url,
74
+ '--new-window',
75
+ f'--window-size={width},{height}',
76
+ '--disable-extensions',
77
+ '--disable-plugins',
78
+ '--inprivate'
79
+ ])
80
+ return True
81
+ elif use_browser_fallback:
82
+ import webbrowser
83
+ webbrowser.open(url)
84
+ return True
85
+ else:
86
+ return False
87
+
88
+
89
+ def play_with_edge(url, width=None, height=None, video_aspect_ratio=16/9):
90
+ """
91
+ 仅使用Edge浏览器播放视频
92
+
93
+ 参数:
94
+ url (str): 视频URL地址
95
+ width (int, optional): 窗口宽度
96
+ height (int, optional): 窗口高度
97
+ video_aspect_ratio (float): 视频宽高比,默认16:9
98
+
99
+ 返回:
100
+ bool: 播放是否成功启动
101
+ """
102
+ return play_video(url, width, height, video_aspect_ratio,
103
+ use_edge=True, use_browser_fallback=False)
104
+
105
+
106
+ def play_with_browser(url, width=None, height=None, video_aspect_ratio=16/9):
107
+ """
108
+ 使用系统默认浏览器播放视频
109
+
110
+ 参数:
111
+ url (str): 视频URL地址
112
+ width (int, optional): 窗口宽度
113
+ height (int, optional): 窗口高度
114
+ video_aspect_ratio (float): 视频宽高比,默认16:9
115
+
116
+ 返回:
117
+ bool: 播放是否成功启动
118
+ """
119
+ return play_video(url, width, height, video_aspect_ratio,
120
+ use_edge=False, use_browser_fallback=True)
121
+
@@ -0,0 +1,5 @@
1
+
2
+ """
3
+ HTMLPlayer 示例代码
4
+ """
5
+
@@ -0,0 +1,66 @@
1
+
2
+ """
3
+ HTMLPlayer 高级示例
4
+ 展示更多功能和自定义配置
5
+ """
6
+
7
+ from htmlplayer import play_video, find_edge_browser, calculate_window_size
8
+
9
+
10
+ def check_edge_availability():
11
+ """检查Edge浏览器是否可用"""
12
+ edge_path = find_edge_browser()
13
+ if edge_path:
14
+ print(f"✅ Edge浏览器可用: {edge_path}")
15
+ return True
16
+ else:
17
+ print("❌ Edge浏览器未找到")
18
+ return False
19
+
20
+
21
+ def demo_window_calculation():
22
+ """演示窗口大小计算"""
23
+ print("\n窗口大小计算演示:")
24
+ print("-" * 30)
25
+
26
+ # 获取屏幕尺寸并计算
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}")
34
+
35
+
36
+ def demo_different_configs():
37
+ """演示不同配置的播放"""
38
+ print("\n不同配置演示:")
39
+ print("-" * 30)
40
+
41
+ # 这里只是示例,实际运行时可以取消注释
42
+ print("1. 仅Edge浏览器(无回退):")
43
+ print(" play_video(url, use_edge=True, use_browser_fallback=False)")
44
+
45
+ print("\n2. 强制使用系统浏览器:")
46
+ print(" play_video(url, use_edge=False, use_browser_fallback=True)")
47
+
48
+ print("\n3. 自定义窗口:")
49
+ print(" play_video(url, width=1920, height=1080)")
50
+
51
+
52
+ def main():
53
+ print("HTMLPlayer 高级示例")
54
+ print("=" * 50)
55
+
56
+ check_edge_availability()
57
+ demo_window_calculation()
58
+ demo_different_configs()
59
+
60
+ print("\n" + "=" * 50)
61
+ print("提示:参考 simple_example.py 来运行实际的视频播放")
62
+
63
+
64
+ if __name__ == '__main__':
65
+ main()
66
+
@@ -0,0 +1,50 @@
1
+
2
+ """
3
+ HTMLPlayer 简单示例
4
+ """
5
+
6
+ from htmlplayer import play_video, play_with_edge, play_with_browser
7
+
8
+
9
+ def main():
10
+ print("HTMLPlayer 视频播放库 - 简单示例")
11
+ print("=" * 50)
12
+
13
+ # 示例 1: 基础用法
14
+ print("\n1. 基础用法:")
15
+ print(" from htmlplayer import play_video")
16
+ print(" play_video('https://example.com/video.m3u8')")
17
+
18
+ # 示例 2: 指定窗口大小
19
+ print("\n2. 指定窗口大小:")
20
+ print(" play_video('https://example.com/video.m3u8', width=1280, height=720)")
21
+
22
+ # 示例 3: 指定视频宽高比
23
+ print("\n3. 指定视频宽高比:")
24
+ print(" play_video('https://example.com/video.m3u8', video_aspect_ratio=21/9)")
25
+
26
+ # 示例 4: 仅使用Edge浏览器
27
+ print("\n4. 仅使用Edge浏览器:")
28
+ print(" from htmlplayer import play_with_edge")
29
+ print(" play_with_edge('https://example.com/video.m3u8')")
30
+
31
+ # 示例 5: 使用系统默认浏览器
32
+ print("\n5. 使用系统默认浏览器:")
33
+ print(" from htmlplayer import play_with_browser")
34
+ print(" play_with_browser('https://example.com/video.m3u8')")
35
+
36
+ print("\n" + "=" * 50)
37
+ print("提示:取消下面的注释可以实际运行一个示例")
38
+ print("=" * 50)
39
+
40
+ # 实际演示(取消注释以运行)
41
+ # print("\n正在播放示例视频...")
42
+ # play_video(
43
+ # 'https://jx.xmflv.com/?url=https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8',
44
+ # video_aspect_ratio=16/9
45
+ # )
46
+
47
+
48
+ if __name__ == '__main__':
49
+ main()
50
+
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.4
2
+ Name: htmlplayer
3
+ Version: 0.1.0
4
+ Summary: 一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频
5
+ Home-page: https://github.com/yourusername/htmlplayer
6
+ Author: lenvy1
7
+ Author-email: lenvy1 <lenvy1@163.com>
8
+ Project-URL: Homepage, https://github.com/yourusername/htmlplayer
9
+ Project-URL: Issues, https://github.com/yourusername/htmlplayer/issues
10
+ Keywords: video,player,html5,browser,edge
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: Microsoft :: Windows
19
+ Requires-Python: >=3.8
20
+ Description-Content-Type: text/markdown
21
+ Dynamic: author
22
+ Dynamic: home-page
23
+ Dynamic: requires-python
24
+
25
+
26
+ # HTMLPlayer
27
+
28
+ 一个简单的Python库,用于使用Microsoft Edge浏览器或系统默认浏览器播放HTML5视频。
29
+
30
+ ## 安装
31
+
32
+ ```bash
33
+ pip install htmlplayer
34
+ ```
35
+
36
+ ## 快速开始
37
+
38
+ ### 基础用法
39
+
40
+ ```python
41
+ from htmlplayer import play_video
42
+
43
+ play_video('https://example.com/video.mp4')
44
+ ```
45
+
46
+ ### 指定窗口大小
47
+
48
+ ```python
49
+ play_video('https://example.com/video.mp4', width=1280, height=720)
50
+ ```
51
+
52
+ ### 指定视频宽高比
53
+
54
+ ```python
55
+ play_video('https://example.com/video.mp4', video_aspect_ratio=21/9)
56
+ ```
57
+
58
+ ### 仅使用Edge浏览器
59
+
60
+ ```python
61
+ from htmlplayer import play_with_edge
62
+
63
+ play_with_edge('https://example.com/video.mp4')
64
+ ```
65
+
66
+ ### 使用系统默认浏览器
67
+
68
+ ```python
69
+ from htmlplayer import play_with_browser
70
+
71
+ play_with_browser('https://example.com/video.mp4')
72
+ ```
73
+
74
+ ## API 文档
75
+
76
+ ### play_video(url, width=None, height=None, video_aspect_ratio=16/9, use_edge=True, use_browser_fallback=True)
77
+
78
+ 使用Edge浏览器或系统默认浏览器播放视频。
79
+
80
+ **参数:**
81
+ - `url` (str): 视频URL地址
82
+ - `width` (int, optional): 窗口宽度
83
+ - `height` (int, optional): 窗口高度
84
+ - `video_aspect_ratio` (float): 视频宽高比,默认16:9
85
+ - `use_edge` (bool): 是否优先使用Edge浏览器,默认True
86
+ - `use_browser_fallback` (bool): Edge不可用时是否使用默认浏览器,默认True
87
+
88
+ **返回:**
89
+ - `bool`: 播放是否成功启动
90
+
91
+ ### play_with_edge(url, width=None, height=None, video_aspect_ratio=16/9)
92
+
93
+ 仅使用Edge浏览器播放视频。
94
+
95
+ ### play_with_browser(url, width=None, height=None, video_aspect_ratio=16/9)
96
+
97
+ 使用系统默认浏览器播放视频。
98
+
99
+ ### find_edge_browser()
100
+
101
+ 查找Microsoft Edge浏览器的安装路径。
102
+
103
+ ### calculate_window_size(screen_width=None, screen_height=None, video_aspect_ratio=16/9, scale=0.5)
104
+
105
+ 计算合适的窗口大小。
106
+
107
+ ## 系统要求
108
+
109
+ - 操作系统:Windows
110
+ - Python 3.8+
111
+ - Microsoft Edge浏览器(可选,推荐)
112
+
113
+ ## 示例代码
114
+
115
+ 安装后,你可以查看 `examples/` 目录下的示例代码:
116
+
117
+ ```bash
118
+ # 简单示例
119
+ python -c "import htmlplayer.examples.simple_example"
120
+
121
+ # 或找到安装位置查看文件
122
+ python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(htmlplayer.__file__), '..', 'examples'))"
123
+ ```
124
+
125
+ 示例文件:
126
+ - `simple_example.py` - 基础使用示例
127
+ - `advanced_example.py` - 高级功能和自定义配置
128
+
129
+ ## 许可证
130
+
131
+ MIT License
132
+
@@ -0,0 +1,9 @@
1
+ htmlplayer/__init__.py,sha256=tlDK_Xu_RYgkoZvERA8xrQwlGT1-9fFt5i4FH5-9NFQ,287
2
+ htmlplayer/core.py,sha256=qBdfmBtwL-2uxFdpNKpjXi9xiw2GipBMQz02t3iwWoY,3603
3
+ htmlplayer/examples/__init__.py,sha256=Jyyld-DWttplVFJKy8F3Q8EtcSQtCuPwiP3Ru8x6AWE,34
4
+ htmlplayer/examples/advanced_example.py,sha256=30ah8-mDs8dBTeBCIqPFy6YI74QEDrwyMtxprZW_0-s,1746
5
+ htmlplayer/examples/simple_example.py,sha256=t_uR_vvpvINP5IJhFxXQbkRkBQqk3MeLw2WbzW5wUQ4,1540
6
+ htmlplayer-0.1.0.dist-info/METADATA,sha256=irjWVID3GkFKcccdWORmZyO8CLut0hW901w7k3ekGNs,3484
7
+ htmlplayer-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
8
+ htmlplayer-0.1.0.dist-info/top_level.txt,sha256=oqzNLfdNdiYWcopRTYKLflNzliVxT7boLP45oEzsN-M,11
9
+ htmlplayer-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ htmlplayer