An SDK for tiktok and douyin which support download videos without water mark and upload videos. (upload videos not implement yet)
By using playwright
scrape the video page you specified, get the rendered source code, parse the source code and get the video file link, then use http client download the video file into your file system.
Note: Due to the anti-crawler policy, the video file link will change constantly, so sometimes this sdk won't get the video file. If you encounter this scenario, please let me know.
1, Python3, network connectivity to tiktok.com or douyin.com
2, clone the source code
$ git clone [email protected]:csrgxtu/eggplant.git
3, install dependencies
$ pip install -r requirements
4, prepare your cookie json file which will be used by script
- install chrome extension Get cookies.txt locally
- access tiktok.com or douyin.com in your chrome
- in the extension, select
json
export format and then clickExport
5, create your script in source root dir like following:
touch my_download_script.py
6, following two code snippet, the video file will be downloaded at your /tmp/
from eggplant import EggPlant, Source
from errors import Exceptions
from douyin import DouYin
cookie_path = "/tmp/www.douyin.com_cookies.json"
url = 'https://v.douyin.com/id1agpHj/'
async with DouYin(cookie_path) as dy:
err, video_file_path = await dy.download_video(url)
assert err == Exceptions.OK
assert ".mp4" in video_file_path
from eggplant import EggPlant, Source
from errors import Exceptions
from tiktok import TikTok
cookie_path = "/tmp/www.tiktok.com_cookies.json"
url = 'https://www.tiktok.com/@runningspeed0/video/7271406113080282373'
async with TikTok(cookie_path) as tiktok:
err, video_file_path = await tiktok.download_video(url)
assert err == Exceptions.OK
assert ".mp4" in video_file_path
1, make eggplant pip
installable
2, support upload video