Jayapraveen / Drm-Dash-stream-downloader

This script helps to download drm protected dash stream [if key is known] and output to a video mp4 file
MIT License
150 stars 94 forks source link

Wiki #5

Open AlvaroBeiro opened 3 years ago

AlvaroBeiro commented 3 years ago

A bit more info on a how to would be great. Even if it's a one line example of usage.

Jayapraveen commented 3 years ago

Please look at the updated readme for clarity.

forhobbie commented 3 years ago

Hi! I spent the whole day trying to make it work, with different video sources, with the multisegment and the single segment... always the same error. I am very new to phyton so hopefully it´s an easy-to-solve issue?

This is the message I keep getting: C:\Users\luis\DRM\dashdownloader.py:77: SyntaxWarning: "is" with a literal. Did you mean "=="? if video.status_code is 200: Traceback (most recent call last): File "C:\Users\luis\DRM\dashdownloader.py", line 142, in video_url,video_keyid,audio_url,audio_keyid = manifest_parser(mpd) File "C:\Users\luis\DRM\dashdownloader.py", line 65, in manifest_parser for prot in adapt_set.content_protections: TypeError: 'NoneType' object is not iterable

Any idea? Thanks!

Jayapraveen commented 3 years ago

Looking at the error, I suspect that the manifest has either no Content protection mentioned or is using cbcs or other cipher suites. If you could attach the manifest link, I could suggest you the modification needed.

forhobbie commented 3 years ago

Thanks! 2 examples I am after: https://shift72d-131.akamaized.net/50ca514a-f3a8-4fdf-a16f-9d5ee04fe4a2/236617/reel_rock_15.mpd https://dmf9cnjua2s32.cloudfront.net/media/AV2AW6FPZiChQ/ad38062f/stream.mpd I can also send you the links with the KEY in private if that helps

Jayapraveen commented 3 years ago

You can try the quickfix commit (d5fbdf1) for the mpd on cloudfront. For the other you'll have to use the multisegmented one. Before running the multisegment, modify the mpd parser for that manifest. You'll probably need to look at mp4box packaging (gpac) for info on how to modify the mpd parser.

forhobbie commented 3 years ago

Thanks. For the cloudfront, video and audio are downloaded (but encrypted?) , and I get on cmd the message "Key not found". Something I have to adapt on the keyfile.json? Elsewhere?

Jayapraveen commented 3 years ago

The script needs the key that was used to encrypt them in the first place. If you have the key and the keyID, you'll need to insert them in the keyfile.json without changing the format.

forhobbie commented 3 years ago

Yes, thanks. I did and it works perfectly. Great work, and thanks for sharing!

AlvaroBeiro commented 3 years ago

Hi. I'm having this error:

Traceback (most recent call last):
  File "D:\Downloads\Drm-Dash-stream-downloader-master\Drm-Dash-stream-downloader-master\dashdownloader_multisegment.py", line 213, in <module>
    media_info = manifest_parser(mpd)
  File "D:\Downloads\Drm-Dash-stream-downloader-master\Drm-Dash-stream-downloader-master\dashdownloader_multisegment.py", line 176, in manifest_parser
    running_time = durationtoseconds(mpd.media_presentation_duration)
  File "D:\Downloads\Drm-Dash-stream-downloader-master\Drm-Dash-stream-downloader-master\dashdownloader_multisegment.py", line 61, in durationtoseconds
    second = seconds.match(period).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

Do you know by any chance what's wrong?

Jayapraveen commented 3 years ago

The regex pattern for seconds failed to extract seconds information. I'm really unsure why it failed, Ill rollout a fix for this.

AlvaroBeiro commented 3 years ago

So did you find what was causing it? Because I have no clue.

Jayapraveen commented 3 years ago

Fixed in the latest release.

AlvaroBeiro commented 3 years ago

Now I'm closer, thanks! But still it throws an error:

0 2 8 1.920
audio/mp4
Traceback (most recent call last):
  File "D:\Descargas\Drm-Dash-stream-downloader\dashdownloader_multisegment.py", line 212, in <module>
    media_info = manifest_parser(mpd)
  File "D:\Descargas\Drm-Dash-stream-downloader\dashdownloader_multisegment.py", line 177, in manifest_parser
    for segment in repr.segment_templates:
TypeError: 'NoneType' object is not iterable

Thank you so much.

Jayapraveen commented 3 years ago

It is because you havent modified the mpd parser according to your manifest.

miztertea commented 3 years ago

It is because you havent modified the mpd parser according to your manifest.

I am having a similar issue:

Total time: 0 days 0 hours 44 minutes and 26.530312 seconds Processing audio/mp4 Media segments are of equal timeframe Traceback (most recent call last): File "dashdownloader_multisegment.py", line 212, in <module> media_info = manifest_parser(mpd) File "dashdownloader_multisegment.py", line 197, in manifest_parser for prot in repr.content_protections: TypeError: 'NoneType' object is not iterable

