The main advantage of this script is that it can download a bunch of TikToks, You just need to prepare .txt file, which contains links to videos.
Another advantage of this script, is that it does not depend on third party APIs or websites.
To use this downloader, You need clone this repository
git clone https://github.com/so1der/tiktok-downloader
cd tiktok-downloader
and install required libraries - Selenium, colorama, requests
pip install -r requirements.txt
You also need to download chromedriver, which matches Your browser version, from this website, and put it in the same directory as .py files. So to work correctly, there should be at least 4 files in one directory: main.py, headers.py, done.py and chromedriver.exe. So after You intall all requirements, and download chromedriver - You are ready to go! Just execute main.py, and enter link, or path to .txt file. You also can just drop .txt file into Your console window, its will write path to file itself.
python main.py
If You dont have python installed, or if You dont want to install all of these requirements, You can just download .exe file at Releases. Unfortunately in this case You still need to download chromedriver. However, I have put chromedriver, that works with 103.0.5060.114 version of Chrome in archive.
It supports all types of TikTok links
Links in .txt file must be divided by newline.
If you just inserting links in console window, you must divide them by Spacebar.
Yes, for now its works only with Google Chrome. But You can easily adapt it for other browser. You need to change these lines in method init_dirver to match Your browser's webdriver syntax:
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option('excludeSwitches', ['enable-logging'])
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(options=chrome_options)
Due to prevalence of Google Chrome, I decided to make downloader work with it. But if dont use Chrome, and cant edit code, but still want to use this downloader - contact me, and I will help.
I dont test this downloader on Linux, but I have a guess that You need to change 'PATH' in config.ini file, so downloader can work properly on Linux.
PATH = 'TikTokVideos\\'
As You can see, this variable contains path to folder in which videos will be downloaded. I suggest that in Linux this variable should be like this:
PATH = 'TikTokVideos/'
You can also change the folder name to Your liking.
Personally, I don't use tiktok, so thats why I wouldn't be able to fully test this downloader. But my friend did. He tested it with .txt file which contains 322 links to tiktok videos. You can see the results yourself. 322 videos downloaded in 15 minutes. Of course the speed also depends on Your internet connection, video length/quality, and PC specs, after all selenium operate a real browser. But despite this, it's still a good result I think.
- Downloader output " ↑ was skipped, can't find video URL" error to all links
This may be due to poor internet connection. The work of the downloader is arranged in such a way that it is waiting till certain "xgwrapper-4" block will appear. This block contains direct video URL, so if the block did not appear, the link may have led to the "Video currently unavailable" page. But if video is aviable, and downloader still output this error, You can increase "waiting" time, by changing TIME_OUT in config.ini
TIME_OUT = 10
# this will make downloader 'waiting' time equal to ten seconds
- Downloader should work, but for some reason it still doesn't work
A good way to debug problems is to comment out the line responsible for silently launching the browser:
chrome_options.add_argument("--headless")
↓
#chrome_options.add_argument("--headless")
This will allow You to see what happens on the webpage, and why downloader cant reach "xgwrapper-4" block for example.
- Downloader crash and closes instantly, I can't see error message
In this case You can execute downloader through terminal/cmd. Just enter:
python main.py
or
tiktok_downloader.exe
Or just drop .py/.exe file into console window. Even if it crush, it wont close cmd, this will allow You to see the error so You can fix it, or contact me.
- 0.5:
Code refactoring, now downloader is uses OOP.
- 0.4:
Added debug mode.
Fixed problem when counter doesnt update in exception
Links that could not download video now stored in 'undownloaded{session_date}.txt' file
- 0.3:
Reworked try-except block, so downloader wont break after exctept
- 0.2:
Reworked file-naming.
Added .ini config file
Despite that fact, that downloader already usable, it is still in the early stage of development. Thats why I will be very grateful for Your feedback. Together we can improve this downloader!