mirror of
https://github.com/devine-dl/pywidevine.git
synced 2025-11-05 04:14:49 +00:00
Compare commits
No commits in common. "master" and "v1.9.0" have entirely different histories.
34
.github/workflows/cd.yml
vendored
34
.github/workflows/cd.yml
vendored
@ -9,25 +9,33 @@ jobs:
|
||||
tagged-release:
|
||||
name: Tagged Release
|
||||
runs-on: ubuntu-latest
|
||||
environment:
|
||||
name: pypi
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: read
|
||||
steps:
|
||||
- uses: actions/checkout@v5
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.14"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v6
|
||||
- name: Install Poetry
|
||||
uses: abatilo/actions-poetry@v3
|
||||
with:
|
||||
version: "0.9.5"
|
||||
enable-cache: true
|
||||
- name: Install the project
|
||||
run: uv sync --locked
|
||||
poetry-version: 2.1.3
|
||||
- name: Install project
|
||||
run: poetry install --only main
|
||||
- name: Build project
|
||||
run: uv build
|
||||
run: poetry build
|
||||
- name: Upload wheel
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: Python Wheel
|
||||
path: "dist/*.whl"
|
||||
- name: Deploy release
|
||||
uses: marvinpinto/action-automatic-releases@latest
|
||||
with:
|
||||
prerelease: false
|
||||
repo_token: "${{ secrets.GITHUB_TOKEN }}"
|
||||
files: |
|
||||
dist/*.whl
|
||||
- name: Publish to PyPI
|
||||
run: uv publish
|
||||
env:
|
||||
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
|
||||
run: poetry publish
|
||||
|
||||
26
.github/workflows/ci.yml
vendored
26
.github/workflows/ci.yml
vendored
@ -15,15 +15,14 @@ jobs:
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: "3.14"
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v6
|
||||
- name: Install poetry
|
||||
uses: abatilo/actions-poetry@v3
|
||||
with:
|
||||
version: "0.9.5"
|
||||
enable-cache: true
|
||||
- name: Install the project
|
||||
run: uv sync --locked --all-extras --dev
|
||||
poetry-version: 2.1.3
|
||||
- name: Install project
|
||||
run: poetry install --all-extras
|
||||
- name: Run pre-commit which does various checks
|
||||
run: uv run pre-commit run --all-files --show-diff-on-failure
|
||||
run: poetry run pre-commit run --all-files --show-diff-on-failure
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
@ -35,12 +34,11 @@ jobs:
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
- name: Install uv
|
||||
uses: astral-sh/setup-uv@v6
|
||||
- name: Install poetry
|
||||
uses: abatilo/actions-poetry@v3
|
||||
with:
|
||||
version: "0.9.5"
|
||||
enable-cache: true
|
||||
- name: Install the project
|
||||
run: uv sync --locked --all-extras
|
||||
poetry-version: 2.1.3
|
||||
- name: Install project
|
||||
run: poetry install --all-extras --only main
|
||||
- name: Build project
|
||||
run: uv build
|
||||
run: poetry build
|
||||
|
||||
129
README.md
129
README.md
@ -5,20 +5,17 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/devine-dl/pywidevine/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/:license-GPL%203.0-blue.svg" alt="License">
|
||||
<a href="https://github.com/devine-dl/pywidevine/actions/workflows/ci.yml">
|
||||
<img src="https://github.com/devine-dl/pywidevine/actions/workflows/ci.yml/badge.svg" alt="Build status">
|
||||
</a>
|
||||
<a href="https://pypi.org/project/pywidevine">
|
||||
<img src="https://img.shields.io/badge/python-3.9%2B-informational" alt="Python version">
|
||||
</a>
|
||||
<a href="https://github.com/astral-sh/uv">
|
||||
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Onyx-Nostalgia/uv/refs/heads/fix/logo-badge/assets/badge/v0.json" alt="Manager: uv">
|
||||
</a>
|
||||
<a href="https://github.com/astral-sh/ruff">
|
||||
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Linter: Ruff">
|
||||
</a>
|
||||
<a href="https://github.com/devine-dl/pywidevine/actions/workflows/ci.yml">
|
||||
<img src="https://github.com/devine-dl/pywidevine/actions/workflows/ci.yml/badge.svg" alt="Build status">
|
||||
<a href="https://python-poetry.org">
|
||||
<img src="https://img.shields.io/endpoint?url=https://python-poetry.org/badge/v0.json" alt="Dependency management: Poetry">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
@ -35,31 +32,22 @@
|
||||
|
||||
## Installation
|
||||
|
||||
### With pip
|
||||
```shell
|
||||
$ pip install pywidevine
|
||||
```
|
||||
|
||||
> Since *pip* is pre-installed with Python, it is the most straight forward way to install pywidevine.
|
||||
> **Note**
|
||||
If pip gives you a warning about a path not being in your PATH environment variable then promptly add that path then
|
||||
close all open command prompt/terminal windows, or `pywidevine` CLI won't work as it will not be found.
|
||||
|
||||
Simply run `pip install pywidevine` and it will be ready to use from the CLI or within scripts in a minute.
|
||||
|
||||
### With uv
|
||||
|
||||
> This is recommended for those who wish to install from the source code, are working on changes in the source code, or
|
||||
just simply prefer it's many handy features.
|
||||
|
||||
Go to to the official website and [get uv installed](https://docs.astral.sh/uv/getting-started/installation/). Download
|
||||
or clone this repository, go inside it, and run `uv run pywidevine --version`. To run scripts, like a `license.py` that
|
||||
is importing pywidevine, do `uv run license.py`. Effectively, put `uv run` before calling whatever is using pywidevine.
|
||||
For other ways to run pywidevine with uv, see [Running commands](https://docs.astral.sh/uv/guides/projects/#running-commands).
|
||||
Voilà 🎉 — You now have the `pywidevine` package installed!
|
||||
You can now import pywidevine in scripts ([see below](#usage)).
|
||||
A command-line interface is also available, try `pywidevine --help`.
|
||||
|
||||
## Usage
|
||||
|
||||
There are two ways to use pywidevine, through scripts, or the CLI (command-line interface).
|
||||
Most people would be using it through scripts due to complexities working with license server APIs.
|
||||
|
||||
### Scripts
|
||||
|
||||
The following is a minimal example of using pywidevine in a script to get a License for Bitmovin's Art of Motion Demo.
|
||||
This demo can be found on [Bitmovin's DRM Stream Test demo page](https://bitmovin.com/demos/drm/).
|
||||
The following is a minimal example of using pywidevine in a script to get a License for Bitmovin's
|
||||
Art of Motion Demo.
|
||||
|
||||
```py
|
||||
from pywidevine.cdm import Cdm
|
||||
@ -68,93 +56,50 @@ from pywidevine.pssh import PSSH
|
||||
|
||||
import requests
|
||||
|
||||
# prepare pssh (usually inside the MPD/M3U8, an API response, the player page, or inside the pssh mp4 box)
|
||||
# prepare pssh
|
||||
pssh = PSSH("AAAAW3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAADsIARIQ62dqu8s0Xpa"
|
||||
"7z2FmMPGj2hoNd2lkZXZpbmVfdGVzdCIQZmtqM2xqYVNkZmFsa3IzaioCSEQyAA==")
|
||||
|
||||
# load device from a WVD file (your provision)
|
||||
# load device
|
||||
device = Device.load("C:/Path/To/A/Provision.wvd")
|
||||
|
||||
# load cdm (creating a CDM instance using that device)
|
||||
# load cdm
|
||||
cdm = Cdm.from_device(device)
|
||||
|
||||
# open cdm session (note that any one device should have a practical limit to amount of sessions open at any one time)
|
||||
# open cdm session
|
||||
session_id = cdm.open()
|
||||
|
||||
# get license challenge (generate a license request message, signed using the device with the pssh)
|
||||
# get license challenge
|
||||
challenge = cdm.get_license_challenge(session_id, pssh)
|
||||
|
||||
# send license challenge to bitmovin's license server (which has no auth and asks simply for the license challenge as-is)
|
||||
# another license server may require authentication and ask for it as JSON or form data instead
|
||||
# you may also be required to use privacy mode, where you use their service certificate when creating the challenge
|
||||
licence = requests.post("https://cwip-shaka-proxy.appspot.com/no_auth", data=challenge)
|
||||
# send license challenge (assuming a generic license server SDK with no API front)
|
||||
licence = requests.post("https://...", data=challenge)
|
||||
licence.raise_for_status()
|
||||
|
||||
# parse the license response message received from the license server API
|
||||
# parse license challenge
|
||||
cdm.parse_license(session_id, licence.content)
|
||||
|
||||
# print keys
|
||||
for key in cdm.get_keys(session_id):
|
||||
print(f"[{key.type}] {key.kid.hex}:{key.key.hex()}")
|
||||
|
||||
# finished, close the session, disposing of all keys and other related data
|
||||
# close session, disposes of session data
|
||||
cdm.close(session_id)
|
||||
```
|
||||
|
||||
There are other features not shown in this small example like:
|
||||
|
||||
- Privacy Mode
|
||||
- Setting Service Certificates
|
||||
- Remote CDMs and Serving
|
||||
- Choosing a License Type
|
||||
- Creating WVD files
|
||||
- and much more!
|
||||
|
||||
> [!TIP]
|
||||
> For examples, take a look at the methods available in the [Cdm class](/pywidevine/cdm.py) and read their doc-strings
|
||||
> for further information.
|
||||
|
||||
### Command-line Interface
|
||||
|
||||
The CLI can be useful to do simple license calls, migrate WVD files, and test provisions.
|
||||
Take a look at `pywidevine --help` to see a list of commands available.
|
||||
|
||||
```plain
|
||||
Usage: pywidevine [OPTIONS] COMMAND [ARGS]...
|
||||
|
||||
pywidevine—Python Widevine CDM implementation.
|
||||
|
||||
Options:
|
||||
-v, --version Print version information.
|
||||
-d, --debug Enable DEBUG level logs.
|
||||
--help Show this message and exit.
|
||||
|
||||
Commands:
|
||||
create-device Create a Widevine Device (.wvd) file from an RSA Private...
|
||||
export-device Export a Widevine Device (.wvd) file to an RSA Private...
|
||||
license Make a License Request for PSSH to SERVER using DEVICE.
|
||||
migrate Upgrade from earlier versions of the Widevine Device...
|
||||
serve Serve your local CDM and Widevine Devices Remotely.
|
||||
test Test the CDM code by getting Content Keys for Bitmovin's...
|
||||
```
|
||||
|
||||
Every command has further help information, simply type `pywidevine <command> --help`.
|
||||
For example, `pywidevine test --help`:
|
||||
|
||||
```plain
|
||||
Usage: pywidevine test [OPTIONS] DEVICE
|
||||
|
||||
Test the CDM code by getting Content Keys for Bitmovin's Art of Motion
|
||||
example. https://bitmovin.com/demos/drm
|
||||
https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd
|
||||
|
||||
The device argument is a Path to a Widevine Device (.wvd) file which
|
||||
contains the device private key among other required information.
|
||||
|
||||
Options:
|
||||
-p, --privacy Use Privacy Mode, off by default.
|
||||
--help Show this message and exit.
|
||||
```
|
||||
> **Note**
|
||||
> There are various features not shown in this specific example like:
|
||||
>
|
||||
> - Privacy Mode
|
||||
> - Setting Service Certificates
|
||||
> - Remote CDMs and Serving
|
||||
> - Choosing a License Type to request
|
||||
> - Creating WVD files
|
||||
> - and much more!
|
||||
>
|
||||
> Take a look at the methods available in the [Cdm class](/pywidevine/cdm.py) and their doc-strings for
|
||||
> further information. For more examples see the [CLI functions](/pywidevine/main.py) which uses a lot
|
||||
> of previously mentioned features.
|
||||
|
||||
## Disclaimer
|
||||
|
||||
|
||||
1620
poetry.lock
generated
Normal file
1620
poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,21 +1,16 @@
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
[project]
|
||||
[tool.poetry]
|
||||
name = "pywidevine"
|
||||
version = "1.9.0"
|
||||
description = "Widevine CDM (Content Decryption Module) implementation in Python."
|
||||
authors = [{ name = "rlaphoenix", email = "rlaphoenix@pm.me" }]
|
||||
requires-python = ">=3.9"
|
||||
readme = "README.md"
|
||||
license = "GPL-3.0-only"
|
||||
keywords = [
|
||||
"python",
|
||||
"drm",
|
||||
"widevine",
|
||||
"google",
|
||||
]
|
||||
authors = ["rlaphoenix <rlaphoenix@pm.me>"]
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/devine-dl/pywidevine"
|
||||
keywords = ["python", "drm", "widevine", "google"]
|
||||
classifiers = [
|
||||
"Development Status :: 5 - Production/Stable",
|
||||
"Intended Audience :: Developers",
|
||||
@ -24,50 +19,45 @@ classifiers = [
|
||||
"Operating System :: OS Independent",
|
||||
"Topic :: Multimedia :: Video",
|
||||
"Topic :: Security :: Cryptography",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules"
|
||||
]
|
||||
dependencies = [
|
||||
"protobuf~=6.33.0",
|
||||
"pymp4~=1.4.0",
|
||||
"pycryptodome~=3.23.0",
|
||||
"click~=8.1.7",
|
||||
"requests~=2.32.5",
|
||||
"Unidecode~=1.3.7",
|
||||
"PyYAML~=6.0.3",
|
||||
]
|
||||
|
||||
[project.optional-dependencies]
|
||||
serve = ["aiohttp~=3.13.1"]
|
||||
|
||||
[project.urls]
|
||||
Repository = "https://github.com/devine-dl/pywidevine"
|
||||
Issues = "https://github.com/devine-dl/pywidevine/issues"
|
||||
Discussions = "https://github.com/devine-dl/pywidevine/discussions"
|
||||
Changelog = "https://github.com/devine-dl/pywidevine/blob/master/CHANGELOG.md"
|
||||
|
||||
[project.scripts]
|
||||
pywidevine = "pywidevine.main:main"
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"pre-commit~=4.3.0",
|
||||
"mypy~=1.18.2",
|
||||
"mypy-protobuf~=3.6.0",
|
||||
"types-protobuf~=6.32.1.20250918",
|
||||
"types-requests~=2.32.4.20250913",
|
||||
"types-PyYAML~=6.0.12.20250915",
|
||||
"isort~=6.1.0",
|
||||
"ruff~=0.14.2",
|
||||
]
|
||||
|
||||
[tool.hatch.build.targets.sdist]
|
||||
include = [
|
||||
"pywidevine",
|
||||
"CHANGELOG.md",
|
||||
{ path = "CHANGELOG.md", format = "sdist" },
|
||||
{ path = "README.md", format = "sdist" },
|
||||
{ path = "LICENSE", format = "sdist" },
|
||||
]
|
||||
|
||||
[tool.hatch.build.targets.wheel]
|
||||
packages = ["pywidevine"]
|
||||
[tool.poetry.urls]
|
||||
"Issues" = "https://github.com/devine-dl/pywidevine/issues"
|
||||
"Discussions" = "https://github.com/devine-dl/pywidevine/discussions"
|
||||
"Changelog" = "https://github.com/devine-dl/pywidevine/blob/master/CHANGELOG.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = ">=3.9,<4.0"
|
||||
protobuf = "^6.33.0"
|
||||
pymp4 = "^1.4.0"
|
||||
pycryptodome = "^3.23.0"
|
||||
click = "^8.1.7"
|
||||
requests = "^2.32.5"
|
||||
Unidecode = "^1.3.7"
|
||||
PyYAML = "^6.0.3"
|
||||
aiohttp = {version = "^3.13.1", optional = true}
|
||||
|
||||
[tool.poetry.group.dev.dependencies]
|
||||
pre-commit = "^4.3.0"
|
||||
mypy = "^1.18.2"
|
||||
mypy-protobuf = "^3.6.0"
|
||||
types-protobuf = "^6.32.1.20250918"
|
||||
types-requests = "^2.32.4.20250913"
|
||||
types-PyYAML = "^6.0.12.20250915"
|
||||
isort = "^6.1.0"
|
||||
ruff = "~0.14.2"
|
||||
|
||||
[tool.poetry.extras]
|
||||
serve = ["aiohttp"]
|
||||
|
||||
[tool.poetry.scripts]
|
||||
pywidevine = "pywidevine.main:main"
|
||||
|
||||
[tool.ruff]
|
||||
extend-exclude = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user