htmlplayer 0.1.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.
- htmlplayer-0.1.0/MANIFEST.in +5 -0
- htmlplayer-0.1.0/PKG-INFO +132 -0
- htmlplayer-0.1.0/README.md +108 -0
- htmlplayer-0.1.0/htmlplayer/__init__.py +18 -0
- htmlplayer-0.1.0/htmlplayer/core.py +121 -0
- htmlplayer-0.1.0/htmlplayer/examples/__init__.py +5 -0
- htmlplayer-0.1.0/htmlplayer/examples/advanced_example.py +66 -0
- htmlplayer-0.1.0/htmlplayer/examples/simple_example.py +50 -0
- htmlplayer-0.1.0/htmlplayer.egg-info/PKG-INFO +132 -0
- htmlplayer-0.1.0/htmlplayer.egg-info/SOURCES.txt +13 -0
- htmlplayer-0.1.0/htmlplayer.egg-info/dependency_links.txt +1 -0
- htmlplayer-0.1.0/htmlplayer.egg-info/top_level.txt +1 -0
- htmlplayer-0.1.0/pyproject.toml +30 -0
- htmlplayer-0.1.0/setup.cfg +4 -0
- htmlplayer-0.1.0/setup.py +28 -0
|
@@ -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,108 @@
|
|
|
1
|
+
|
|
2
|
+
# HTMLPlayer
|
|
3
|
+
|
|
4
|
+
一个简单的Python库,用于使用Microsoft Edge浏览器或系统默认浏览器播放HTML5视频。
|
|
5
|
+
|
|
6
|
+
## 安装
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pip install htmlplayer
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## 快速开始
|
|
13
|
+
|
|
14
|
+
### 基础用法
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from htmlplayer import play_video
|
|
18
|
+
|
|
19
|
+
play_video('https://example.com/video.mp4')
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### 指定窗口大小
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
play_video('https://example.com/video.mp4', width=1280, height=720)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 指定视频宽高比
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
play_video('https://example.com/video.mp4', video_aspect_ratio=21/9)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 仅使用Edge浏览器
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from htmlplayer import play_with_edge
|
|
38
|
+
|
|
39
|
+
play_with_edge('https://example.com/video.mp4')
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 使用系统默认浏览器
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from htmlplayer import play_with_browser
|
|
46
|
+
|
|
47
|
+
play_with_browser('https://example.com/video.mp4')
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API 文档
|
|
51
|
+
|
|
52
|
+
### play_video(url, width=None, height=None, video_aspect_ratio=16/9, use_edge=True, use_browser_fallback=True)
|
|
53
|
+
|
|
54
|
+
使用Edge浏览器或系统默认浏览器播放视频。
|
|
55
|
+
|
|
56
|
+
**参数:**
|
|
57
|
+
- `url` (str): 视频URL地址
|
|
58
|
+
- `width` (int, optional): 窗口宽度
|
|
59
|
+
- `height` (int, optional): 窗口高度
|
|
60
|
+
- `video_aspect_ratio` (float): 视频宽高比,默认16:9
|
|
61
|
+
- `use_edge` (bool): 是否优先使用Edge浏览器,默认True
|
|
62
|
+
- `use_browser_fallback` (bool): Edge不可用时是否使用默认浏览器,默认True
|
|
63
|
+
|
|
64
|
+
**返回:**
|
|
65
|
+
- `bool`: 播放是否成功启动
|
|
66
|
+
|
|
67
|
+
### play_with_edge(url, width=None, height=None, video_aspect_ratio=16/9)
|
|
68
|
+
|
|
69
|
+
仅使用Edge浏览器播放视频。
|
|
70
|
+
|
|
71
|
+
### play_with_browser(url, width=None, height=None, video_aspect_ratio=16/9)
|
|
72
|
+
|
|
73
|
+
使用系统默认浏览器播放视频。
|
|
74
|
+
|
|
75
|
+
### find_edge_browser()
|
|
76
|
+
|
|
77
|
+
查找Microsoft Edge浏览器的安装路径。
|
|
78
|
+
|
|
79
|
+
### calculate_window_size(screen_width=None, screen_height=None, video_aspect_ratio=16/9, scale=0.5)
|
|
80
|
+
|
|
81
|
+
计算合适的窗口大小。
|
|
82
|
+
|
|
83
|
+
## 系统要求
|
|
84
|
+
|
|
85
|
+
- 操作系统:Windows
|
|
86
|
+
- Python 3.8+
|
|
87
|
+
- Microsoft Edge浏览器(可选,推荐)
|
|
88
|
+
|
|
89
|
+
## 示例代码
|
|
90
|
+
|
|
91
|
+
安装后,你可以查看 `examples/` 目录下的示例代码:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# 简单示例
|
|
95
|
+
python -c "import htmlplayer.examples.simple_example"
|
|
96
|
+
|
|
97
|
+
# 或找到安装位置查看文件
|
|
98
|
+
python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(htmlplayer.__file__), '..', 'examples'))"
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
示例文件:
|
|
102
|
+
- `simple_example.py` - 基础使用示例
|
|
103
|
+
- `advanced_example.py` - 高级功能和自定义配置
|
|
104
|
+
|
|
105
|
+
## 许可证
|
|
106
|
+
|
|
107
|
+
MIT License
|
|
108
|
+
|
|
@@ -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
|
+
|
|
@@ -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,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,13 @@
|
|
|
1
|
+
MANIFEST.in
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.py
|
|
5
|
+
htmlplayer/__init__.py
|
|
6
|
+
htmlplayer/core.py
|
|
7
|
+
htmlplayer.egg-info/PKG-INFO
|
|
8
|
+
htmlplayer.egg-info/SOURCES.txt
|
|
9
|
+
htmlplayer.egg-info/dependency_links.txt
|
|
10
|
+
htmlplayer.egg-info/top_level.txt
|
|
11
|
+
htmlplayer/examples/__init__.py
|
|
12
|
+
htmlplayer/examples/advanced_example.py
|
|
13
|
+
htmlplayer/examples/simple_example.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
htmlplayer
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
[build-system]
|
|
3
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
4
|
+
build-backend = "setuptools.build_meta"
|
|
5
|
+
|
|
6
|
+
[project]
|
|
7
|
+
name = "htmlplayer"
|
|
8
|
+
version = "0.1.0"
|
|
9
|
+
authors = [
|
|
10
|
+
{ name = "lenvy1", email = "lenvy1@163.com" }
|
|
11
|
+
]
|
|
12
|
+
description = "一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频"
|
|
13
|
+
readme = "README.md"
|
|
14
|
+
requires-python = ">=3.8"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.8",
|
|
18
|
+
"Programming Language :: Python :: 3.9",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: Microsoft :: Windows",
|
|
24
|
+
]
|
|
25
|
+
keywords = ["video", "player", "html5", "browser", "edge"]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/yourusername/htmlplayer"
|
|
29
|
+
Issues = "https://github.com/yourusername/htmlplayer/issues"
|
|
30
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
|
|
2
|
+
from setuptools import setup, find_packages
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name="htmlplayer",
|
|
6
|
+
version="0.1.0",
|
|
7
|
+
packages=find_packages(),
|
|
8
|
+
include_package_data=True,
|
|
9
|
+
description="一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频",
|
|
10
|
+
long_description=open("README.md", "r", encoding="utf-8").read(),
|
|
11
|
+
long_description_content_type="text/markdown",
|
|
12
|
+
author="lenvy1",
|
|
13
|
+
author_email="lenvy1@163.com",
|
|
14
|
+
url="https://github.com/yourusername/htmlplayer",
|
|
15
|
+
classifiers=[
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3.8",
|
|
18
|
+
"Programming Language :: Python :: 3.9",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Operating System :: Microsoft :: Windows",
|
|
24
|
+
],
|
|
25
|
+
keywords=["video", "player", "html5", "browser", "edge"],
|
|
26
|
+
python_requires=">=3.8",
|
|
27
|
+
)
|
|
28
|
+
|