[PYTHON] DOWNLOAD ALL TIKTOK VIDEOS FROM A USER OF YOUR CHOICE!

This is a Python script that uses the TikTokApi library to download videos from a TikTok user's account without a watermark.

The script first requires the user to enter their TikTok username and the number of videos they want to download.

Then, it creates an instance of the TikTokApi class and uses the byUsername() method to fetch the specified number of videos of the given user.

Next, it creates a directory with the given username to store the downloaded videos.

Finally, it downloads each video without a watermark and saves it to the directory created earlier. The video's filename is the video ID followed by ".mp4".

Once all videos have been downloaded successfully, the script prints "All videos downloaded successfully!" to the console.

Read also : How to Get Free Members to Your Telegram Group



Code Here
import os
import requests
from TikTokApi import TikTokApi

# enter your TikTok username and the number of videos to download
username = "your_username"
num_videos = 50

# create TikTokApi instance
api = TikTokApi()

# get user's videos
user_videos = api.byUsername(username, count=num_videos)

# create directory to save videos
if not os.path.exists(username):
    os.makedirs(username)

# download videos without watermark
for video in user_videos:
    video_url = video['video']['downloadAddr']
    video_id = video['id']
    video_filename = f"{username}/{video_id}.mp4"
    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'}
    response = requests.get(video_url, headers=headers)
    with open(video_filename, "wb") as f:
        f.write(response.content)
    print(f"Downloaded video {video_id}")

print("All videos downloaded successfully!");

Read also : How to Create a Twitter Bot


How That code Work

Here is a step-by-step explanation of how the code works:

  1. The first two lines of code import the necessary libraries: os, requests, and TikTokApi.

  2. The user must provide their TikTok username and the number of videos they want to download.

  3. The code creates an instance of the TikTokApi class called "api".

  4. The byUsername() method of the TikTokApi class is called, which takes the username and number of videos as arguments. It returns a list of TikTok video objects.

  5. The script creates a directory with the given username to store the downloaded videos, if it does not already exist.

  6. The script then iterates through each video object returned from the byUsername() method.

  7. For each video object, the script extracts the video download URL, the video ID, and the video filename.

  8. It then sends a GET request to the download URL with the necessary headers to get the video content.

  9. The video content is then written to a new file with the video filename in the previously created directory.

  10. The script prints a message to the console indicating that the video has been downloaded successfully.

  11. Once all videos have been downloaded successfully, the script prints "All videos downloaded successfully!" to the console.

Note that this script only works if the TikTok account is public. If the account is private, the script won't be able to fetch the videos. Also, keep in mind that TikTok's terms of service prohibit unauthorized downloading of videos.

المقالة التالية المقالة السابقة
لا توجد تعليقات
اضـف تعليق
comment url