mhdzumair commited on
Commit
0d394b4
1 Parent(s): 60fc64b

Update endpoint paths for fixing video playback in some player

Browse files
README.md CHANGED
@@ -143,10 +143,10 @@ Ideal for users who want a reliable, plug-and-play solution without the technica
143
 
144
  ### Endpoints
145
 
146
- 1. `/proxy/hls`: Proxify HLS streams
147
  2. `/proxy/stream`: Proxy generic http video streams
148
- 3. `/proxy/mpd/manifest`: Process MPD manifests
149
- 4. `/proxy/mpd/playlist`: Generate HLS playlists from MPD
150
  5. `/proxy/mpd/segment`: Process and decrypt media segments
151
  6. `/proxy/ip`: Get the public IP address of the MediaFlow Proxy server
152
 
@@ -170,19 +170,19 @@ mpv "http://localhost:8888/proxy/stream?d=https://self-signed.badssl.com/&api_pa
170
  #### Proxy HLS Stream with Headers
171
 
172
  ```bash
173
- 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"
174
  ```
175
 
176
  #### Live DASH Stream (Non-DRM Protected)
177
 
178
  ```bash
179
- 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"
180
  ```
181
 
182
  #### VOD DASH Stream (DRM Protected)
183
 
184
  ```bash
185
- 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"
186
  ```
187
 
188
  Note: The `key` and `key_id` parameters are automatically processed if they're not in the correct format.
@@ -196,7 +196,7 @@ from mediaflow_proxy.utils.http_utils import encode_mediaflow_proxy_url
196
 