Can you help me understand what are some example moidfications to the mpd parser?

Jayapraveen commented 3 years ago

The MPD or Manifest contains the media information for Playback, We have to extract the Media information especially how the media is segmented , timeframe details , encryption scheme used and the url for the segments. The mpd parser function is used to grab those information. I have not used third party downloaders for downloading and merging the media segments as some vendors have made changes to the manifest to make thirdparty tools fail downloading properly, thats why we need to customize the function to every usecase.

  1. The best way to make the customizations yourself is get the sample of the manifest.
  2. Try to compare the iteration operation done by the mpdparser function on various attributes of the Manifest.
  3. Once you have an idea on what each step of the function is doing, recreate the same according to your manifest file.
steamupeu commented 3 years ago

i m getting this error File "dashdownloader_multisegment.py", line 204, in media_info = manifest_parser(mpd) File "dashdownloader_multisegment.py", line 163, in manifest_parser running_time = durationtoseconds(mpd.media_presentation_duration) File "dashdownloader_multisegment.py", line 50, in durationtoseconds if(period[:2] == "PT"): TypeError: 'NoneType' object has no attribute 'getitem'

my mpd url hav this publishTime="2021-06-04T11:51:54Z" minimumUpdatePeriod="PT30S" availabilityStartTime="2021-06-02T14:02:08Z" minBufferTime="PT6S" suggestedPresentationDelay="PT20S" timeShiftBufferDepth="PT10M0S" profiles="urn:mpeg:dash:profile:isoff-live:2011"> <AdaptationSet mimeType="video/mp4" frameRate="25/1" segmentAlignment="true"

Jayapraveen commented 3 years ago

@fijo33, The mpd link should be replaced with the sample one in the driver code found at https://github.com/Jayapraveen/Drm-Dash-stream-downloader/blob/1d2d2edc6d7b87f08744cb7979e6e7843a90231c/dashdownloader_multisegment.py#L209

steamupeu commented 3 years ago

i m getting this error File "dashdownloader_multisegment.py", line 204, in media_info = manifest_parser(mpd) File "dashdownloader_multisegment.py", line 163, in manifest_parser running_time = durationtoseconds(mpd.media_presentation_duration) File "dashdownloader_multisegment.py", line 50, in durationtoseconds if(period[:2] == "PT"): TypeError: 'NoneType' object has no attribute 'getitem'

my mpd url hav this publishTime="2021-06-04T11:51:54Z" minimumUpdatePeriod="PT30S" availabilityStartTime="2021-06-02T14:02:08Z" minBufferTime="PT6S" suggestedPresentationDelay="PT20S" timeShiftBufferDepth="PT10M0S" profiles="urn:mpeg💨profile:isoff-live:2011"> <AdaptationSet mimeType="video/mp4" frameRate="25/1" segmentAlignment="true"

Jayapraveen commented 3 years ago

@fijo33, Need stack trace. Looks like the request to your manifest needs some authentication.

Jayapraveen commented 3 years ago

@steamupeu, You will need to modify the script as mentioned.

The MPD or Manifest contains the media information for Playback, We have to extract the Media information especially how the media is segmented , timeframe details , encryption scheme used and the url for the segments. The mpd parser function is used to grab those information. I have not used third party downloaders for downloading and merging the media segments as some vendors have made changes to the manifest to make thirdparty tools fail downloading properly, thats why we need to customize the function to every usecase.

  1. The best way to make the customizations yourself is get the sample of the manifest.
  2. Try to compare the iteration operation done by the mpdparser function on various attributes of the Manifest.
  3. Once you have an idea on what each step of the function is doing, recreate the same according to your manifest file.
Jayapraveen commented 3 years ago

@fijo33, I can help you, if you give a better understanding of what youre trying to do, what you did and what didnt work out.

andrewzhong1122 commented 3 years ago

Does this work with dynamic mpd? Thanks

Masterbasterx commented 3 years ago

I am getting Traceback (most recent call last): File "dashdownloader_multisegment.py", line 212, in <module> media_info = manifest_parser(mpd) File "dashdownloader_multisegment.py", line 170, in manifest_parser mpd = MPEGDASHParser.parse("./manifest.mpd") File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\mpegdash\parser.py", line 31, in parse return parse_child_nodes(xml_root_node, 'MPD', MPEGDASH)[0] TypeError: 'NoneType' object is not subscriptable while trying from https://edgecastcdnsecure.hbogo.eu/d919b023-606c-6b89-f4e3-45ac1567acef_m125765_hbo/COMP/139896597_pol_comp_2e7ef8a5-dc90-4bfc-99ea-f2247ac75e50_3400000_v2.ism/manifest

manafn commented 3 years ago

can you plz make a video how you use it , we are not that techy