Skip to content

Instantly share code, notes, and snippets.

@BazinkNoMore
Forked from thehappydinoa/README.md
Last active January 29, 2025 00:59
Show Gist options
  • Save BazinkNoMore/59e1be7269dc865ed73efbdd9f0c7056 to your computer and use it in GitHub Desktop.
Save BazinkNoMore/59e1be7269dc865ed73efbdd9f0c7056 to your computer and use it in GitHub Desktop.

TikTok Video Downloader Python Script

(1/16/2025) Currently 3 days before the ban. I know this is last minute, I'm sorry I literally just got the script to work as intended. Anyways, this Python script will automatically download ALL your liked, favorited, DM'd videos as well as recent history videos with no watermarks and no audio delays. Still testing as we speak so I'll share more info as time passes. Forewarning, you may want to use VLC Media Player on Windows to open a majority of your downloaded TikToks. There is also a codec for the regular media player that you can purchase from Microsoft for $0.99: https://apps.microsoft.com/detail/9NMZLZ57R3T7?hl=en-us&gl=US&ocid=pdpshare

If for any reason you need to stop the script from running in Visual Studio Code, use this shortcut: (Ctrl + C)

Table of Contents

Requirements - You must have your JSON file that you requested from TikTok in a 'New Folder'

image

(Note) Wherever you make the 'New Folder' is where all the videos will be downloaded to. I have the file on my desktop for example

image image

Next, you want to open Notepad and copy/paste the script onto it.

image

Then you want to save the code as 'download_tiktok_videos_yt_dlp.py'. To do that, just replace the ".txt" with "download_tiktok_videos_yt_dlp.py"

Make sure you save it in the New Folder that you created with the 'user_data-tiktok.JSON' file image

Your New Folder should look just like this.

image

Your file is all set! Next you want to open Miscrosoft Visual Studio Code. You can install the app here: https://code.visualstudio.com

image

You then want to click this side icon for extensions. You want to search and install these Python extensions first before doing anything. For this tutorial, I installed this specific version of Python https://apps.microsoft.com/detail/9NRWMJP3717K?hl=en-us&gl=US&ocid=pdpshare

After you install Python, you want to restart Visual Studio Code by closing it and opening it again.

image

After you installed the Python extensions, click 'File' on the top and then click 'Add Folder to Workspace...'

image

A file browser will open. You want to go to the New Folder that you created earlier that has the 'user_data_tiktok' file and the 'download_tiktok_videos_yt_dlp' file. Once you find it in the file browser, it will appear as if it is empty. Do not panic, the files are still there. You then want to click the 'Add' button on the bottom-right of the window.

image

There will be a message that pops up. Click 'Yes'

After you add the folder to the workspace. Go to this side icon and click it. You will now see both your JSON file and your Python file are in the workspace.

image

Next you want to click on your Python file in the workspace.

image

Then you want to go to the top of the window and click 'Terminal'. After that, click 'New Terminal'

image

A new menu will appear at the bottom of the window. The path to your New Folder will already be in the terminal. (Note: Your path may look different than how it appears here. As long as you see (\New Folder) at the end of the path, then you're good to go)

image

Important Note!

On the lower right corner, you may see a different version of Python there. You must click on that tab to change the 'Interpreter'.

image

A small window will appear on the top of the screen. Make sure you select the Python interpreter that has the 'Global' lable at the end.

image

Now you're almost ready.

Now you want to install these Python extensions within the terminal. Just type this line in then press 'Enter' on your keyboard.

you will see the terminal install these extensions. image

And finally, you want to put this command in the line just like how you did with the extensions, then hit 'Enter'

image

Then that's it! The script is now running and your videos will start downloading one by one in that terminal. It will take a long time so I suggest you leave you computer alone until it is complete. Do not try to move the videos to another folder while the script is downloading your videos or try to update any programs or games in the background. This could cause your computer to slow down and\or freeze. (UPDATE as of 1/18/25) You can move the videos to another spot where you have more space while the script is still downloading your videos. HOWEVER, you should only do it in very small groups at a time. Say 20 or 50 videos at a time. You can try to do more if you want, just be cautious. Make sure you're actually moving the videos to your new spot and not just copying them. Use (Cut/Paste instead of Copy/Paste)

image image

Speaking of folders. You remember that 'New Folder' you created? The script will create another folder in that same place. That will contain all of your Tiktoks as they're being downloaded.

image

If for any reason you need to stop the script from running in Visual Studio Code, use this shortcut: (Ctrl + C)

P.S. The script skips over videos that have been taken down, so you don't have to worry about those appearing in your downloads file. And no, there is no way to make those videos work again unfortunately :(

Installation

  1. Clone the repository:
git clone https://gist.github.com/43327d54f5bd6b854916d095a1a42b8d.git
  1. Install dependencies:
pip install requests pytube yt-dlp

Usage

To run the project, use the following command:

python download_tiktok_videos_yt_dlp.py user_data_tiktok.json output/
import os
import json
import re
import yt_dlp
import argparse
# Function to recursively extract TikTok video links
def extract_tiktok_links(data):
links = []
if isinstance(data, dict):
for key, value in data.items():
links.extend(extract_tiktok_links(value))
elif isinstance(data, list):
for item in data:
links.extend(extract_tiktok_links(item))
elif isinstance(data, str):
if re.match(r'https://www\.tiktokv\.com/share/video/\d+', data):
links.append(data)
return links
# Function to download videos using yt-dlp
def download_video_with_ytdlp(url, output_folder):
ydl_opts = {
'outtmpl': os.path.join(output_folder, '%(id)s.%(ext)s'), # Save with video ID as the filename
'format': 'mp4', # Ensure videos are saved as .mp4
'quiet': False, # Show download progress
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
print(f"Downloaded: {url}")
except Exception as e:
print(f"Failed to download {url}: {str(e)}")
# Function to handle command-line arguments
def parse_arguments():
parser = argparse.ArgumentParser(description="Download TikTok videos from a JSON file containing links.")
parser.add_argument("input_file", type=str, help="Path to the JSON file containing TikTok video links")
parser.add_argument("output_folder", type=str, help="Directory where downloaded videos will be saved")
return parser.parse_args()
# Main script
def main():
args = parse_arguments()
# Create the output folder if it doesn't exist
os.makedirs(args.output_folder, exist_ok=True)
# Load the JSON data
with open(args.input_file, 'r', encoding='utf-8') as f:
data = json.load(f)
# Extract video links from the JSON data
video_links = extract_tiktok_links(data)
print(f"Found {len(video_links)} video links.")
# Download each video
for link in video_links:
download_video_with_ytdlp(link, args.output_folder)
print(f"All videos have been processed. Check the '{args.output_folder}' folder.")
if __name__ == "__main__":
main()

Copyright (c) 2025 BazinkNoMore

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment