Skip to content

Instantly share code, notes, and snippets.

@frozenpandaman
Last active April 22, 2025 16:32
Show Gist options
  • Save frozenpandaman/a91f4dc7b999499761f798fdd6da6129 to your computer and use it in GitHub Desktop.
Save frozenpandaman/a91f4dc7b999499761f798fdd6da6129 to your computer and use it in GitHub Desktop.
download videos protected with widevine DRM

Downloading Widevine content

Specifically from Rakuten TV (live.tv.rakuten.co.jp)

FMI: https://cdm-project.com/How-To/ & https://old.reddit.com/r/Piracy/comments/y30ffr/

Setup

  1. Install Tampermonkey: https://www.tampermonkey.net/
  2. Install yt-dlp: https://github.com/yt-dlp/yt-dlp#installation
  3. Install ffmpeg: https://ffmpeg.org/download.html
  4. Download Bento4: https://www.bento4.com/downloads/
  5. Have a proxy/VPN if you're not in Japan since stuff is geolocked

Getting your decryption key

Get PSSH

  1. Install this userscript: https://greasyfork.org/en/scripts/373903-eme-logger
  2. Search browser JS Console for MediaKeySession::generateRequest, then press play on the video and look under "Init Data"
  3. Get something like AAAAMnBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAXXXXXXXXFtoyTEzFOZDD4T9lmTiI=

Get License URL

  1. After doing the above, go to your browser developer tools' Network tab and search for Widevine
  2. Right click > Copy > Copy link address
  3. Get something like https://azcp001.keydelivery.japaneast.media.azure.net/Widevine/?kid=e0c5b68c-9313-314e-6430-f8XXXXXXXX22

Get headers

  1. Left click on the Widevine entry from the above steps, under the "Headers tab" scroll down to "Request Headers"
  2. Copy the following lines & do some manual formatting, get something like:
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,ja-JP;q=0.8,ja;q=0.7
Authorization: blahblah
Cache-Control: no-cache
Content-Length: "blahblah"
Origin: https://live.tv.rakuten.co.jp
Pragma: no-cache
Referer: https://live.tv.rakuten.co.jp/
User-Agent: blahblah

Getting the key

  1. Open https://cdrm-project.com/
  2. Input the results from the previous steps and press "Send"
  3. Hopefully see the "SUCCESS" message along with a key that looks like e0c5b68c93133XXXXXXXX84fd9664e22:499047f36b770957XXXXXXXX9dfc4033

Downloading the encrypted files

  1. In the developer console Network tab, search for mpd
  2. Find something that starts with Manifest, right click and copy the URL, e.g. https://azclwds01.akamaized.net/9dc3547a-ede5-4aed-841f-5cXXXXXXXX0f/tXyKyP_tab_hd.ism/Manifest(format=mpd-time-csf,encryption=cenc,filter=pc_hd_001)
  3. Run the Terminal command: yt-dlp --allow-unplayable [url]
  4. Get two files, an .mp4 and an .m4a

Decrypting & merging the files

  1. In Bento4's bin/ folder, find the mp4decrypt command line utility
  2. Navigate to this folder in your Terminal and run mp4decrypt --key [yourkey] /path/to/corrupted.file /path/to/fixed.file on both files
  3. Run ffmpeg -i fixedvideo.mp4 -i fixedaudio.m4a -c:v copy -c:a copy output.mp4
  4. The end
@2142070
Copy link

2142070 commented Sep 22, 2024

Does it work with "channel.rakuten.co.jp"?

Free video example: https://channel.rakuten.co.jp/videos/200973

@frozenpandaman
Copy link
Author

@2142070 Not sure, no experience with that subdomain/site. Try it and let me know!

@2142070
Copy link

2142070 commented Sep 24, 2024

@frozenpandaman I was able to do so. Just change the “Headers” and search for “m3u8” (instead of mpd).

...::: PSSH (Init Data Type) :::...

Search (console): MediaKeySession::generateRequest
Example: AAAAP3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAAB8SEKfYZ9e5qkL1sIwuzT3T54UaBWV6ZHJtSOPclZsG

...::: License URL :::...

Search (Network tab): Widevine
Example: https://widevine-dash.ezdrm.com/proxy?pX=97B7F0&token=b5c4e79ce6e5401386376d0260b2a62d

...::: Headers :::...

Only this (Python formatt): {'x-dt-auth-token': 'token',}
Token (from "license url"): b5c4e79ce6e5401386376d0260b2a62d
Example: {'x-dt-auth-token': 'b5c4e79ce6e5401386376d0260b2a62d',}

...::: Key :::...

Example: a7d867d7b9aa42f5b08c2ecd3dd3e785:83ddcbfbae399debe2114884b4ac5b08

...::: Encrypted files :::...

Search (Network tab): m3u8
Example: https://d3lz3061imcwu3.cloudfront.net/avod/Rakuten-TV-Japan-ANIM2-rakutenJP-all-avod/as_153831/as_153831.m3u8?ads.device_make=rchweb&ads.url=channel.rakuten.co.jp&ads.uuid=bfeee50f-0eca-52ee-86f8-8e0bd5cfbe2b&ads.uid_rch=bfeee50f-0eca-52ee-86f8-8e0bd5cfbe2b&ads.episode_id=200973&ads.refid=0

@koubafire
Copy link

I cant get this working for Rakuten.de for Movie Deadpool for example. CDRM Still says python not correctly formated.

@npsmalley
Copy link

Will this work with Plex?

@2142070
Copy link

2142070 commented Oct 10, 2024

I cant get this working for Rakuten.de for Movie Deadpool for example. CDRM Still says python not correctly formated.

Use "Copy as cURL (bash)" and paste in this web for get headers in python format: https://curlconverter.com/python/

@koubafire
Copy link

I cant get this working for Rakuten.de for Movie Deadpool for example. CDRM Still says python not correctly formated.

Use "Copy as cURL (bash)" and paste in this web for get headers in python format: https://curlconverter.com/python/

can you make step by step tutorial how to download 5.1 audio from rakuten?

@kevle1
Copy link

kevle1 commented Mar 15, 2025

For those having an issue parsing the headers with CDRM

An error occurred getting headers
invalid syntax (, line 1)

Try right-clicking on the license request in the Network tab, then choose Copy -> Copy As Fetch (Node.js), then click the yellow "Paste from Fetch" button on the CDRM form, then submit.

Note: My Widevine license URL looked like https://ottapp-appgw-amp.prodc.mkio.tv3cloud.com/drm/widevine-license

@iambatosai93
Copy link

can we do .mkv?

@theguy000
Copy link

theguy000 commented Apr 22, 2025

Note: /path/to/corrupted.file is the encrypted mp4 file. and /path/to/fixed.file is where you want the fixed/decrypted mp4 file to be

@kevle1
Copy link

kevle1 commented Apr 22, 2025

@theguy000

i dont understand the /path/to/corrupted.file wdym by corrupter file? the mp4 and m4a?

That's the path to the output from yt-dlp, run the mp4decrypt command for both the mp4 and m4a which are currently unplayable as they are encrypted :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment