Python to download video from douyin

134 Likes Comment
import requests
import re
import json
#Parse douyin URL
url=input("Enter your URL:")
userAgent = "Mozilla/5.0 ABCD"
header = {
    "Referer": "https://v.douyin.com/",
    'User-Agent': userAgent,
}
#Get video id
r = requests.get(url,headers = header)
url=r.url
id=url.split("video/")[1].split("/?")[0]
#Get watermark video url
url="https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+id
r = requests.get(url,headers = header)
#Get non-watermark video url
video=json.loads(r.content)["item_list"][0]
url=video["video"]["play_addr"]["url_list"][0]
url=url.replace("playwm","play")
#download the video file
r = requests.get(url,headers = header)
with open(video["desc"]+".mp4", "wb") as code:
     code.write(r.content)
     print("Download successfully!")
input("Press Enter to quit")

You might like

Avatar

About the Author: Toc Xoan

Leave a Reply

Your email address will not be published. Required fields are marked *