-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to deal with m3u8 without links in uri #311
Comments
This is the data I get |
Use the >>> import m3u8
>>> playlist = m3u8.load('http://cph-p2p-msl.akamaized.net/hls/live/2000341/test/master.m3u8')
>>> playlist.playlists[0].absolute_uri
http://cph-p2p-msl.akamaized.net/hls/live/2000341/test/level_0.m3u8 If you loaded the multivariant playlist from text rather than a URL, use >>> from urllib.parse import urljoin
>>> urljoin('https://example.org', 'hls/360/main.m3u8')
https://example.org/hls/360/main.m3u8 |
Alright, the absolute_uri doesn't worked for me But getting to the second point I added /hls/720/main.m3u8 at last of the url and I got this [link removed] But I have no idea how to deal with it |
Use the same trick with |
Yes but I think that this .ts file is encrypted |
You'll have to download the key and decrypt the Something like this: import m3u8
import requests
from urllib.parse import urljoin
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
base_url = '...' # Your URL here
playlist_text = '...' # Your text here
parsed_playlist = m3u8.loads(playlist_text)
seq_no = parsed_playlist.media_sequence or 0
key_data = {}
for n, segment in enumerate(parsed_playlist.segments, seq_no):
# Save the key for this segment if we don't have it already
key_url = segment.key.uri
if key_url not in key_data:
key_data[key_url] = requests.get(key_url).content
# Download the encrypted segment
segment_url = urljoin(base_url, segment.uri)
segment_data = requests.get(segment.key.uri).content
# The initialization vector is either given in the playlist or is the sequence number
iv = segment.key.iv or n.to_bytes(16, 'big')
# Decrypt with the key and IV
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
decryptor = cipher.decryptor()
decrypted_data = decryptor.update(segment_data) + decryptor.finalize()
# Do something with the decrypted data That's probably not going to work verbatim, but those are the right steps. |
Then why isn't it all required in the 1dm app? I'm confused whether I'm
going right
…On Wed, 25 Jan, 2023, 9:28 pm Bo Bayles, ***@***.***> wrote:
You'll have to download the key and decrypt the .ts files.
Something like this:
import m3u8import requestsfrom urllib.parse import urljoinfrom cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
base_url = '...' # Your URL hereplaylist_text = '...' # Your text here
parsed_playlist = m3u8.loads(playlist_text)seq_no = parsed_playlist.media_sequence or 0
key_data = {}
for n, segment in enumerate(parsed_playlist.segments, seq_no):
# Save the key for this segment if we don't have it already
key_url = segment.key.uri
if key_url not in key_data:
key_data[key_url] = requests.get(key_url).content
# Download the encrypted segment
segment_url = urljoin(base_url, segment.uri)
segment_data = requests.get(segment.key.uri).content
# The initialization vector is either give in the playlist or is the sequence number
iv = segment.key.iv or f'0x{n:032x}'
# Decrypt with the key and IV
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
decryptor = cipher.decryptor()
decrypted_data = decryptor.update(ts) + decryptor.finalize()
# Do something with the decrypted data
That's probably not going to work verbatim, but those are the right steps.
—
Reply to this email directly, view it on GitHub
<#311 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALYHMXXQSB2XG5O3VGJZUMDWUFETDANCNFSM6AAAAAAUGANNQE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Thanks for your support, I've managed to key the key and will try decrypting it soon. thanks a lot |
but the code that you sent is using key as string |
Try: |
|
II managed to do this and got the decrypted .ts file and it's playable. Thanks for your support sir |
as seen in this m3u8 file the uri can't be specified as a link.
How to download this type of file? Even it's possible to download using 1dm app in android
The text was updated successfully, but these errors were encountered: