Skip to content

Instantly share code, notes, and snippets.

@BazinkNoMore
Last active January 17, 2025 05:08
Show Gist options
  • Save BazinkNoMore/8a27cf8ff8fd654f785abbbc36843bc6 to your computer and use it in GitHub Desktop.
Save BazinkNoMore/8a27cf8ff8fd654f785abbbc36843bc6 to your computer and use it in GitHub Desktop.

TikTok Video Downloader Script for Microsoft Visual Studio Code/ Python

(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 for $0.99

Requirements - You must have your JSON file that you requested from TikTok in a new folder

image

Table of Contents

Installation

  1. Clone the repository:
 git clone https://gist.github.com/8a27cf8ff8fd654f785abbbc36843bc6.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
import os
import json
import re
import yt_dlp
# 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)}")
# Main script
def main():
input_file = "user_data_tiktok.json" # Path to your JSON file
output_folder = "Downloaded_TikTok_Videos" # Folder to save downloaded videos
# Create the output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)
# Load the JSON data
with open(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, output_folder)
print(f"All videos have been processed. Check the '{output_folder}' folder.")
if __name__ == "__main__":
main()

Copyright (c) 2011-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