Aiisc Sunday
Aiisc Sunday

Reputation: 75

Download Videos using python from ttdownloader

Hey guys I need some help, I am trying to download videos from this sitehttps://ttdownloader.com/dl.php?v=YTo0OntzOjk6IndhdGVybWFyayI7YjowO3M6NzoidmlkZW9JZCI7czoxOToiNjkxMjEwNzYyNzY1MjY5NzM1MCI7czozOiJ1aWQiO3M6MzI6Ijk0MTdiOWE3NWU2MmE3MDQ1NjZhYzk0MzJjMThlY2VlIjtzOjQ6InRpbWUiO2k6MTYxMTQ5NzE1ODt9 using python.

this is code I have tried.

import requests

url ='''https://ttdownloader.com/dl.php?v=YTo0OntzOjk6IndhdGVybWFyayI7YjowO3M6NzoidmlkZW9JZCI7czoxOToiNjkxMjEwNzYyNzY1MjY5NzM1MCI7czozOiJ1aWQiO3M6MzI6Ijk0MTdiOWE3NWU2MmE3MDQ1NjZhYzk0MzJjMThlY2VlIjtzOjQ6InRpbWUiO2k6MTYxMTQ5NzE1ODt9'''
page = requests.get(url)
with open('output.mp4', 'wb') as file:
    file.write(page.content)

But it doesnt work as expected, when i check page.content all I see is b''

Upvotes: 1

Views: 290

Answers (2)

anjandash
anjandash

Reputation: 827

❌ The link that you are using is NOT a html page.
❌ Therefore it doesn't return anything as html.

✅ Your link is a media link.
✅ Therefore you must stream it and download it. Something like this:

import requests

url = '/your/valid/ttdownloader/url'
with requests.get(url, stream=True) as r:
    with open('ouput.mp4', 'wb') as f:
        for chunk in r.iter_content(chunk_size=8192): 
            f.write(chunk)

NOTE:
The link that you posted in the question is now invalid.
Please try the above code with a newly generated link.

Upvotes: 1

Jaap Joris Vens
Jaap Joris Vens

Reputation: 3560

You should use request.urlretrieve to directly save the URL to a file:

from urllib import request 

url ='''https://ttdownloader.com/dl.php?v=YTo0OntzOjk6IndhdGVybWFyayI7YjowO3M6NzoidmlkZW9JZCI7czoxOToiNjkxMjEwNzYyNzY1MjY5NzM1MCI7czozOiJ1aWQiO3M6MzI6Ijk0MTdiOWE3NWU2MmE3MDQ1NjZhYzk0MzJjMThlY2VlIjtzOjQ6InRpbWUiO2k6MTYxMTQ5NzE1ODt9'''
request.urlretrieve(url, output.mp4)

However, this code gave me a urllib.error.HTTPError: HTTP Error 403: Forbidden error. It appears that this link is not publicly available without authentication.

Upvotes: 0

Related Questions