Skip to content

Commit

Permalink
initial work on replacing the old pywidevine
Browse files Browse the repository at this point in the history
- Existing devices are converted to WVD
- Delete device <-> user relation on delete
- Strip out old vinetrimmer in preparation to replace it with Devine
- Moved User util class to its own file
- Renamed `Library` class to `GetWVKeys`
- Moved `search_res_to_dict` to utils
- Removed old pywidevine
  • Loading branch information
Puyodead1 committed Jul 24, 2024
1 parent 382cdea commit 0c152ef
Show file tree
Hide file tree
Showing 22 changed files with 827 additions and 1,012 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ Example command to run on port 8081 listening on all interfaces:

- `poetry run gunicorn -w 1 -b 0.0.0.0:8081 getwvkeys.main:app`

or waitress:
- `poetry run waitress-serve --listen=*:8081 getwvkeys.main:app`

_never use more than 1 worker, getwvkeys does not currently support that and you will encounter issues with sessions._

# Other Info
Expand Down
12 changes: 3 additions & 9 deletions alembic/versions/684292138a0a_many_devices_to_many_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
revision: str = "684292138a0a"
down_revision: Union[str, None] = "c8ce82d0c054"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = "c8ce82d0c054"


def upgrade() -> None:
Expand Down Expand Up @@ -91,14 +91,8 @@ def upgrade() -> None:
"user_device",
sa.Column("user_id", sa.VARCHAR(255), nullable=False),
sa.Column("device_code", sa.VARCHAR(255), nullable=False),
sa.ForeignKeyConstraint(
["device_code"],
["devices.code"],
),
sa.ForeignKeyConstraint(
["user_id"],
["users.id"],
),
sa.ForeignKeyConstraint(["device_code"], ["devices.code"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
)

# remove useless columns, these never served any purpose
Expand Down
63 changes: 63 additions & 0 deletions alembic/versions/8fbc59f03986_convert_device_to_wvd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""convert_device_to_wvd
Revision ID: 8fbc59f03986
Revises: 684292138a0a
Create Date: 2024-07-24 16:35:56.530161
"""

import base64
import logging
from typing import Sequence, Union

import sqlalchemy as sa
from pywidevine.device import Device, DeviceTypes
from sqlalchemy.dialects import mysql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "8fbc59f03986"
down_revision: Union[str, None] = "684292138a0a"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = "684292138a0a"

logger = logging.getLogger("alembic.runtime.migration")


def upgrade() -> None:
# create the new wvd column and make it nullable temporarily
op.add_column("devices", sa.Column("wvd", sa.Text(), nullable=True))

# DROP all devices that have an empty private key or client id
op.execute("DELETE FROM devices WHERE device_private_key = '' OR client_id_blob_filename = ''")

# run through all devices and convert them to a WVD
devices = (
op.get_bind().execute(sa.text("SELECT code,client_id_blob_filename,device_private_key FROM devices")).fetchall()
)
for code, client_id, private_key in devices:
logger.info(f"Converting device {code} to WVD")
wvd = Device(
type_=DeviceTypes.ANDROID,
security_level=3,
flags=None,
private_key=base64.b64decode(private_key),
client_id=base64.b64decode(client_id),
)

wvd_b64 = base64.b64encode(wvd.dumps()).decode()
op.get_bind().execute(
sa.text("UPDATE devices SET wvd = :wvd WHERE code = :code"), {"wvd": wvd_b64, "code": code}
)

# make the wvd column non-nullable
op.alter_column("devices", "wvd", existing_type=sa.Text(), nullable=False)

# remove the old columns
op.drop_column("devices", "device_private_key")
op.drop_column("devices", "client_id_blob_filename")


def downgrade() -> None:
raise NotImplementedError("Downgrade is not supported for this migration.")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 0c152ef

Please sign in to comment.