mediaflow-proxy 1.4.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2024] [Mohamed Zumair]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,297 @@
1
+ Metadata-Version: 2.1
2
+ Name: mediaflow-proxy
3
+ Version: 1.4.2
4
+ Summary: A high-performance proxy server for streaming media, supporting HTTP(S), HLS, and MPEG-DASH with real-time DRM decryption.
5
+ Home-page: https://github.com/mhdzumair/mediaflow-proxy
6
+ License: MIT
7
+ Keywords: proxy,media,streaming,hls,dash,drm
8
+ Author: mhdzumair
9
+ Author-email: mhdzumair@gmail.com
10
+ Requires-Python: >=3.12,<4.0
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Requires-Dist: cachetools (>=5.4.0,<6.0.0)
19
+ Requires-Dist: fastapi (>=0.112.2,<0.113.0)
20
+ Requires-Dist: gunicorn (>=23.0.0,<24.0.0)
21
+ Requires-Dist: httpx[socks] (>=0.27.2,<0.28.0)
22
+ Requires-Dist: pycryptodome (>=3.20.0,<4.0.0)
23
+ Requires-Dist: pydantic-settings (>=2.4.0,<3.0.0)
24
+ Requires-Dist: tenacity (>=9.0.0,<10.0.0)
25
+ Requires-Dist: uvicorn (>=0.30.6,<0.31.0)
26
+ Requires-Dist: xmltodict (>=0.13.0,<0.14.0)
27
+ Project-URL: Documentation, https://github.com/mhdzumair/mediaflow-proxy#readme
28
+ Project-URL: Repository, https://github.com/mhdzumair/mediaflow-proxy
29
+ Description-Content-Type: text/markdown
30
+
31
+ ---
32
+ title: MediaFlow Proxy
33
+ emoji: 🎥
34
+ colorFrom: blue
35
+ colorTo: green
36
+ sdk: docker
37
+ app_port: 8888
38
+ pinned: false
39
+ license: mit
40
+ thumbnail: >-
41
+ https://cdn.githubraw.com/mhdzumair/mediaflow-proxy/main/mediaflow_proxy/static/logo.png
42
+ ---
43
+
44
+
45
+ # MediaFlow Proxy
46
+
47
+ <div style="text-align: center;">
48
+ <img src="https://cdn.githubraw.com/mhdzumair/mediaflow-proxy/main/mediaflow_proxy/static/logo.png" alt="MediaFlow Proxy Logo" width="200" style="border-radius: 15px;">
49
+ </div>
50
+
51
+ MediaFlow Proxy is a powerful and flexible solution for proxifying various types of media streams. It supports HTTP(S) links, HLS (M3U8) streams, and MPEG-DASH streams, including DRM-protected content. This proxy can convert MPEG-DASH DRM-protected streams to decrypted HLS live streams in real-time, making it one of the fastest live decrypter servers available.
52
+
53
+ ## Features
54
+
55
+ - Convert MPEG-DASH streams (DRM-protected and non-protected) to HLS
56
+ - Support for Clear Key DRM-protected MPD DASH streams
57
+ - Support for non-DRM protected DASH live and VOD streams
58
+ - Proxy HTTP/HTTPS links with custom headers
59
+ - Proxy and modify HLS (M3U8) streams in real-time with custom headers and key URL modifications for bypassing some sneaky restrictions.
60
+ - Retrieve public IP address of the MediaFlow Proxy server for use with Debrid services
61
+ - Support for HTTP/HTTPS/SOCKS5 proxy forwarding
62
+ - Protect against unauthorized access and network bandwidth abuses
63
+ - Support for play expired or self-signed SSL certificates server streams
64
+
65
+ ## Configuration
66
+
67
+ Set the following environment variables:
68
+
69
+ - `API_PASSWORD`: Required. Protects against unauthorized access and API network abuses.
70
+ - `PROXY_URL`: Optional. HTTP/HTTPS/SOCKS5 proxy URL for forwarding network requests.
71
+ - `MPD_LIVE_STREAM_DELAY`: Optional. Delay in seconds for live DASH streams. This is useful to prevent buffering issues with live streams. Default is `30` seconds.
72
+
73
+ ## Installation
74
+
75
+ ### Option 1: Self-Hosted Deployment
76
+
77
+ #### Using Docker from Docker Hub
78
+
79
+ 1. Pull & Run the Docker image:
80
+ ```
81
+ docker run -p 8888:8888 -e API_PASSWORD=your_password mhdzumair/mediaflow-proxy
82
+ ```
83
+
84
+ #### Using pip
85
+
86
+ > ![Note]
87
+ > Ensure that you have Python 3.10 or higher installed.
88
+
89
+ 1. Install the package:
90
+ ```
91
+ pip install mediaflow-proxy
92
+ ```
93
+
94
+ 2. Set the `API_PASSWORD` and other environment variables in `.env`:
95
+ ```
96
+ echo "API_PASSWORD=your_password" > .env
97
+ ```
98
+
99
+ 3. Run the MediaFlow Proxy server:
100
+ ```
101
+ mediaflow-proxy
102
+ ```
103
+
104
+
105
+ #### Using git & poetry
106
+
107
+ > ![Note]
108
+ > Ensure that you have Python 3.10 or higher installed.
109
+
110
+
111
+ 1. Clone the repository:
112
+ ```
113
+ git clone https://github.com/mhdzumair/mediaflow-proxy.git
114
+ cd mediaflow-proxy
115
+ ```
116
+
117
+ 2. Install dependencies using Poetry:
118
+ ```
119
+ poetry install
120
+ ```
121
+
122
+ 3. Set the `API_PASSWORD` environment variable in `.env`:
123
+ ```
124
+ echo "API_PASSWORD=your_password" > .env
125
+ ```
126
+
127
+ 4. Run the FastAPI server:
128
+ ```
129
+ poetry run uvicorn mediaflow_proxy.main:app --host 0.0.0.0 --port 8888
130
+ ```
131
+
132
+
133
+ #### Build and Run Docker Image Locally
134
+
135
+ 1. Build the Docker image:
136
+ ```
137
+ docker build -t mediaflow-proxy .
138
+ ```
139
+
140
+ 2. Run the Docker container:
141
+ ```
142
+ docker run -d -p 8888:8888 -e API_PASSWORD=your_password --restart unless-stopped --name mediaflow-proxy mediaflow-proxy
143
+ ```
144
+
145
+ ### Option 2: Premium Hosted Service (ElfHosted)
146
+ <div style="text-align: center;">
147
+ <img src="https://store.elfhosted.com/wp-content/uploads/2024/08/mediaflow-proxy.jpg" alt="ElfHosted Logo" width="200" style="border-radius: 15px;">
148
+ </div>
149
+ For a hassle-free, high-performance deployment of MediaFlow Proxy, consider the premium hosted service through ElfHosted.
150
+
151
+ To purchase:
152
+ 1. Visit [https://store.elfhosted.com/product/mediaflow-proxy](https://store.elfhosted.com/product/mediaflow-proxy)
153
+ 2. Follow ElfHosted's setup instructions
154
+
155
+ Benefits:
156
+ - Instant setup and automatic updates
157
+ - High performance and 24/7 availability
158
+ - No server maintenance required
159
+
160
+ Ideal for users who want a reliable, plug-and-play solution without the technical overhead of self-hosting.
161
+
162
+ ### Option 3: Hugging Face Space Deployment
163
+
164
+ 1. Visit the HF Space: [mhdzumair/mediaflow-proxy](https://huggingface.co/spaces/mhdzumair/mediaflow-proxy)
165
+ 2. Click on three dots on the right side of the page and select "Duplicate Space"
166
+ 3. Set the `API_PASSWORD` secret value & Set Visibility to "Public"
167
+ 4. Click on "Duplicate Space" to deploy the API
168
+
169
+ ## Usage
170
+
171
+ ### Endpoints
172
+
173
+ 1. `/proxy/hls`: Proxify HLS streams
174
+ 2. `/proxy/stream`: Proxy generic http video streams
175
+ 3. `/proxy/mpd/manifest`: Process MPD manifests
176
+ 4. `/proxy/mpd/playlist`: Generate HLS playlists from MPD
177
+ 5. `/proxy/mpd/segment`: Process and decrypt media segments
178
+ 6. `/proxy/ip`: Get the public IP address of the MediaFlow Proxy server
179
+
180
+ Once the server is running, for more details on the available endpoints and their parameters, visit the Swagger UI at `http://localhost:8888/docs`.
181
+
182
+ ### Examples
183
+
184
+ #### Proxy HTTPS Stream
185
+
186
+ ```bash
187
+ mpv "http://localhost:8888/proxy/stream?d=https://jsoncompare.org/LearningContainer/SampleFiles/Video/MP4/sample-mp4-file.mp4&api_password=your_password"
188
+ ```
189
+
190
+ #### Proxy HTTPS self-signed certificate Stream
191
+
192
+ ```bash
193
+ mpv "http://localhost:8888/proxy/stream?d=https://self-signed.badssl.com/&api_password=your_password&verify_ssl=false"
194
+ ```
195
+
196
+
197
+ #### Proxy HLS Stream with Headers
198
+
199
+ ```bash
200
+ mpv "http://localhost:8888/proxy/hls?d=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8&h_referer=https://apple.com/&h_origin=https://apple.com&h_user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36&api_password=your_password"
201
+ ```
202
+
203
+ #### Live DASH Stream (Non-DRM Protected)
204
+
205
+ ```bash
206
+ mpv -v "http://localhost:8888/proxy/mpd/manifest?d=https://livesim.dashif.org/livesim/chunkdur_1/ato_7/testpic4_8s/Manifest.mpd&api_password=your_password"
207
+ ```
208
+
209
+ #### VOD DASH Stream (DRM Protected)
210
+
211
+ ```bash
212
+ mpv -v "http://localhost:8888/proxy/mpd/manifest?d=https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd&key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=your_password"
213
+ ```
214
+
215
+ Note: The `key` and `key_id` parameters are automatically processed if they're not in the correct format.
216
+
217
+ ### URL Encoding
218
+
219
+ For players like VLC that require properly encoded URLs, use the `encode_mediaflow_proxy_url` function:
220
+
221
+ ```python
222
+ from mediaflow_proxy.utils.http_utils import encode_mediaflow_proxy_url
223
+
224
+ encoded_url = encode_mediaflow_proxy_url(
225
+ mediaflow_proxy_url="http://127.0.0.1:8888",
226
+ endpoint="/proxy/mpd/manifest",
227
+ destination_url="https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
228
+ query_params={
229
+ "key_id": "nrQFDeRLSAKTLifXUIPiZg",
230
+ "key": "FmY0xnWCPCNaSpRG-tUuTQ",
231
+ "api_password": "your_password"
232
+ },
233
+ request_headers={
234
+ "referer": "https://media.axprod.net/",
235
+ "origin": "https://media.axprod.net",
236
+ }
237
+ )
238
+
239
+ print(encoded_url)
240
+
241
+ # http://127.0.0.1:8888/proxy/mpd/manifest?key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=your_password&d=https%3A%2F%2Fmedia.axprod.net%2FTestVectors%2Fv7-MultiDRM-SingleKey%2FManifest_1080p_ClearKey.mpd&h_referer=https%3A%2F%2Fmedia.axprod.net%2F&h_origin=https%3A%2F%2Fmedia.axprod.net
242
+ ```
243
+
244
+ This will output a properly encoded URL that can be used with players like VLC.
245
+
246
+ ```bash
247
+ vlc "http://127.0.0.1:8888/proxy/mpd/manifest?key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=dedsec&d=https%3A%2F%2Fmedia.axprod.net%2FTestVectors%2Fv7-MultiDRM-SingleKey%2FManifest_1080p_ClearKey.mpd"
248
+ ```
249
+
250
+ ### Using MediaFlow Proxy with Debrid Services and Stremio Addons
251
+
252
+ MediaFlow Proxy can be particularly useful when working with Debrid services (like Real-Debrid, AllDebrid) and Stremio addons. The `/proxy/ip` endpoint allows you to retrieve the public IP address of the MediaFlow Proxy server, which is crucial for routing Debrid streams correctly.
253
+
254
+ When a Stremio addon needs to create a video URL for a Debrid service, it typically needs to provide the user's public IP address. However, when routing the Debrid stream through MediaFlow Proxy, you should use the IP address of the MediaFlow Proxy server instead.
255
+
256
+ Here's how to utilize MediaFlow Proxy in this scenario:
257
+
258
+ 1. If MediaFlow Proxy is accessible over the internet:
259
+ - Use the `/proxy/ip` endpoint to get the MediaFlow Proxy server's public IP.
260
+ - Use this IP when creating Debrid service URLs in your Stremio addon.
261
+
262
+ 2. If MediaFlow Proxy is set up locally:
263
+ - Stremio addons can directly use the client's IP address.
264
+
265
+
266
+ ## Future Development
267
+
268
+ - Add support for Widevine and PlayReady decryption
269
+
270
+ ## Acknowledgements and Inspirations
271
+
272
+ MediaFlow Proxy was developed with inspiration from various projects and resources:
273
+
274
+ - [Stremio Server](https://github.com/Stremio/stremio-server) for HLS Proxify implementation, which inspired our HLS M3u8 Manifest parsing and redirection proxify support.
275
+ - [Comet Debrid proxy](https://github.com/g0ldyy/comet) for the idea of proxifying HTTPS video streams.
276
+ - [mp4decrypt](https://www.bento4.com/developers/dash/encryption_and_drm/), [mp4box](https://wiki.gpac.io/xmlformats/Common-Encryption/), and [devine](https://github.com/devine-dl/devine) for insights on parsing MPD and decrypting Clear Key DRM protected content.
277
+ - Test URLs were sourced from:
278
+ - [OTTVerse MPEG-DASH MPD Examples](https://ottverse.com/free-mpeg-dash-mpd-manifest-example-test-urls/)
279
+ - [OTTVerse HLS M3U8 Examples](https://ottverse.com/free-hls-m3u8-test-urls/)
280
+ - [Bitmovin Stream Test](https://bitmovin.com/demos/stream-test)
281
+ - [Bitmovin DRM Demo](https://bitmovin.com/demos/drm)
282
+ - [DASH-IF Reference Player](http://reference.dashif.org/dash.js/nightly/samples/)
283
+ - [HLS Protocol RFC](https://www.rfc-editor.org/rfc/rfc8216) for understanding the HLS protocol specifications.
284
+ - Claude 3.5 Sonnet for code assistance and brainstorming.
285
+
286
+ ## Contributing
287
+
288
+ Contributions are welcome! Please feel free to submit a Pull Request.
289
+
290
+ ## License
291
+
292
+ [MIT License](LICENSE)
293
+
294
+
295
+ ## Disclaimer
296
+
297
+ This project is for educational purposes only. The developers of MediaFlow Proxy are not responsible for any misuse of this software. Please ensure that you have the necessary permissions to access and use the media streams you are proxying.
@@ -0,0 +1,267 @@
1
+ ---
2
+ title: MediaFlow Proxy
3
+ emoji: 🎥
4
+ colorFrom: blue
5
+ colorTo: green
6
+ sdk: docker
7
+ app_port: 8888
8
+ pinned: false
9
+ license: mit
10
+ thumbnail: >-
11
+ https://cdn.githubraw.com/mhdzumair/mediaflow-proxy/main/mediaflow_proxy/static/logo.png
12
+ ---
13
+
14
+
15
+ # MediaFlow Proxy
16
+
17
+ <div style="text-align: center;">
18
+ <img src="https://cdn.githubraw.com/mhdzumair/mediaflow-proxy/main/mediaflow_proxy/static/logo.png" alt="MediaFlow Proxy Logo" width="200" style="border-radius: 15px;">
19
+ </div>
20
+
21
+ MediaFlow Proxy is a powerful and flexible solution for proxifying various types of media streams. It supports HTTP(S) links, HLS (M3U8) streams, and MPEG-DASH streams, including DRM-protected content. This proxy can convert MPEG-DASH DRM-protected streams to decrypted HLS live streams in real-time, making it one of the fastest live decrypter servers available.
22
+
23
+ ## Features
24
+
25
+ - Convert MPEG-DASH streams (DRM-protected and non-protected) to HLS
26
+ - Support for Clear Key DRM-protected MPD DASH streams
27
+ - Support for non-DRM protected DASH live and VOD streams
28
+ - Proxy HTTP/HTTPS links with custom headers
29
+ - Proxy and modify HLS (M3U8) streams in real-time with custom headers and key URL modifications for bypassing some sneaky restrictions.
30
+ - Retrieve public IP address of the MediaFlow Proxy server for use with Debrid services
31
+ - Support for HTTP/HTTPS/SOCKS5 proxy forwarding
32
+ - Protect against unauthorized access and network bandwidth abuses
33
+ - Support for play expired or self-signed SSL certificates server streams
34
+
35
+ ## Configuration
36
+
37
+ Set the following environment variables:
38
+
39
+ - `API_PASSWORD`: Required. Protects against unauthorized access and API network abuses.
40
+ - `PROXY_URL`: Optional. HTTP/HTTPS/SOCKS5 proxy URL for forwarding network requests.
41
+ - `MPD_LIVE_STREAM_DELAY`: Optional. Delay in seconds for live DASH streams. This is useful to prevent buffering issues with live streams. Default is `30` seconds.
42
+
43
+ ## Installation
44
+
45
+ ### Option 1: Self-Hosted Deployment
46
+
47
+ #### Using Docker from Docker Hub
48
+
49
+ 1. Pull & Run the Docker image:
50
+ ```
51
+ docker run -p 8888:8888 -e API_PASSWORD=your_password mhdzumair/mediaflow-proxy
52
+ ```
53
+
54
+ #### Using pip
55
+
56
+ > ![Note]
57
+ > Ensure that you have Python 3.10 or higher installed.
58
+
59
+ 1. Install the package:
60
+ ```
61
+ pip install mediaflow-proxy
62
+ ```
63
+
64
+ 2. Set the `API_PASSWORD` and other environment variables in `.env`:
65
+ ```
66
+ echo "API_PASSWORD=your_password" > .env
67
+ ```
68
+
69
+ 3. Run the MediaFlow Proxy server:
70
+ ```
71
+ mediaflow-proxy
72
+ ```
73
+
74
+
75
+ #### Using git & poetry
76
+
77
+ > ![Note]
78
+ > Ensure that you have Python 3.10 or higher installed.
79
+
80
+
81
+ 1. Clone the repository:
82
+ ```
83
+ git clone https://github.com/mhdzumair/mediaflow-proxy.git
84
+ cd mediaflow-proxy
85
+ ```
86
+
87
+ 2. Install dependencies using Poetry:
88
+ ```
89
+ poetry install
90
+ ```
91
+
92
+ 3. Set the `API_PASSWORD` environment variable in `.env`:
93
+ ```
94
+ echo "API_PASSWORD=your_password" > .env
95
+ ```
96
+
97
+ 4. Run the FastAPI server:
98
+ ```
99
+ poetry run uvicorn mediaflow_proxy.main:app --host 0.0.0.0 --port 8888
100
+ ```
101
+
102
+
103
+ #### Build and Run Docker Image Locally
104
+
105
+ 1. Build the Docker image:
106
+ ```
107
+ docker build -t mediaflow-proxy .
108
+ ```
109
+
110
+ 2. Run the Docker container:
111
+ ```
112
+ docker run -d -p 8888:8888 -e API_PASSWORD=your_password --restart unless-stopped --name mediaflow-proxy mediaflow-proxy
113
+ ```
114
+
115
+ ### Option 2: Premium Hosted Service (ElfHosted)
116
+ <div style="text-align: center;">
117
+ <img src="https://store.elfhosted.com/wp-content/uploads/2024/08/mediaflow-proxy.jpg" alt="ElfHosted Logo" width="200" style="border-radius: 15px;">
118
+ </div>
119
+ For a hassle-free, high-performance deployment of MediaFlow Proxy, consider the premium hosted service through ElfHosted.
120
+
121
+ To purchase:
122
+ 1. Visit [https://store.elfhosted.com/product/mediaflow-proxy](https://store.elfhosted.com/product/mediaflow-proxy)
123
+ 2. Follow ElfHosted's setup instructions
124
+
125
+ Benefits:
126
+ - Instant setup and automatic updates
127
+ - High performance and 24/7 availability
128
+ - No server maintenance required
129
+
130
+ Ideal for users who want a reliable, plug-and-play solution without the technical overhead of self-hosting.
131
+
132
+ ### Option 3: Hugging Face Space Deployment
133
+
134
+ 1. Visit the HF Space: [mhdzumair/mediaflow-proxy](https://huggingface.co/spaces/mhdzumair/mediaflow-proxy)
135
+ 2. Click on three dots on the right side of the page and select "Duplicate Space"
136
+ 3. Set the `API_PASSWORD` secret value & Set Visibility to "Public"
137
+ 4. Click on "Duplicate Space" to deploy the API
138
+
139
+ ## Usage
140
+
141
+ ### Endpoints
142
+
143
+ 1. `/proxy/hls`: Proxify HLS streams
144
+ 2. `/proxy/stream`: Proxy generic http video streams
145
+ 3. `/proxy/mpd/manifest`: Process MPD manifests
146
+ 4. `/proxy/mpd/playlist`: Generate HLS playlists from MPD
147
+ 5. `/proxy/mpd/segment`: Process and decrypt media segments
148
+ 6. `/proxy/ip`: Get the public IP address of the MediaFlow Proxy server
149
+
150
+ Once the server is running, for more details on the available endpoints and their parameters, visit the Swagger UI at `http://localhost:8888/docs`.
151
+
152
+ ### Examples
153
+
154
+ #### Proxy HTTPS Stream
155
+
156
+ ```bash
157
+ mpv "http://localhost:8888/proxy/stream?d=https://jsoncompare.org/LearningContainer/SampleFiles/Video/MP4/sample-mp4-file.mp4&api_password=your_password"
158
+ ```
159
+
160
+ #### Proxy HTTPS self-signed certificate Stream
161
+
162
+ ```bash
163
+ mpv "http://localhost:8888/proxy/stream?d=https://self-signed.badssl.com/&api_password=your_password&verify_ssl=false"
164
+ ```
165
+
166
+
167
+ #### Proxy HLS Stream with Headers
168
+
169
+ ```bash
170
+ mpv "http://localhost:8888/proxy/hls?d=https://devstreaming-cdn.apple.com/videos/streaming/examples/img_bipbop_adv_example_fmp4/master.m3u8&h_referer=https://apple.com/&h_origin=https://apple.com&h_user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36&api_password=your_password"
171
+ ```
172
+
173
+ #### Live DASH Stream (Non-DRM Protected)
174
+
175
+ ```bash
176
+ mpv -v "http://localhost:8888/proxy/mpd/manifest?d=https://livesim.dashif.org/livesim/chunkdur_1/ato_7/testpic4_8s/Manifest.mpd&api_password=your_password"
177
+ ```
178
+
179
+ #### VOD DASH Stream (DRM Protected)
180
+
181
+ ```bash
182
+ mpv -v "http://localhost:8888/proxy/mpd/manifest?d=https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd&key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=your_password"
183
+ ```
184
+
185
+ Note: The `key` and `key_id` parameters are automatically processed if they're not in the correct format.
186
+
187
+ ### URL Encoding
188
+
189
+ For players like VLC that require properly encoded URLs, use the `encode_mediaflow_proxy_url` function:
190
+
191
+ ```python
192
+ from mediaflow_proxy.utils.http_utils import encode_mediaflow_proxy_url
193
+
194
+ encoded_url = encode_mediaflow_proxy_url(
195
+ mediaflow_proxy_url="http://127.0.0.1:8888",
196
+ endpoint="/proxy/mpd/manifest",
197
+ destination_url="https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
198
+ query_params={
199
+ "key_id": "nrQFDeRLSAKTLifXUIPiZg",
200
+ "key": "FmY0xnWCPCNaSpRG-tUuTQ",
201
+ "api_password": "your_password"
202
+ },
203
+ request_headers={
204
+ "referer": "https://media.axprod.net/",
205
+ "origin": "https://media.axprod.net",
206
+ }
207
+ )
208
+
209
+ print(encoded_url)
210
+
211
+ # http://127.0.0.1:8888/proxy/mpd/manifest?key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=your_password&d=https%3A%2F%2Fmedia.axprod.net%2FTestVectors%2Fv7-MultiDRM-SingleKey%2FManifest_1080p_ClearKey.mpd&h_referer=https%3A%2F%2Fmedia.axprod.net%2F&h_origin=https%3A%2F%2Fmedia.axprod.net
212
+ ```
213
+
214
+ This will output a properly encoded URL that can be used with players like VLC.
215
+
216
+ ```bash
217
+ vlc "http://127.0.0.1:8888/proxy/mpd/manifest?key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=dedsec&d=https%3A%2F%2Fmedia.axprod.net%2FTestVectors%2Fv7-MultiDRM-SingleKey%2FManifest_1080p_ClearKey.mpd"
218
+ ```
219
+
220
+ ### Using MediaFlow Proxy with Debrid Services and Stremio Addons
221
+
222
+ MediaFlow Proxy can be particularly useful when working with Debrid services (like Real-Debrid, AllDebrid) and Stremio addons. The `/proxy/ip` endpoint allows you to retrieve the public IP address of the MediaFlow Proxy server, which is crucial for routing Debrid streams correctly.
223
+
224
+ When a Stremio addon needs to create a video URL for a Debrid service, it typically needs to provide the user's public IP address. However, when routing the Debrid stream through MediaFlow Proxy, you should use the IP address of the MediaFlow Proxy server instead.
225
+
226
+ Here's how to utilize MediaFlow Proxy in this scenario:
227
+
228
+ 1. If MediaFlow Proxy is accessible over the internet:
229
+ - Use the `/proxy/ip` endpoint to get the MediaFlow Proxy server's public IP.
230
+ - Use this IP when creating Debrid service URLs in your Stremio addon.
231
+
232
+ 2. If MediaFlow Proxy is set up locally:
233
+ - Stremio addons can directly use the client's IP address.
234
+
235
+
236
+ ## Future Development
237
+
238
+ - Add support for Widevine and PlayReady decryption
239
+
240
+ ## Acknowledgements and Inspirations
241
+
242
+ MediaFlow Proxy was developed with inspiration from various projects and resources:
243
+
244
+ - [Stremio Server](https://github.com/Stremio/stremio-server) for HLS Proxify implementation, which inspired our HLS M3u8 Manifest parsing and redirection proxify support.
245
+ - [Comet Debrid proxy](https://github.com/g0ldyy/comet) for the idea of proxifying HTTPS video streams.
246
+ - [mp4decrypt](https://www.bento4.com/developers/dash/encryption_and_drm/), [mp4box](https://wiki.gpac.io/xmlformats/Common-Encryption/), and [devine](https://github.com/devine-dl/devine) for insights on parsing MPD and decrypting Clear Key DRM protected content.
247
+ - Test URLs were sourced from:
248
+ - [OTTVerse MPEG-DASH MPD Examples](https://ottverse.com/free-mpeg-dash-mpd-manifest-example-test-urls/)
249
+ - [OTTVerse HLS M3U8 Examples](https://ottverse.com/free-hls-m3u8-test-urls/)
250
+ - [Bitmovin Stream Test](https://bitmovin.com/demos/stream-test)
251
+ - [Bitmovin DRM Demo](https://bitmovin.com/demos/drm)
252
+ - [DASH-IF Reference Player](http://reference.dashif.org/dash.js/nightly/samples/)
253
+ - [HLS Protocol RFC](https://www.rfc-editor.org/rfc/rfc8216) for understanding the HLS protocol specifications.
254
+ - Claude 3.5 Sonnet for code assistance and brainstorming.
255
+
256
+ ## Contributing
257
+
258
+ Contributions are welcome! Please feel free to submit a Pull Request.
259
+
260
+ ## License
261
+
262
+ [MIT License](LICENSE)
263
+
264
+
265
+ ## Disclaimer
266
+
267
+ This project is for educational purposes only. The developers of MediaFlow Proxy are not responsible for any misuse of this software. Please ensure that you have the necessary permissions to access and use the media streams you are proxying.
File without changes
@@ -0,0 +1,14 @@
1
+ from pydantic_settings import BaseSettings
2
+
3
+
4
+ class Settings(BaseSettings):
5
+ api_password: str # The password for accessing the API endpoints.
6
+ proxy_url: str | None = None # The URL of the proxy server to route requests through.
7
+ mpd_live_stream_delay: int = 30 # The delay in seconds for live MPD streams.
8
+
9
+ class Config:
10
+ env_file = ".env"
11
+ extra = "ignore"
12
+
13
+
14
+ settings = Settings()
@@ -0,0 +1,24 @@
1
+ SUPPORTED_RESPONSE_HEADERS = [
2
+ "accept-ranges",
3
+ "content-type",
4
+ "content-length",
5
+ "content-range",
6
+ "connection",
7
+ "transfer-encoding",
8
+ "last-modified",
9
+ "etag",
10
+ "cache-control",
11
+ "expires",
12
+ ]
13
+
14
+ SUPPORTED_REQUEST_HEADERS = [
15
+ "accept",
16
+ "accept-encoding",
17
+ "accept-language",
18
+ "connection",
19
+ "range",
20
+ "if-range",
21
+ "user-agent",
22
+ "referer",
23
+ "origin",
24
+ ]
@@ -0,0 +1,11 @@
1
+ import os
2
+ import tempfile
3
+
4
+
5
+ async def create_temp_file(suffix: str, content: bytes = None, prefix: str = None) -> tempfile.NamedTemporaryFile:
6
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix, prefix=prefix)
7
+ temp_file.delete_file = lambda: os.unlink(temp_file.name)
8
+ if content:
9
+ temp_file.write(content)
10
+ temp_file.close()
11
+ return temp_file