Untitled

 avatar
unknown
plain_text
a year ago
4.7 kB
6
Indexable
import os
import requests
import rich

from base64 import b64encode
from pywidevine.cdm import Cdm
from pywidevine.device import Device
from pywidevine.pssh import PSSH
from rich import print as pp
from rich.console import Console

class Ripper:
    def __init__(self):
        currentPath = os.getcwd()
        self.wvdPath = os.path.join(currentPath, 'binaries/WVDs/default.wvd')
        self.session = self.create_session()
        self.console = Console()

    def start_process(self):
        all_keys = []

        print("\nStreaming list")
        print("1. Generic")
        print("2. AstroGO")

        selection = int(input("\nPlease choose a service: "))
        pssh = input("\nEnter pssh: ")
        
        if not pssh:
            kid = input("Enter kid: ")
            pssh = metadata.get_pssh_from_kid(kid).decode('utf-8')
        
        license_url = input("Enter license url: ")
        
        if selection == 1:
            all_keys = self.getKeys(license_url, pssh, selection)
        elif selection == 2:
            bearerToken = input("\nEnter bearerToken: ")
            self.session.headers['authorization'] = f'Bearer {bearerToken}'
            
            all_keys = self.getKeysAotg(license_url, pssh, selection)
            
        print('')
        
        for key in all_keys:
            self.console.print(f'[bright_green]KEY[/bright_green]: {key}', highlight=False)
            
    ########################################################### AUTHENTICATION ################################################
    
    def create_session(self): # Creating session
        headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
        }

        session = requests.Session()
        session.headers.update(headers)

        return session
        
    def get_pssh_from_kid(self, keyId):
        keyId.replace('-', '')
        array_of_bytes = bytearray( b'\x00\x00\x002pssh\x00\x00\x00\x00')
        array_of_bytes.extend(bytes.fromhex("edef8ba979d64acea3c827dcd51d21ed"))
        array_of_bytes.extend(b'\x00\x00\x00\x12\x12\x10')
        array_of_bytes.extend(bytes.fromhex( keyId.replace("-", "")))
        
        return base64.b64encode(bytes.fromhex(array_of_bytes.hex()))
        
    ########################################################### GETTING KEYS ################################################
    
    def getKeys(self, license_url, initData, selection):
        all_keys = []

        pssh = PSSH(initData)
        device = Device.load(self.wvdPath)

        cdm = Cdm.from_device(device)
        session_id = cdm.open()
        challenge = cdm.get_license_challenge(session_id, pssh)

        licence = self.session.post(url=license_url, data=challenge)
        
        licence.raise_for_status()

        cdm.parse_license(session_id, licence.content)
        
        for key in cdm.get_keys(session_id):
            if key.type == 'CONTENT':
                raw_key = f"{key.kid.hex}:{key.key.hex()}"
                all_keys.append(raw_key)

        cdm.close(session_id)

        return all_keys
        
    def getKeysAotg(self, license_url, initData, selection):
        all_keys = []

        pssh = PSSH(initData)
        device = Device.load(self.wvdPath)

        cdm = Cdm.from_device(device)
        session_id = cdm.open()
        challenge = cdm.get_license_challenge(session_id, pssh)

        contentID = input("\nEnter contentID: ")
        contentType = input("Enter contentType: ")
        authorizationToken = input("Enter authorizationToken: ")
        
        json_data = {
            'contentID': str(contentID),
            'contentType': contentType,
            'authorizationToken': authorizationToken,
            'authorizationTokenType': '1',
            'licenseChallenge': b64encode(challenge).decode(),
            'playbackSessionCookie': None,
        }
        
        licence = self.session.post(url=license_url, json=json_data)
        licence.raise_for_status()

        license_b64 = licence.json()['licenseData'][0]
        cdm.parse_license(session_id, license_b64)

        for key in cdm.get_keys(session_id):
            if key.type == 'CONTENT':
                raw_key = f"{key.kid.hex}:{key.key.hex()}"
                all_keys.append(raw_key)

        cdm.close(session_id)
        
        self.console.print(f"\n[bright_green][ OK ][/bright_green] Getting keys", highlight=False)
        
        return all_keys
        
ripper = Ripper()
manual = ripper.start_process()
Editor is loading...
Leave a Comment