197
  encoded_url = encode_mediaflow_proxy_url(
198
  mediaflow_proxy_url="http://127.0.0.1:8888",
199
- endpoint="/proxy/mpd/manifest",
200
  destination_url="https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
201
  query_params={
202
  "key_id": "nrQFDeRLSAKTLifXUIPiZg",
@@ -211,13 +211,13 @@ encoded_url = encode_mediaflow_proxy_url(
211
 
212
  print(encoded_url)
213
 
214
- # 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
215
  ```
216
 
217
  This will output a properly encoded URL that can be used with players like VLC.
218
 
219
  ```bash
220
- 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"
221
  ```
222
 
223
  ### Generating Encrypted URLs
@@ -229,7 +229,7 @@ import requests
229
  url = "http://localhost:8888/generate_encrypted_or_encoded_url"
230
  data = {
231
  "mediaflow_proxy_url": "http://localhost:8888",
232
- "endpoint": "/proxy/mpd/manifest",
233
  "destination_url": "https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
234
  "query_params": {
235
  "key_id": "nrQFDeRLSAKTLifXUIPiZg",
 
143
 
144
  ### Endpoints
145
 
146
+ 1. `/proxy/hls/manifest.m3u8`: Proxify HLS streams
147
  2. `/proxy/stream`: Proxy generic http video streams
148
+ 3. `/proxy/mpd/manifest.m3u8`: Process MPD manifests
149
+ 4. `/proxy/mpd/playlist.m3u8`: Generate HLS playlists from MPD
150
  5. `/proxy/mpd/segment`: Process and decrypt media segments
151
  6. `/proxy/ip`: Get the public IP address of the MediaFlow Proxy server
152
 
 
170
  #### Proxy HLS Stream with Headers
171
 
172
  ```bash
173
+ mpv "http://localhost:8888/proxy/hls/manifest.m3u8?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"
174
  ```
175
 
176
  #### Live DASH Stream (Non-DRM Protected)
177
 
178
  ```bash
179
+ mpv -v "http://localhost:8888/proxy/mpd/manifest.m3u8?d=https://livesim.dashif.org/livesim/chunkdur_1/ato_7/testpic4_8s/Manifest.mpd&api_password=your_password"
180
  ```
181
 
182
  #### VOD DASH Stream (DRM Protected)
183
 
184
  ```bash
185
+ mpv -v "http://localhost:8888/proxy/mpd/manifest.m3u8?d=https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd&key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=your_password"
186
  ```
187
 
188
  Note: The `key` and `key_id` parameters are automatically processed if they're not in the correct format.
 
196
 
197
  encoded_url = encode_mediaflow_proxy_url(
198
  mediaflow_proxy_url="http://127.0.0.1:8888",
199
+ endpoint="/proxy/mpd/manifest.m3u8",
200
  destination_url="https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
201
  query_params={
202
  "key_id": "nrQFDeRLSAKTLifXUIPiZg",
 
211
 
212
  print(encoded_url)
213
 
214
+ # http://127.0.0.1:8888/proxy/mpd/manifest.m3u8?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
215
  ```
216
 
217
  This will output a properly encoded URL that can be used with players like VLC.
218
 
219
  ```bash
220
+ vlc "http://127.0.0.1:8888/proxy/mpd/manifest.m3u8?key_id=nrQFDeRLSAKTLifXUIPiZg&key=FmY0xnWCPCNaSpRG-tUuTQ&api_password=dedsec&d=https%3A%2F%2Fmedia.axprod.net%2FTestVectors%2Fv7-MultiDRM-SingleKey%2FManifest_1080p_ClearKey.mpd"
221
  ```
222
 
223
  ### Generating Encrypted URLs
 
229
  url = "http://localhost:8888/generate_encrypted_or_encoded_url"
230
  data = {
231
  "mediaflow_proxy_url": "http://localhost:8888",
232
+ "endpoint": "/proxy/mpd/manifest.m3u8",
233
  "destination_url": "https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
234
  "query_params": {
235
  "key_id": "nrQFDeRLSAKTLifXUIPiZg",
mediaflow_proxy/routes.py CHANGED
@@ -7,8 +7,8 @@ from .utils.http_utils import get_proxy_headers, ProxyRequestHeaders
7
  proxy_router = APIRouter()
8
 
9
 
10
- @proxy_router.head("/hls")
11
- @proxy_router.get("/hls")
12
  async def hls_stream_proxy(
13
  request: Request,
14
  d: HttpUrl,
@@ -61,7 +61,7 @@ async def proxy_stream_endpoint(
61
  return await proxy_stream(request.method, str(d), proxy_headers, verify_ssl, use_request_proxy)
62
 
63
 
64
- @proxy_router.get("/mpd/manifest")
65
  async def manifest_endpoint(
66
  request: Request,
67
  d: HttpUrl,
@@ -89,7 +89,7 @@ async def manifest_endpoint(
89
  return await get_manifest(request, str(d), proxy_headers, key_id, key, verify_ssl, use_request_proxy)
90
 
91
 
92
- @proxy_router.get("/mpd/playlist")
93
  async def playlist_endpoint(
94
  request: Request,
95
  d: HttpUrl,
 
7
  proxy_router = APIRouter()
8
 
9
 
10
+ @proxy_router.head("/hls/manifest.m3u8")
11
+ @proxy_router.get("/hls/manifest.m3u8")
12
  async def hls_stream_proxy(
13
  request: Request,
14
  d: HttpUrl,
 
61
  return await proxy_stream(request.method, str(d), proxy_headers, verify_ssl, use_request_proxy)
62
 
63
 
64
+ @proxy_router.get("/mpd/manifest.m3u8")
65
  async def manifest_endpoint(
66
  request: Request,
67
  d: HttpUrl,
 
89
  return await get_manifest(request, str(d), proxy_headers, key_id, key, verify_ssl, use_request_proxy)
90
 
91
 
92
+ @proxy_router.get("/mpd/playlist.m3u8")
93
  async def playlist_endpoint(
94
  request: Request,
95
  d: HttpUrl,
mediaflow_proxy/utils/crypto_utils.py CHANGED
@@ -1,5 +1,6 @@
1
  import base64
2
  import json
 
3
  import time
4
  from urllib.parse import urlencode
5
 
@@ -75,7 +76,11 @@ class EncryptionMiddleware(BaseHTTPMiddleware):
75
  except HTTPException as e:
76
  return JSONResponse(content={"error": str(e.detail)}, status_code=e.status_code)
77
 
78
- response = await call_next(request)
 
 
 
 
79
  return response
80
 
81
  @staticmethod
 
1
  import base64
2
  import json
3
+ import logging
4
  import time
5
  from urllib.parse import urlencode
6
 
 
76
  except HTTPException as e:
77
  return JSONResponse(content={"error": str(e.detail)}, status_code=e.status_code)
78
 
79
+ try:
80
+ response = await call_next(request)
81
+ except Exception as e:
82
+ logging.exception("An error occurred while processing the request")
83
+ return JSONResponse(content={"error": str(e)}, status_code=500)
84
  return response
85
 
86
  @staticmethod