robots.txt
robots.txt

Reputation: 137

Could not download a video from a link using requests

I'm created a script to download a video from this link. The way I've tried so far doesn't seem to be working at all.

import requests

video_link = 'https://resources.newscdn.com.au//cs//video//vjs//stable//build//index.html?id=5348771529001-5977442689001&=domain=del'

with requests.Session() as s:
    s.headers['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36'
    with open("delicious.mp4","wb") as f:
        f.write(s.get(video_link,stream=True).content)

How can I download the video from the link above?

Upvotes: 1

Views: 333

Answers (1)

Johnny
Johnny

Reputation: 694

import requests


headers = {'User-Agent': 'Mozilla/4.0(compatible;MSIE7.0;WindowsNT5.1;AvantBrowser)'}

with open("delicious.ts", 'wb') as f:
    for i in range(6):
        url = 'https://nws-bolt-amd-prod.akamaized.net/media/v1/hls/v4/clear/5348771529001/817d6bbd-f04a-4be7-8df1-7840daea9951/7bbe9b18-1754-4cfc-b110-ee9a08d94589/5x/segment{}.ts?akamai_token=exp=1615091351~acl=/media/v1/hls/v4/clear/5348771529001/817d6bbd-f04a-4be7-8df1-7840daea9951/7bbe9b18-1754-4cfc-b110-ee9a08d94589/*~hmac=4882307c77be752bf8972da100c9ee65dd091dc6a225eea9727dd55e92751300'.format(
            i)
        response = requests.get(url, headers=headers, stream=True)
        f.write(response.content)

enter image description here

Upvotes: 2

Related Questions