In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use Python to download Douyin unwatermarked videos, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Python download
First of all, let's take a look at the results of directly visiting the Douyin link.
A proper watermark.
Next, open the developer tool of the browser and see the address of the video.
You can find that "playAddr" is the address of the video, copy it and then access it.
The link will be redirected to the link that starts with "v9", but there is still a watermark.
The next point is, first of all, you need to enable your browser to modify UA, the "User-Agent" that crawlers often use.
I use Mac+ Google browser, so tell me how I modified it myself.
For Windows, please make your own Baidu ~
First, create a folder in the manuscript on your computer.
The path to this folder is as follows.
/ Users/star-river/Documents/MyChrome
And run the following code on the terminal of the root directory.
Open-n / Applications/Google\ Chrome.app/-args-disable-web-security-user-data-dir=/Users/star-river/Documents/MyChrome
In this way, my Google browser can successfully replace UA!
Or directly visit the Douyin link, you can see that the result is different from the original.
Find the interface in this mode.
It is found that the interface that starts with "? item_ids" contains the unwatermarked Douyin video we want.
These are the two links in the list under "play_addr".
The interface that starts with "? item_ids" has two parameters that we need to get in another interface.
So we also know the values of "item_ids" and "dytk" parameters.
However, we directly use the browser to access the two links will not directly appear in the video, need to be the same as above.
Also change the UA. If the link here is also accessed with the UA of "iPhone X", it will fail.
What is the reason, Xiao F is unknown.
Change the browser UA to "Responsive" and the link will be redirected.
In this way, the unwatermarked Douyin video is done.
But if every video needs to be downloaded like this, it will be too troublesome.
So write the code that you can download the video with Python.
Import requestsimport jsonimport reheaders = {'accept':' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/ajpg,*/*;q=0.8', 'accept-encoding':' gzip, deflate, br', 'accept-language':' zh-CN,zh;q=0.9,en 0.8, 'cache-control':' max-age=0', # this seems to be very important 'User-Agent':' Mozilla/5.0 (Linux; Android 6. 0 Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36',} def download (url): "download Douyin unwatermarked video" # get the API parameters html = requests.get (url=url, headers=headers) title = re.findall ('itemId: "(. *?)",' Html.text) [0] dytk= re.findall ('dytk: "(. *?)"}', html.text) [0] # splicing interface url_item = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' + title +' & dytk=' + dytk # get Douyin unwatermarked video link html_item = requests.get (url=url_item Headers=headers) # string conversion dictionary content = json.loads (html_item.text) # Video Interface url_video = content ['item_list'] [0] [' video'] ['play_addr'] [' url_list'] [1] response = requests.get (url_video, headers=headers, allow_redirects=True) # get the redirected link, which is also the download link for unwatermarked videos But this time redirect = response.url print (redirect) # video is binary, so you need this download method: video = requests.get (url_video, headers=headers). Content video_name = "douyin.mp4" with open (video_name) 'wb') as f: f.write (video) f.flush () print ("download completed") if _ _ name__ =' _ _ main__': # Douyin link url = 'https://v.douyin.com/XJj85H/' download (url)
Perfect download of unwatermarked video.
Interface download
Now that you know how to download videos with Python.
So Xiao F wanted to make it easier for everyone to download, so he deployed the program to the server.
You only need to download the video through the interface of Xiao F, the code is as follows.
From flask import Flask, request, send_fileimport requestsimport jsonimport reapp = Flask (_ _ name__) # only accept get method access @ app.route ("/ douyin/", methods= ["GET"]) def check (): headers = {'accept':' text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/ajpg,*/* Max-age=0', 0.8, 'accept-encoding':' gzip, deflate, br', 'accept-language':' zh-CN,zh;q=0.9,en;q=0.8', 'cache-control':' max-age=0', 'User-Agent':' Mozilla/5.0 (Linux; Android 6.0) Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Mobile Safari/537.36',} # default returned content return_dict = {'code': 1,' result': False 'msg':' request succeeded'} # determine whether the input parameter is empty if request.args is None: return_dict ['return_code'] =' 504' return_dict ['return_info'] =' request parameter is empty 'return json.dumps (return_dict Ensure_ascii=False) # get the passed parameter get_data = request.args.to_dict () url= get_data.get ('url') # get the interface parameter html = requests.get (url=url, headers=headers) title = re.findall (' itemId: "(. *?),', html.text) [0] dytk = re.findall ('dytk:" (. *?) "}' Html.text) [0] # stitching interface url_item = 'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids=' + title +' & dytk=' + dytk # get Douyin unwatermarked video link html_item = requests.get (url=url_item Headers=headers) # string conversion dictionary content = json.loads (html_item.text) # get video related information # data = {} # description of video # data ['videoDesc'] = content [' item_list'] [0] ['desc'] # cover image of video Small image # data ['dynamiCoverUrl'] = content [' item_list'] [0] ['video'] [' dynamic_cover'] ['url_list'] [0] # cover image of the video Large image # data ['staticCoverUrl'] = content [' item_list'] [0] ['video'] [' origin_cover'] ['url_list'] [0] # comments on the video # data [' comments'] = content ['item_list'] [0] [' statistics'] ['comment_count'] # likes on the video # data [' prise'] = content ['item_list'] [0] [ 'statistics'] [' digg_count'] # Video interface url_video = content ['item_list'] [0] [' video'] ['play_addr'] [' url_list'] [1] response = requests.get (url_video) Headers=headers, allow_redirects=True) # get the redirected link, which is also the download link for unwatermarked videos, but this time the download link for redirect = response.url # print (redirect) # video is not used # data ['videoPlayAddr'] = redirect # returns the video information # return_dict [' result'] = data # returns the result # return json.dumps (return_dict) Ensure_ascii=False) video = requests.get (url=redirect, headers=headers). Content video_name = "douyin.mp4" with open (video_name 'wb') as f: f.write (video) f.flush () return send_file (' douyin.mp4') if _ _ name__ = "_ _ main__": # Local debugging app.run (debug=True) # deployment # app.run (host='127.0.0.1', port=443)
If Flask and Requests libraries are installed locally, this program can be run directly.
And you can download the unwatermarked Douyin video you want.
# Local API
Http://127.0.0.1:500/douyin/?url=https://v.douyin.com/CoQBx1/
If deployed to the server, port 443 is required.
The above is all the content of this article "how to use Python to download Douyin unwatermarked videos". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.