From 6ab2ca174a076d61dd88166dc2720955e8a568e3 Mon Sep 17 00:00:00 2001 From: vgvr0 <126200367+vgvr0@users.noreply.github.com> Date: Sat, 13 Apr 2024 15:26:23 +0200 Subject: [PATCH] Add files via upload --- TikTokDownloader.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 TikTokDownloader.py diff --git a/TikTokDownloader.py b/TikTokDownloader.py new file mode 100644 index 0000000..8b65035 --- /dev/null +++ b/TikTokDownloader.py @@ -0,0 +1,35 @@ +from tiktok_scraper import TikTokScraper +import os + +def download_tiktok_video(video_url, output_dir): + """ + Downloads a TikTok video from the given URL and saves it to the specified directory. + + Args: + video_url (str): URL of the TikTok video. + output_dir (str): Destination directory where the downloaded video will be saved. + """ + try: + scraper = TikTokScraper() + video_path = scraper.download_video(video_url, output_dir) + print("Downloaded video:", video_path) + + # Additional functionality: Rename the downloaded video + video_name = os.path.basename(video_path) + new_video_name = f"tiktok_{video_name}" + new_video_path = os.path.join(output_dir, new_video_name) + os.rename(video_path, new_video_path) + print("Renamed video:", new_video_path) + + # Additional functionality: Get video metadata + video_metadata = scraper.get_video_metadata(video_url) + print("Video metadata:", video_metadata) + + except Exception as e: + print("Error:", str(e)) + +# Example usage +if __name__ == "__main__": + tiktok_url = "https://www.tiktok.com/@username/video/123456789" + download_directory = "/path/to/directory" + download_tiktok_video(tiktok_url, download_directory)