Skip to main content

A high-performance proxy server for streaming media, supporting HTTP(S), HLS, and MPEG-DASH with real-time DRM decryption.

Project description


title: MediaFlow Proxy emoji: 🎥 colorFrom: blue colorTo: green sdk: docker app_port: 8888 pinned: false license: mit thumbnail: >- https://cdn.githubraw.com/mhdzumair/mediaflow-proxy/main/mediaflow_proxy/static/logo.png

MediaFlow Proxy

MediaFlow Proxy Logo

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.

Features

Stream Processing

  • Convert MPEG-DASH streams (DRM-protected and non-protected) to HLS
  • Support for Clear Key DRM-protected MPD DASH streams
  • Support for non-DRM protected DASH live and VOD streams
  • Proxy and modify HLS (M3U8) streams in real-time
  • Proxy HTTP/HTTPS links with custom headers

Proxy & Routing

  • Advanced proxy routing system with support for:
    • Domain-based routing rules
    • Protocol-specific routing (HTTP/HTTPS)
    • Subdomain and wildcard patterns
    • Port-specific routing
  • Support for HTTP/HTTPS/SOCKS5 proxy forwarding
  • Flexible SSL verification control per route
  • Support for expired or self-signed SSL certificates
  • Public IP address retrieval for Debrid services integration

Security

  • API password protection against unauthorized access & Network bandwidth abuse prevention
  • Parameter encryption to hide sensitive information
  • Optional IP-based access control for encrypted URLs
  • URL expiration support for encrypted URLs

Additional Features

  • Built-in speed test for RealDebrid and AllDebrid services
  • Custom header injection and modification
  • Real-time HLS manifest manipulation
  • HLS Key URL modifications for bypassing stream restrictions

Configuration

Set the following environment variables:

  • API_PASSWORD: Required. Protects against unauthorized access and API network abuses.
  • ENABLE_STREAMING_PROGRESS: Optional. Enable streaming progress logging. Default is false.

Proxy Configuration Examples

MediaFlow Proxy now supports advanced proxy routing using HTTPX's routing system. You can configure different proxy rules for different domains, protocols, and patterns. Here are some examples:

  1. Basic proxy configuration with a default proxy:
PROXY_DEFAULT_URL=http://default-proxy:8080
  1. Advanced routing with multiple rules:
PROXY_ROUTES='{
    "all://*.debrid.com": {
        "proxy_url": "socks5://debrid-proxy:8080"
    },
    "https://internal.company.com": {
        "proxy_url": null,
        "verify_ssl": false
    },
    "all://api.external.com": {
        "proxy_url": "http://api-proxy:8080",
        "verify_ssl": false
    }
}'

Proxy routing supports various patterns:

  • Domain routing: "all://example.com"
  • Subdomain routing: "all://*.example.com"
  • Protocol-specific routing: "https://example.com"
  • Port-specific routing: "all://*:1234"
  • Wildcard routing: "all://"

Speed Test Feature

MediaFlow Proxy now includes a built-in speed test feature for testing RealDebrid and AllDebrid network speeds. To access the speed test:

  1. Open your browser and navigate to http://your-server:8888/speedtest.html
  2. The speed test page allows you to:
    • Test download speeds from RealDebrid servers
    • Test download speeds from AllDebrid servers

Installation

Option 1: Self-Hosted Deployment

Using Docker from Docker Hub

  1. Pull & Run the Docker image:
    docker run -p 8888:8888 -e API_PASSWORD=your_password mhdzumair/mediaflow-proxy
    

Using pip

[!IMPORTANT]
Ensure that you have Python 3.10 or higher installed.

  1. Install the package:

    pip install mediaflow-proxy
    
  2. Set the API_PASSWORD and other environment variables in .env:

    echo "API_PASSWORD=your_password" > .env
    
  3. Run the MediaFlow Proxy server:

    mediaflow-proxy
    

    You can access the server at http://localhost:8888.

  4. To run the server with uvicorn options: (Optional)

    uvicorn mediaflow_proxy.main:app --host 0.0.0.0 --port 8888 --workers 4
    

Using git & poetry

[!IMPORTANT]
Ensure that you have Python 3.10 or higher installed.

  1. Clone the repository:

    git clone https://github.com/mhdzumair/mediaflow-proxy.git
    cd mediaflow-proxy
    
  2. Install dependencies using Poetry:

    poetry install
    
  3. Set the API_PASSWORD environment variable in .env:

    echo "API_PASSWORD=your_password" > .env
    
  4. Run the FastAPI server:

    poetry run uvicorn mediaflow_proxy.main:app --host 0.0.0.0 --port 8888 --workers 4
    

Build and Run Docker Image Locally

  1. Build the Docker image:

    docker build -t mediaflow-proxy .
    
  2. Run the Docker container:

    docker run -d -p 8888:8888 -e API_PASSWORD=your_password --restart unless-stopped --name mediaflow-proxy mediaflow-proxy
    

Option 2: Premium Hosted Service (ElfHosted)

ElfHosted Logo
For a hassle-free, high-performance deployment of MediaFlow Proxy, consider the premium hosted service through ElfHosted.

To purchase:

  1. Visit https://store.elfhosted.com/product/mediaflow-proxy
  2. Follow ElfHosted's setup instructions

Benefits:

  • Instant setup and automatic updates
  • High performance and 24/7 availability
  • No server maintenance required

Ideal for users who want a reliable, plug-and-play solution without the technical overhead of self-hosting.

