Home  >  Article  >  Backend Development  >  Python teaches you to quickly batch download Douyin watermark short videos

Python teaches you to quickly batch download Douyin watermark short videos

WBOY
WBOYforward
2023-04-10 15:21:032951browse

TikTokDownload is an open-source TikTok watermark video download tool developed by Chinese people. The open source address is: https://github.com/Johnserf-Seed/TikTokDownload

For some students who do video analysis and research, this tool is very useful and can quickly obtain video data.

Let’s introduce how to use this tool.

1. Preparation

Before you start, you must ensure that Python and pip have been successfully installed on your computer. If not, you can visit this article: Super Detailed Python Installation Guide to install it.

(Optional 1) If you use Python for data analysis, you can install Anaconda directly: Anaconda, a good helper for Python data analysis and mining, has built-in Python and pip.

( Optional 2) In addition, it is recommended that you use the VSCode editor, which has many advantages: The best partner for Python programming—VSCode Detailed Guide.

Please choose any of the following methods to enter commands to install dependencies: 1. Windows environment Open Cmd (Start-Run-CMD). 2. MacOS environment Open Terminal (command space and enter Terminal). 3. If you are using the VSCode editor or Pycharm, you can directly use the Terminal at the bottom of the interface.

git clone https://github.com/Johnserf-Seed/TikTokDownload.git
cd TikTokDownload
pip install -r requirements.txt

If your network environment cannot access Github, you can reply TikTokDownload in the background of the Python Practical Collection official account to download the latest Source code (2023-02-27).

2. Douyin watermark removal short video download method

Before running the software, open the conf.ini file in the directory and configure it according to the requirements:

Python teaches you to quickly batch download Douyin watermark short videos

After the configuration is completed, create a new py file in the TikTokDownload directory and fill in the following code to use:

# example.py
import TikTokDownload as TK
import Util

# 单视频下载
# TK.video_download(*TK.main())

# 批量下载
if __name__ == '__main__':
# 获取命令行参数
cmd = Util.Command()
# 获取用户主页数据
profile = Util.Profile()
# 使用参数,没有则使用默认参数并下载
profile.getProfile(cmd.setting())
# 如果需要定时下载则注释这个input
input('[ 完成 ]:已完成批量下载,输入任意键后退出:')

The effect is as follows:

Python teaches you to quickly batch download Douyin watermark short videos

The video will be saved in the Download directory of the current directory by default.

If you only want to download a single video, you can download it through TK.video_download

import TikTokDownload as TK
TK.video_download("视频链接", "yes")

Video_download The first parameter is the original link of the video, and the second parameter indicates whether to download the original music sound, yes for download.

3. Batch multi-user download

By modifying the configuration, we can only download short videos for each user one by one. Each time we download a new user's short video, we must modify the configuration. This very troublesome.

What should we do if we want to download short videos for all users in one run?

The method is very simple. We put the Douyin account we want to download and the corresponding Userid in rooms.txt, separated by commas:

1545798353,MS4wLjABAAAAdv-v-WcZO48UMZRDLB-huZxYObcxv5Z5FFWXKw4-o_8
135180247,MS4wLjABAAAAtmTX6GSVN_AFW792_8srxdu1kPNXkuSGoG8Xl8xDHbE

Use the code below to Download all short videos of the two authors.

# 公众号:Python实用宝典
import Util

def read_rooms():
f = open("rooms.txt", "r", encoding="utf-8")
short_rooms = ["https://www.douyin.com/user/" + l.strip("n").split(",")[1] for l in f.readlines()]
return short_rooms

# 批量下载
if __name__ == '__main__':
userids = []
cmd = Util.Command()
for room in read_rooms():
setting = cmd.setting()
setting[0] = room
# 获取用户主页数据
profile = Util.Profile()
# 使用参数,没有则使用默认参数并下载
profile.getProfile(tuple(setting))

Save it as batch_download.py in the TikTokDownload directory, and then use Python to run the py file:

cd TikTokDownload
python batch_download.py

Python teaches you to quickly batch download Douyin watermark short videos

4 .Common mistakes

  • Single video links and user homepage links must be distinguished. Links must be entered carefully. The configuration file only supports user homepages.
  • Be sure to pay attention to the encoding format of the configuration file (Notepad is recommended)

Python teaches you to quickly batch download Douyin watermark short videos


The above is the detailed content of Python teaches you to quickly batch download Douyin watermark short videos. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete