CoolFace
Apppublic

LoremPizza/mediaflow-proxy

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
README.md267 linesDownload Raw Back to root
1---2title: MediaFlow Proxy3emoji: 🎥4colorFrom: blue5colorTo: green6sdk: docker7app_port: 88888pinned: false9license: mit10thumbnail: >-11  https://cdn.githubraw.com/mhdzumair/mediaflow-proxy/main/mediaflow_proxy/static/logo.png12---13 14 15# MediaFlow Proxy16 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 21MediaFlow 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## Features24 25- Convert MPEG-DASH streams (DRM-protected and non-protected) to HLS26- Support for Clear Key DRM-protected MPD DASH streams27- Support for non-DRM protected DASH live and VOD streams28- Proxy HTTP/HTTPS links with custom headers29- 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 services31- Support for HTTP/HTTPS/SOCKS5 proxy forwarding32- Protect against unauthorized access and network bandwidth abuses33- Support for play expired or self-signed SSL certificates server streams34 35## Configuration36 37Set 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## Installation44 45### Option 1: Self-Hosted Deployment46 47#### Using Docker from Docker Hub48 491. Pull & Run the Docker image:50   ```51   docker run -p 8888:8888 -e API_PASSWORD=your_password mhdzumair/mediaflow-proxy52   ```53 54#### Using pip55 56> ![IMPORTANT]57> Ensure that you have Python 3.10 or higher installed.58 591. Install the package:60   ```61   pip install mediaflow-proxy62   ```63 642. Set the `API_PASSWORD` and other environment variables in `.env`:65   ```66   echo "API_PASSWORD=your_password" > .env67   ```68 693. Run the MediaFlow Proxy server:70   ```71   mediaflow-proxy72   ```73 74 75#### Using git & poetry76 77> ![IMPORTANT]78> Ensure that you have Python 3.10 or higher installed.79 80 811. Clone the repository:82   ```83   git clone https://github.com/mhdzumair/mediaflow-proxy.git84   cd mediaflow-proxy85   ```86 872. Install dependencies using Poetry:88   ```89   poetry install90   ```91 923. Set the `API_PASSWORD` environment variable in `.env`:93   ```94   echo "API_PASSWORD=your_password" > .env95   ```96 974. Run the FastAPI server:98   ```99   poetry run uvicorn mediaflow_proxy.main:app --host 0.0.0.0 --port 8888100   ```101 102 103#### Build and Run Docker Image Locally104 1051. Build the Docker image:106   ```107   docker build -t mediaflow-proxy .108   ```109 1102. Run the Docker container:111   ```112   docker run -d -p 8888:8888 -e API_PASSWORD=your_password --restart unless-stopped --name mediaflow-proxy mediaflow-proxy113   ```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>119For a hassle-free, high-performance deployment of MediaFlow Proxy, consider the premium hosted service through ElfHosted.120 121To purchase:1221. Visit [https://store.elfhosted.com/product/mediaflow-proxy](https://store.elfhosted.com/product/mediaflow-proxy)1232. Follow ElfHosted's setup instructions124 125Benefits:126- Instant setup and automatic updates127- High performance and 24/7 availability128- No server maintenance required129 130Ideal for users who want a reliable, plug-and-play solution without the technical overhead of self-hosting.131 132### Option 3: Hugging Face Space Deployment133 1341. Visit the HF Space: [mhdzumair/mediaflow-proxy](https://huggingface.co/spaces/mhdzumair/mediaflow-proxy)1352. Click on three dots on the right side of the page and select "Duplicate Space"1363. Set the `API_PASSWORD` secret value & Set Visibility to "Public"1374. Click on "Duplicate Space" to deploy the API138 139## Usage140 141### Endpoints142 1431. `/proxy/hls`: Proxify HLS streams1442. `/proxy/stream`: Proxy generic http video streams1453. `/proxy/mpd/manifest`: Process MPD manifests1464. `/proxy/mpd/playlist`: Generate HLS playlists from MPD1475. `/proxy/mpd/segment`: Process and decrypt media segments1486. `/proxy/ip`: Get the public IP address of the MediaFlow Proxy server149 150Once 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### Examples153 154#### Proxy HTTPS Stream155 156```bash157mpv "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 Stream161 162```bash163mpv "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 Headers168 169```bash170mpv "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```bash176mpv -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```bash182mpv -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 185Note: The `key` and `key_id` parameters are automatically processed if they're not in the correct format.186 187### URL Encoding188 189For players like VLC that require properly encoded URLs, use the `encode_mediaflow_proxy_url` function:190 191```python192from mediaflow_proxy.utils.http_utils import encode_mediaflow_proxy_url193 194encoded_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 209print(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.net212```213 214This will output a properly encoded URL that can be used with players like VLC.215 216```bash217vlc "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 Addons221 222MediaFlow 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 224When 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 226Here's how to utilize MediaFlow Proxy in this scenario:227 2281. 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 2322. If MediaFlow Proxy is set up locally:233   - Stremio addons can directly use the client's IP address.234 235 236## Future Development237 238- Add support for Widevine and PlayReady decryption239 240## Acknowledgements and Inspirations241 242MediaFlow 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## Contributing257 258Contributions are welcome! Please feel free to submit a Pull Request.259 260## License261 262[MIT License](LICENSE)263 264 265## Disclaimer266 267This 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.