Python to download video from douyin

3 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

About the Author: Toc Xoan

This guy likes taking photos, hunting cheap tours, exploring the unique culture of every cities of Vietnam. Contact: [email protected]