python-mpv-jsonipc 1.2.0__tar.gz → 1.2.2__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.
- python_mpv_jsonipc-1.2.2/LICENSE.md +195 -0
- python_mpv_jsonipc-1.2.2/PKG-INFO +70 -0
- python_mpv_jsonipc-1.2.2/pyproject.toml +25 -0
- python_mpv_jsonipc-1.2.2/python_mpv_jsonipc.egg-info/PKG-INFO +70 -0
- {python-mpv-jsonipc-1.2.0 → python_mpv_jsonipc-1.2.2}/python_mpv_jsonipc.egg-info/SOURCES.txt +2 -1
- {python-mpv-jsonipc-1.2.0 → python_mpv_jsonipc-1.2.2}/python_mpv_jsonipc.py +35 -23
- python-mpv-jsonipc-1.2.0/PKG-INFO +0 -71
- python-mpv-jsonipc-1.2.0/python_mpv_jsonipc.egg-info/PKG-INFO +0 -71
- python-mpv-jsonipc-1.2.0/setup.py +0 -25
- {python-mpv-jsonipc-1.2.0 → python_mpv_jsonipc-1.2.2}/README.md +0 -0
- {python-mpv-jsonipc-1.2.0 → python_mpv_jsonipc-1.2.2}/python_mpv_jsonipc.egg-info/dependency_links.txt +0 -0
- {python-mpv-jsonipc-1.2.0 → python_mpv_jsonipc-1.2.2}/python_mpv_jsonipc.egg-info/top_level.txt +0 -0
- {python-mpv-jsonipc-1.2.0 → python_mpv_jsonipc-1.2.2}/setup.cfg +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
_Version 2.0, January 2004_
|
|
5
|
+
_<<http://www.apache.org/licenses/>>_
|
|
6
|
+
|
|
7
|
+
### Terms and Conditions for use, reproduction, and distribution
|
|
8
|
+
|
|
9
|
+
#### 1. Definitions
|
|
10
|
+
|
|
11
|
+
“License” shall mean the terms and conditions for use, reproduction, and
|
|
12
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
“Licensor” shall mean the copyright owner or entity authorized by the copyright
|
|
15
|
+
owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
“Legal Entity” shall mean the union of the acting entity and all other entities
|
|
18
|
+
that control, are controlled by, or are under common control with that entity.
|
|
19
|
+
For the purposes of this definition, “control” means **(i)** the power, direct or
|
|
20
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
21
|
+
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or **(iii)** beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
“You” (or “Your”) shall mean an individual or Legal Entity exercising
|
|
25
|
+
permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
“Source” form shall mean the preferred form for making modifications, including
|
|
28
|
+
but not limited to software source code, documentation source, and configuration
|
|
29
|
+
files.
|
|
30
|
+
|
|
31
|
+
“Object” form shall mean any form resulting from mechanical transformation or
|
|
32
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
33
|
+
generated documentation, and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
“Work” shall mean the work of authorship, whether in Source or Object form, made
|
|
36
|
+
available under the License, as indicated by a copyright notice that is included
|
|
37
|
+
in or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
“Derivative Works” shall mean any work, whether in Source or Object form, that
|
|
40
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
41
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
42
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
43
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
44
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
45
|
+
|
|
46
|
+
“Contribution” shall mean any work of authorship, including the original version
|
|
47
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
48
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
|
49
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
|
50
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
|
51
|
+
“submitted” means any form of electronic, verbal, or written communication sent
|
|
52
|
+
to the Licensor or its representatives, including but not limited to
|
|
53
|
+
communication on electronic mailing lists, source code control systems, and
|
|
54
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
|
55
|
+
the purpose of discussing and improving the Work, but excluding communication
|
|
56
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
57
|
+
owner as “Not a Contribution.”
|
|
58
|
+
|
|
59
|
+
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
|
|
60
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
61
|
+
incorporated within the Work.
|
|
62
|
+
|
|
63
|
+
#### 2. Grant of Copyright License
|
|
64
|
+
|
|
65
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
66
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
67
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
|
68
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
|
69
|
+
Derivative Works in Source or Object form.
|
|
70
|
+
|
|
71
|
+
#### 3. Grant of Patent License
|
|
72
|
+
|
|
73
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
74
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
75
|
+
irrevocable (except as stated in this section) patent license to make, have
|
|
76
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
|
77
|
+
such license applies only to those patent claims licensable by such Contributor
|
|
78
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
|
79
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
|
80
|
+
submitted. If You institute patent litigation against any entity (including a
|
|
81
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
82
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
|
83
|
+
patent infringement, then any patent licenses granted to You under this License
|
|
84
|
+
for that Work shall terminate as of the date such litigation is filed.
|
|
85
|
+
|
|
86
|
+
#### 4. Redistribution
|
|
87
|
+
|
|
88
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
|
89
|
+
in any medium, with or without modifications, and in Source or Object form,
|
|
90
|
+
provided that You meet the following conditions:
|
|
91
|
+
|
|
92
|
+
* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
|
|
93
|
+
this License; and
|
|
94
|
+
* **(b)** You must cause any modified files to carry prominent notices stating that You
|
|
95
|
+
changed the files; and
|
|
96
|
+
* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
|
|
97
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
|
98
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
|
99
|
+
Derivative Works; and
|
|
100
|
+
* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
|
|
101
|
+
Derivative Works that You distribute must include a readable copy of the
|
|
102
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
103
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
104
|
+
following places: within a NOTICE text file distributed as part of the
|
|
105
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
106
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
107
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
|
108
|
+
the NOTICE file are for informational purposes only and do not modify the
|
|
109
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
110
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
111
|
+
provided that such additional attribution notices cannot be construed as
|
|
112
|
+
modifying the License.
|
|
113
|
+
|
|
114
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
115
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
116
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
117
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
118
|
+
with the conditions stated in this License.
|
|
119
|
+
|
|
120
|
+
#### 5. Submission of Contributions
|
|
121
|
+
|
|
122
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
|
123
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
|
124
|
+
conditions of this License, without any additional terms or conditions.
|
|
125
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
|
126
|
+
any separate license agreement you may have executed with Licensor regarding
|
|
127
|
+
such Contributions.
|
|
128
|
+
|
|
129
|
+
#### 6. Trademarks
|
|
130
|
+
|
|
131
|
+
This License does not grant permission to use the trade names, trademarks,
|
|
132
|
+
service marks, or product names of the Licensor, except as required for
|
|
133
|
+
reasonable and customary use in describing the origin of the Work and
|
|
134
|
+
reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
#### 7. Disclaimer of Warranty
|
|
137
|
+
|
|
138
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
|
139
|
+
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
|
|
140
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
|
141
|
+
including, without limitation, any warranties or conditions of TITLE,
|
|
142
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
|
143
|
+
solely responsible for determining the appropriateness of using or
|
|
144
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
|
145
|
+
permissions under this License.
|
|
146
|
+
|
|
147
|
+
#### 8. Limitation of Liability
|
|
148
|
+
|
|
149
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
|
150
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
151
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
|
152
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
|
153
|
+
or consequential damages of any character arising as a result of this License or
|
|
154
|
+
out of the use or inability to use the Work (including but not limited to
|
|
155
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
|
156
|
+
any and all other commercial damages or losses), even if such Contributor has
|
|
157
|
+
been advised of the possibility of such damages.
|
|
158
|
+
|
|
159
|
+
#### 9. Accepting Warranty or Additional Liability
|
|
160
|
+
|
|
161
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
|
162
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
|
163
|
+
other liability obligations and/or rights consistent with this License. However,
|
|
164
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
|
165
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
|
166
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
|
167
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
168
|
+
accepting any such warranty or additional liability.
|
|
169
|
+
|
|
170
|
+
_END OF TERMS AND CONDITIONS_
|
|
171
|
+
|
|
172
|
+
### APPENDIX: How to apply the Apache License to your work
|
|
173
|
+
|
|
174
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
175
|
+
notice, with the fields enclosed by brackets `[]` replaced with your own
|
|
176
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
177
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
178
|
+
recommend that a file or class name and description of purpose be included on
|
|
179
|
+
the same “printed page” as the copyright notice for easier identification within
|
|
180
|
+
third-party archives.
|
|
181
|
+
|
|
182
|
+
Copyright [yyyy] [name of copyright owner]
|
|
183
|
+
|
|
184
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
185
|
+
you may not use this file except in compliance with the License.
|
|
186
|
+
You may obtain a copy of the License at
|
|
187
|
+
|
|
188
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
189
|
+
|
|
190
|
+
Unless required by applicable law or agreed to in writing, software
|
|
191
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
192
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
193
|
+
See the License for the specific language governing permissions and
|
|
194
|
+
limitations under the License.
|
|
195
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-mpv-jsonipc
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: Python API to MPV using JSON IPC
|
|
5
|
+
Author-email: Izzie Walton <izzie@iwalton.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/iwalton3/python-mpv-jsonipc
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.md
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# Python MPV JSONIPC
|
|
16
|
+
|
|
17
|
+
This implements an interface similar to `python-mpv`, but it uses the JSON IPC protocol instead of the C API. This means
|
|
18
|
+
you can control external instances of MPV including players like SMPlayer, and it can use MPV players that are prebuilt
|
|
19
|
+
instead of needing `libmpv1`. It may also be more resistant to crashes such as Segmentation Faults, but since it isn't
|
|
20
|
+
directly communicating with MPV via the C API the performance will be worse.
|
|
21
|
+
|
|
22
|
+
Please note that this only implements the subset of `python-mpv` that is used by `plex-mpv-shim` and
|
|
23
|
+
`jellyfin-mpv-shim`. Other functionality has not been implemented.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
sudo pip3 install python-mpv-jsonipc
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Basic usage
|
|
32
|
+
|
|
33
|
+
Create an instance of MPV. You can use an already running MPV or have the library start a
|
|
34
|
+
managed copy of MPV. Command arguments can be specified when initializing MPV if you are
|
|
35
|
+
starting a managed copy of MPV.
|
|
36
|
+
|
|
37
|
+
Please also see the [API Documentation](https://github.com/iwalton3/python-mpv-jsonipc/blob/master/docs.md).
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from python_mpv_jsonipc import MPV
|
|
41
|
+
|
|
42
|
+
# Uses MPV that is in the PATH.
|
|
43
|
+
mpv = MPV()
|
|
44
|
+
|
|
45
|
+
# Use MPV that is running and connected to /tmp/mpv-socket.
|
|
46
|
+
mpv = MPV(start_mpv=False, ipc_socket="/tmp/mpv-socket")
|
|
47
|
+
|
|
48
|
+
# Uses MPV that is found at /path/to/mpv.
|
|
49
|
+
mpv = MPV(mpv_location="/path/to/mpv")
|
|
50
|
+
|
|
51
|
+
# After you have an MPV, you can read and set (if applicable) properties.
|
|
52
|
+
mpv.volume # 100.0 by default
|
|
53
|
+
mpv.volume = 20
|
|
54
|
+
|
|
55
|
+
# You can also send commands.
|
|
56
|
+
mpv.command_name(arg1, arg2)
|
|
57
|
+
|
|
58
|
+
# Bind to key press events with a decorator
|
|
59
|
+
@mpv.on_key_press("space")
|
|
60
|
+
def space_handler():
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
# You can also observe and wait for properties.
|
|
64
|
+
@mpv.property_observer("eof-reached")
|
|
65
|
+
def handle_eof(name, value):
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
# Or simply wait for the value to change once.
|
|
69
|
+
mpv.wait_for_property("duration")
|
|
70
|
+
```
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "python-mpv-jsonipc"
|
|
7
|
+
version = "1.2.2"
|
|
8
|
+
description = "Python API to MPV using JSON IPC"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE.md"]
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Izzie Walton", email = "izzie@iwalton.com" },
|
|
14
|
+
]
|
|
15
|
+
requires-python = ">=3.6"
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/iwalton3/python-mpv-jsonipc"
|
|
23
|
+
|
|
24
|
+
[tool.setuptools]
|
|
25
|
+
py-modules = ["python_mpv_jsonipc"]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: python-mpv-jsonipc
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: Python API to MPV using JSON IPC
|
|
5
|
+
Author-email: Izzie Walton <izzie@iwalton.com>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/iwalton3/python-mpv-jsonipc
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.6
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE.md
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# Python MPV JSONIPC
|
|
16
|
+
|
|
17
|
+
This implements an interface similar to `python-mpv`, but it uses the JSON IPC protocol instead of the C API. This means
|
|
18
|
+
you can control external instances of MPV including players like SMPlayer, and it can use MPV players that are prebuilt
|
|
19
|
+
instead of needing `libmpv1`. It may also be more resistant to crashes such as Segmentation Faults, but since it isn't
|
|
20
|
+
directly communicating with MPV via the C API the performance will be worse.
|
|
21
|
+
|
|
22
|
+
Please note that this only implements the subset of `python-mpv` that is used by `plex-mpv-shim` and
|
|
23
|
+
`jellyfin-mpv-shim`. Other functionality has not been implemented.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
sudo pip3 install python-mpv-jsonipc
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Basic usage
|
|
32
|
+
|
|
33
|
+
Create an instance of MPV. You can use an already running MPV or have the library start a
|
|
34
|
+
managed copy of MPV. Command arguments can be specified when initializing MPV if you are
|
|
35
|
+
starting a managed copy of MPV.
|
|
36
|
+
|
|
37
|
+
Please also see the [API Documentation](https://github.com/iwalton3/python-mpv-jsonipc/blob/master/docs.md).
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from python_mpv_jsonipc import MPV
|
|
41
|
+
|
|
42
|
+
# Uses MPV that is in the PATH.
|
|
43
|
+
mpv = MPV()
|
|
44
|
+
|
|
45
|
+
# Use MPV that is running and connected to /tmp/mpv-socket.
|
|
46
|
+
mpv = MPV(start_mpv=False, ipc_socket="/tmp/mpv-socket")
|
|
47
|
+
|
|
48
|
+
# Uses MPV that is found at /path/to/mpv.
|
|
49
|
+
mpv = MPV(mpv_location="/path/to/mpv")
|
|
50
|
+
|
|
51
|
+
# After you have an MPV, you can read and set (if applicable) properties.
|
|
52
|
+
mpv.volume # 100.0 by default
|
|
53
|
+
mpv.volume = 20
|
|
54
|
+
|
|
55
|
+
# You can also send commands.
|
|
56
|
+
mpv.command_name(arg1, arg2)
|
|
57
|
+
|
|
58
|
+
# Bind to key press events with a decorator
|
|
59
|
+
@mpv.on_key_press("space")
|
|
60
|
+
def space_handler():
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
# You can also observe and wait for properties.
|
|
64
|
+
@mpv.property_observer("eof-reached")
|
|
65
|
+
def handle_eof(name, value):
|
|
66
|
+
pass
|
|
67
|
+
|
|
68
|
+
# Or simply wait for the value to change once.
|
|
69
|
+
mpv.wait_for_property("duration")
|
|
70
|
+
```
|
|
@@ -38,7 +38,7 @@ class MPVError(Exception):
|
|
|
38
38
|
class WindowsSocket(threading.Thread):
|
|
39
39
|
"""
|
|
40
40
|
Wraps a Windows named pipe in a high-level interface. (Internal)
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
Data is automatically encoded and decoded as JSON. The callback
|
|
43
43
|
function will be called for each inbound message.
|
|
44
44
|
"""
|
|
@@ -52,7 +52,8 @@ class WindowsSocket(threading.Thread):
|
|
|
52
52
|
ipc_socket = "\\\\.\\pipe\\" + ipc_socket
|
|
53
53
|
self.callback = callback
|
|
54
54
|
self.quit_callback = quit_callback
|
|
55
|
-
|
|
55
|
+
self._stopping = False
|
|
56
|
+
|
|
56
57
|
access = _winapi.GENERIC_READ | _winapi.GENERIC_WRITE
|
|
57
58
|
limit = 5 # Connection may fail at first. Try 5 times.
|
|
58
59
|
for _ in range(limit):
|
|
@@ -72,9 +73,11 @@ class WindowsSocket(threading.Thread):
|
|
|
72
73
|
self.callback = lambda data: None
|
|
73
74
|
|
|
74
75
|
threading.Thread.__init__(self)
|
|
76
|
+
self.daemon = True
|
|
75
77
|
|
|
76
78
|
def stop(self, join=True):
|
|
77
79
|
"""Terminate the thread."""
|
|
80
|
+
self._stopping = True
|
|
78
81
|
if self.socket is not None:
|
|
79
82
|
try:
|
|
80
83
|
self.socket.close()
|
|
@@ -116,14 +119,16 @@ class WindowsSocket(threading.Thread):
|
|
|
116
119
|
if self.quit_callback:
|
|
117
120
|
self.quit_callback()
|
|
118
121
|
except Exception as ex:
|
|
119
|
-
log
|
|
122
|
+
# Only log if not intentionally stopping
|
|
123
|
+
if not self._stopping:
|
|
124
|
+
log.error("Pipe connection died.", exc_info=1)
|
|
120
125
|
if self.quit_callback:
|
|
121
126
|
self.quit_callback()
|
|
122
127
|
|
|
123
128
|
class UnixSocket(threading.Thread):
|
|
124
129
|
"""
|
|
125
130
|
Wraps a Unix/Linux socket in a high-level interface. (Internal)
|
|
126
|
-
|
|
131
|
+
|
|
127
132
|
Data is automatically encoded and decoded as JSON. The callback
|
|
128
133
|
function will be called for each inbound message.
|
|
129
134
|
"""
|
|
@@ -137,6 +142,7 @@ class UnixSocket(threading.Thread):
|
|
|
137
142
|
self.ipc_socket = ipc_socket
|
|
138
143
|
self.callback = callback
|
|
139
144
|
self.quit_callback = quit_callback
|
|
145
|
+
self._stopping = False
|
|
140
146
|
self.socket = socket.socket(socket.AF_UNIX)
|
|
141
147
|
self.socket.connect(self.ipc_socket)
|
|
142
148
|
|
|
@@ -144,9 +150,11 @@ class UnixSocket(threading.Thread):
|
|
|
144
150
|
self.callback = lambda data: None
|
|
145
151
|
|
|
146
152
|
threading.Thread.__init__(self)
|
|
153
|
+
self.daemon = True
|
|
147
154
|
|
|
148
155
|
def stop(self, join=True):
|
|
149
156
|
"""Terminate the thread."""
|
|
157
|
+
self._stopping = True
|
|
150
158
|
if self.socket is not None:
|
|
151
159
|
try:
|
|
152
160
|
self.socket.shutdown(socket.SHUT_WR)
|
|
@@ -184,7 +192,9 @@ class UnixSocket(threading.Thread):
|
|
|
184
192
|
self.callback(json_data)
|
|
185
193
|
data = b''
|
|
186
194
|
except Exception as ex:
|
|
187
|
-
log
|
|
195
|
+
# Only log if not intentionally stopping
|
|
196
|
+
if not self._stopping:
|
|
197
|
+
log.error("Socket connection died.", exc_info=1)
|
|
188
198
|
if self.quit_callback:
|
|
189
199
|
self.quit_callback()
|
|
190
200
|
|
|
@@ -206,7 +216,7 @@ class MPVProcess:
|
|
|
206
216
|
mpv_location = "mpv.exe"
|
|
207
217
|
else:
|
|
208
218
|
mpv_location = "mpv"
|
|
209
|
-
|
|
219
|
+
|
|
210
220
|
log.debug("Staring MPV from {0}.".format(mpv_location))
|
|
211
221
|
ipc_socket_name = ipc_socket
|
|
212
222
|
if os.name == 'nt':
|
|
@@ -248,7 +258,7 @@ class MPVProcess:
|
|
|
248
258
|
else:
|
|
249
259
|
self.process.terminate()
|
|
250
260
|
raise MPVError("MPV start timed out.")
|
|
251
|
-
|
|
261
|
+
|
|
252
262
|
if not ipc_exists or self.process.returncode is not None:
|
|
253
263
|
self.process.terminate()
|
|
254
264
|
raise MPVError("MPV not started.")
|
|
@@ -290,7 +300,7 @@ class MPVInter:
|
|
|
290
300
|
self.quit_callback = quit_callback
|
|
291
301
|
if self.callback is None:
|
|
292
302
|
self.callback = lambda event, data: None
|
|
293
|
-
|
|
303
|
+
|
|
294
304
|
self.socket = Socket(ipc_socket, self.event_callback, self.quit_callback)
|
|
295
305
|
self.socket.start()
|
|
296
306
|
self.command_id = 1
|
|
@@ -298,7 +308,7 @@ class MPVInter:
|
|
|
298
308
|
self.socket_lock = threading.Lock()
|
|
299
309
|
self.cid_result = {}
|
|
300
310
|
self.cid_wait = {}
|
|
301
|
-
|
|
311
|
+
|
|
302
312
|
def stop(self, join=True):
|
|
303
313
|
"""Terminate the underlying connection."""
|
|
304
314
|
self.socket.stop(join)
|
|
@@ -310,11 +320,11 @@ class MPVInter:
|
|
|
310
320
|
self.cid_wait[data["request_id"]].set()
|
|
311
321
|
elif "event" in data:
|
|
312
322
|
self.callback(data["event"], data)
|
|
313
|
-
|
|
323
|
+
|
|
314
324
|
def command(self, command, *args):
|
|
315
325
|
"""
|
|
316
326
|
Issue a command to MPV. Will block until completed or timeout is reached.
|
|
317
|
-
|
|
327
|
+
|
|
318
328
|
*command* is the name of the MPV command
|
|
319
329
|
|
|
320
330
|
All further arguments are forwarded to the MPV command.
|
|
@@ -356,13 +366,14 @@ class EventHandler(threading.Thread):
|
|
|
356
366
|
"""Create an instance of the thread."""
|
|
357
367
|
self.queue = queue.Queue()
|
|
358
368
|
threading.Thread.__init__(self)
|
|
359
|
-
|
|
369
|
+
self.daemon = True
|
|
370
|
+
|
|
360
371
|
def put_task(self, func, *args):
|
|
361
372
|
"""
|
|
362
373
|
Put a new task to the thread.
|
|
363
|
-
|
|
374
|
+
|
|
364
375
|
*func* is the function to call
|
|
365
|
-
|
|
376
|
+
|
|
366
377
|
All further arguments are forwarded to *func*.
|
|
367
378
|
"""
|
|
368
379
|
self.queue.put((func, args))
|
|
@@ -386,15 +397,15 @@ class EventHandler(threading.Thread):
|
|
|
386
397
|
class MPV:
|
|
387
398
|
"""
|
|
388
399
|
The main MPV interface class. Use this to control MPV.
|
|
389
|
-
|
|
400
|
+
|
|
390
401
|
This will expose all mpv commands as callable methods and all properties.
|
|
391
402
|
You can set properties and call the commands directly.
|
|
392
|
-
|
|
403
|
+
|
|
393
404
|
Please note that if you are using a really old MPV version, a fallback command
|
|
394
405
|
list is used. Not all commands may actually work when this fallback is used.
|
|
395
406
|
"""
|
|
396
407
|
def __init__(self, start_mpv=True, ipc_socket=None, mpv_location=None,
|
|
397
|
-
log_handler=None, loglevel=None, quit_callback=None, **kwargs):
|
|
408
|
+
log_handler=None, loglevel=None, quit_callback=None, start_retries=5, start_retry_delay_ms=1000, **kwargs):
|
|
398
409
|
"""
|
|
399
410
|
Create the interface to MPV and process instance.
|
|
400
411
|
|
|
@@ -424,13 +435,14 @@ class MPV:
|
|
|
424
435
|
ipc_socket = "/tmp/{0}".format(rand_file)
|
|
425
436
|
|
|
426
437
|
if start_mpv:
|
|
427
|
-
# Attempt to start MPV
|
|
428
|
-
for i in range(
|
|
438
|
+
# Attempt to start MPV multiple times.
|
|
439
|
+
for i in range(start_retries):
|
|
429
440
|
try:
|
|
430
441
|
self.mpv_process = MPVProcess(ipc_socket, mpv_location, **kwargs)
|
|
431
442
|
break
|
|
432
443
|
except MPVError:
|
|
433
444
|
log.warning("MPV start failed.", exc_info=1)
|
|
445
|
+
time.sleep(start_retry_delay_ms / 1000)
|
|
434
446
|
continue
|
|
435
447
|
else:
|
|
436
448
|
raise MPVError("MPV process retry limit reached.")
|
|
@@ -455,7 +467,7 @@ class MPV:
|
|
|
455
467
|
self.observer_lock = threading.Lock()
|
|
456
468
|
self.keybind_id = 1
|
|
457
469
|
self.keybind_lock = threading.Lock()
|
|
458
|
-
|
|
470
|
+
|
|
459
471
|
if log_handler is not None and loglevel is not None:
|
|
460
472
|
self.command("request_log_messages", loglevel)
|
|
461
473
|
@self.on_event("log-message")
|
|
@@ -582,7 +594,7 @@ class MPV:
|
|
|
582
594
|
self.bind_property_observer(name, func)
|
|
583
595
|
return func
|
|
584
596
|
return wrapper
|
|
585
|
-
|
|
597
|
+
|
|
586
598
|
def wait_for_property(self, name):
|
|
587
599
|
"""
|
|
588
600
|
Waits for the value of a property to change.
|
|
@@ -630,11 +642,11 @@ class MPV:
|
|
|
630
642
|
"""
|
|
631
643
|
Send a command to MPV. All commands are bound to the class by default,
|
|
632
644
|
except JSON IPC specific commands. This may also be useful to retain
|
|
633
|
-
compatibility with python-mpv, as it does not bind all of the commands.
|
|
645
|
+
compatibility with python-mpv, as it does not bind all of the commands.
|
|
634
646
|
|
|
635
647
|
*command* is the command name.
|
|
636
648
|
|
|
637
|
-
All further arguments are forwarded to the MPV command.
|
|
649
|
+
All further arguments are forwarded to the MPV command.
|
|
638
650
|
"""
|
|
639
651
|
return self.mpv_inter.command(command, *args)
|
|
640
652
|
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: python-mpv-jsonipc
|
|
3
|
-
Version: 1.2.0
|
|
4
|
-
Summary: Python API to MPV using JSON IPC
|
|
5
|
-
Home-page: https://github.com/iwalton3/python-mpv-jsonipc
|
|
6
|
-
Author: Ian Walton
|
|
7
|
-
Author-email: iwalton3@gmail.com
|
|
8
|
-
License: Apache-2.0
|
|
9
|
-
Description: # Python MPV JSONIPC
|
|
10
|
-
|
|
11
|
-
This implements an interface similar to `python-mpv`, but it uses the JSON IPC protocol instead of the C API. This means
|
|
12
|
-
you can control external instances of MPV including players like SMPlayer, and it can use MPV players that are prebuilt
|
|
13
|
-
instead of needing `libmpv1`. It may also be more resistant to crashes such as Segmentation Faults, but since it isn't
|
|
14
|
-
directly communicating with MPV via the C API the performance will be worse.
|
|
15
|
-
|
|
16
|
-
Please note that this only implements the subset of `python-mpv` that is used by `plex-mpv-shim` and
|
|
17
|
-
`jellyfin-mpv-shim`. Other functionality has not been implemented.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
sudo pip3 install python-mpv-jsonipc
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Basic usage
|
|
26
|
-
|
|
27
|
-
Create an instance of MPV. You can use an already running MPV or have the library start a
|
|
28
|
-
managed copy of MPV. Command arguments can be specified when initializing MPV if you are
|
|
29
|
-
starting a managed copy of MPV.
|
|
30
|
-
|
|
31
|
-
Please also see the [API Documentation](https://github.com/iwalton3/python-mpv-jsonipc/blob/master/docs.md).
|
|
32
|
-
|
|
33
|
-
```python
|
|
34
|
-
from python_mpv_jsonipc import MPV
|
|
35
|
-
|
|
36
|
-
# Uses MPV that is in the PATH.
|
|
37
|
-
mpv = MPV()
|
|
38
|
-
|
|
39
|
-
# Use MPV that is running and connected to /tmp/mpv-socket.
|
|
40
|
-
mpv = MPV(start_mpv=False, ipc_socket="/tmp/mpv-socket")
|
|
41
|
-
|
|
42
|
-
# Uses MPV that is found at /path/to/mpv.
|
|
43
|
-
mpv = MPV(mpv_location="/path/to/mpv")
|
|
44
|
-
|
|
45
|
-
# After you have an MPV, you can read and set (if applicable) properties.
|
|
46
|
-
mpv.volume # 100.0 by default
|
|
47
|
-
mpv.volume = 20
|
|
48
|
-
|
|
49
|
-
# You can also send commands.
|
|
50
|
-
mpv.command_name(arg1, arg2)
|
|
51
|
-
|
|
52
|
-
# Bind to key press events with a decorator
|
|
53
|
-
@mpv.on_key_press("space")
|
|
54
|
-
def space_handler():
|
|
55
|
-
pass
|
|
56
|
-
|
|
57
|
-
# You can also observe and wait for properties.
|
|
58
|
-
@mpv.property_observer("eof-reached")
|
|
59
|
-
def handle_eof(name, value):
|
|
60
|
-
pass
|
|
61
|
-
|
|
62
|
-
# Or simply wait for the value to change once.
|
|
63
|
-
mpv.wait_for_property("duration")
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Platform: UNKNOWN
|
|
67
|
-
Classifier: Programming Language :: Python :: 3
|
|
68
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
69
|
-
Classifier: Operating System :: OS Independent
|
|
70
|
-
Requires-Python: >=3.6
|
|
71
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: python-mpv-jsonipc
|
|
3
|
-
Version: 1.2.0
|
|
4
|
-
Summary: Python API to MPV using JSON IPC
|
|
5
|
-
Home-page: https://github.com/iwalton3/python-mpv-jsonipc
|
|
6
|
-
Author: Ian Walton
|
|
7
|
-
Author-email: iwalton3@gmail.com
|
|
8
|
-
License: Apache-2.0
|
|
9
|
-
Description: # Python MPV JSONIPC
|
|
10
|
-
|
|
11
|
-
This implements an interface similar to `python-mpv`, but it uses the JSON IPC protocol instead of the C API. This means
|
|
12
|
-
you can control external instances of MPV including players like SMPlayer, and it can use MPV players that are prebuilt
|
|
13
|
-
instead of needing `libmpv1`. It may also be more resistant to crashes such as Segmentation Faults, but since it isn't
|
|
14
|
-
directly communicating with MPV via the C API the performance will be worse.
|
|
15
|
-
|
|
16
|
-
Please note that this only implements the subset of `python-mpv` that is used by `plex-mpv-shim` and
|
|
17
|
-
`jellyfin-mpv-shim`. Other functionality has not been implemented.
|
|
18
|
-
|
|
19
|
-
## Installation
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
sudo pip3 install python-mpv-jsonipc
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Basic usage
|
|
26
|
-
|
|
27
|
-
Create an instance of MPV. You can use an already running MPV or have the library start a
|
|
28
|
-
managed copy of MPV. Command arguments can be specified when initializing MPV if you are
|
|
29
|
-
starting a managed copy of MPV.
|
|
30
|
-
|
|
31
|
-
Please also see the [API Documentation](https://github.com/iwalton3/python-mpv-jsonipc/blob/master/docs.md).
|
|
32
|
-
|
|
33
|
-
```python
|
|
34
|
-
from python_mpv_jsonipc import MPV
|
|
35
|
-
|
|
36
|
-
# Uses MPV that is in the PATH.
|
|
37
|
-
mpv = MPV()
|
|
38
|
-
|
|
39
|
-
# Use MPV that is running and connected to /tmp/mpv-socket.
|
|
40
|
-
mpv = MPV(start_mpv=False, ipc_socket="/tmp/mpv-socket")
|
|
41
|
-
|
|
42
|
-
# Uses MPV that is found at /path/to/mpv.
|
|
43
|
-
mpv = MPV(mpv_location="/path/to/mpv")
|
|
44
|
-
|
|
45
|
-
# After you have an MPV, you can read and set (if applicable) properties.
|
|
46
|
-
mpv.volume # 100.0 by default
|
|
47
|
-
mpv.volume = 20
|
|
48
|
-
|
|
49
|
-
# You can also send commands.
|
|
50
|
-
mpv.command_name(arg1, arg2)
|
|
51
|
-
|
|
52
|
-
# Bind to key press events with a decorator
|
|
53
|
-
@mpv.on_key_press("space")
|
|
54
|
-
def space_handler():
|
|
55
|
-
pass
|
|
56
|
-
|
|
57
|
-
# You can also observe and wait for properties.
|
|
58
|
-
@mpv.property_observer("eof-reached")
|
|
59
|
-
def handle_eof(name, value):
|
|
60
|
-
pass
|
|
61
|
-
|
|
62
|
-
# Or simply wait for the value to change once.
|
|
63
|
-
mpv.wait_for_property("duration")
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
Platform: UNKNOWN
|
|
67
|
-
Classifier: Programming Language :: Python :: 3
|
|
68
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
69
|
-
Classifier: Operating System :: OS Independent
|
|
70
|
-
Requires-Python: >=3.6
|
|
71
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
from setuptools import setup
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
with open("README.md", "r") as fh:
|
|
5
|
-
long_description = fh.read()
|
|
6
|
-
|
|
7
|
-
setup(
|
|
8
|
-
name='python-mpv-jsonipc',
|
|
9
|
-
version='1.2.0',
|
|
10
|
-
author="Ian Walton",
|
|
11
|
-
author_email="iwalton3@gmail.com",
|
|
12
|
-
description="Python API to MPV using JSON IPC",
|
|
13
|
-
license='Apache-2.0',
|
|
14
|
-
long_description=open('README.md').read(),
|
|
15
|
-
long_description_content_type="text/markdown",
|
|
16
|
-
url="https://github.com/iwalton3/python-mpv-jsonipc",
|
|
17
|
-
py_modules=['python_mpv_jsonipc'],
|
|
18
|
-
classifiers=[
|
|
19
|
-
"Programming Language :: Python :: 3",
|
|
20
|
-
"License :: OSI Approved :: Apache Software License",
|
|
21
|
-
"Operating System :: OS Independent",
|
|
22
|
-
],
|
|
23
|
-
python_requires='>=3.6',
|
|
24
|
-
install_requires=[]
|
|
25
|
-
)
|
|
File without changes
|
|
File without changes
|
{python-mpv-jsonipc-1.2.0 → python_mpv_jsonipc-1.2.2}/python_mpv_jsonipc.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|