Option 3: Hugging Face Space Deployment

  1. Visit the HF Space: mhdzumair/mediaflow-proxy
  2. Click on three dots on the right side of the page and select "Duplicate Space"
  3. Set the API_PASSWORD secret value & Set Visibility to "Public"
  4. Click on "Duplicate Space" to deploy the API

Usage

Endpoints

  1. /proxy/hls/manifest.m3u8: Proxify HLS streams
  2. /proxy/stream: Proxy generic http video streams
  3. /proxy/mpd/manifest.m3u8: Process MPD manifests
  4. /proxy/mpd/playlist.m3u8: Generate HLS playlists from MPD
  5. /proxy/mpd/segment.mp4: Process and decrypt media segments
  6. /proxy/ip: Get the public IP address of the MediaFlow Proxy server

Once the server is running, for more details on the available endpoints and their parameters, visit the Swagger UI at http://localhost:8888/docs.

Examples

Proxy HTTPS Stream

mpv "http://localhost:8888/proxy/stream?d=https://jsoncompare.org/LearningContainer/SampleFiles/Video/MP4/sample-mp4-file.mp4&api_password=your_password"

Proxy HTTPS self-signed certificate Stream

To bypass SSL verification for a self-signed certificate stream, export the proxy route configuration:

PROXY_ROUTES='{"https://self-signed.badssl.com": {"proxy_url": null, "verify_ssl": false}}'
mpv "http://localhost:8888/proxy/stream?d=https://self-signed.badssl.com/&api_password=your_password"

Proxy HLS Stream with Headers

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"

Live DASH Stream (Non-DRM Protected)

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"

VOD DASH Stream (DRM Protected)

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"

Note: The key and key_id parameters are automatically processed if they're not in the correct format.

URL Encoding

For players like VLC that require properly encoded URLs, use the encode_mediaflow_proxy_url function:

from mediaflow_proxy.utils.http_utils import encode_mediaflow_proxy_url

encoded_url = encode_mediaflow_proxy_url(
    mediaflow_proxy_url="http://127.0.0.1:8888",
    endpoint="/proxy/mpd/manifest.m3u8",
    destination_url="https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
    query_params={
        "key_id": "nrQFDeRLSAKTLifXUIPiZg",
        "key": "FmY0xnWCPCNaSpRG-tUuTQ",
        "api_password": "your_password"
    },
    request_headers={
        "referer": "https://media.axprod.net/",
        "origin": "https://media.axprod.net",
    }
)

print(encoded_url)

# 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

This will output a properly encoded URL that can be used with players like VLC.

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"

Generating Encrypted URLs

To generate an encrypted URL with optional IP restriction and expiration, Use the /generate_encrypted_or_encoded_url endpoint via swagger UI or programmatically as shown below:

import requests

url = "http://localhost:8888/generate_encrypted_or_encoded_url"
data = {
    "mediaflow_proxy_url": "http://localhost:8888",
    "endpoint": "/proxy/mpd/manifest.m3u8",
    "destination_url": "https://media.axprod.net/TestVectors/v7-MultiDRM-SingleKey/Manifest_1080p_ClearKey.mpd",
    "query_params": {
        "key_id": "nrQFDeRLSAKTLifXUIPiZg",
        "key": "FmY0xnWCPCNaSpRG-tUuTQ"
    },
    "request_headers": {
        "referer": "https://media.axprod.net/",
        "origin": "https://media.axprod.net",
    },
    "expiration": 3600,  # URL will expire in 1 hour
    "ip": "123.123.123.123",  # Optional: Restrict access to this IP
    "api_password": "your_password"
}

response = requests.post(url, json=data)
encrypted_url = response.json()["encoded_url"]
print(encrypted_url)

You can then use the encoded_url in your player or application to access the media stream.

Using MediaFlow Proxy with Debrid Services and Stremio Addons

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.

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.

Here's how to utilize MediaFlow Proxy in this scenario:

  1. If MediaFlow Proxy is accessible over the internet:

    • Use the /proxy/ip endpoint to get the MediaFlow Proxy server's public IP.
    • Use this IP when creating Debrid service URLs in your Stremio addon.
  2. If MediaFlow Proxy is set up locally:

    • Stremio addons can directly use the client's IP address.

Future Development

  • Add support for Widevine and PlayReady decryption

Acknowledgements and Inspirations

MediaFlow Proxy was developed with inspiration from various projects and resources:

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License

Disclaimer

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mediaflow_proxy-1.9.0.tar.gz (140.3 kB view details)

Uploaded Source

Built Distribution

mediaflow_proxy-1.9.0-py3-none-any.whl (151.5 kB view details)

Uploaded Python 3

File details

Details for the file mediaflow_proxy-1.9.0.tar.gz.

File metadata

  • Download URL: mediaflow_proxy-1.9.0.tar.gz
  • Upload date:
  • Size: 140.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for mediaflow_proxy-1.9.0.tar.gz
Algorithm Hash digest
SHA256 59d738468a834cc8c2492600822feb5cf8d9a21fb4cffa38195e7db2afdfe1fa
MD5 2893cf1958a4a11690d7c83bc9fd941e
BLAKE2b-256 251eeb926458cd3553b82ffda1aa709a94068e63b22a25b63fa72f134d91bfe0

See more details on using hashes here.

File details

Details for the file mediaflow_proxy-1.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mediaflow_proxy-1.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4cab801798709fe981c2038bf9d61883ddd6375d03962b110decc788b532b875
MD5 99c791289b599678ec2ec7c8c5dd9f60
BLAKE2b-256 49c19f1309934137ab012a5e3772aaf51a3cbc13cf98e5ae11456be532ce9b22

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page