#!/usr/bin/env python3 import argparse import bs4 import re import os import subprocess import time def change_dir(): if not os.path.exists(args.d): os.makedirs(args.d) os.chdir(args.d) def download_videos(): if os.path.exists("in.html"): html = open("in.html") else: html = open(args.html) soup = bs4.BeautifulSoup(html, "html.parser") video_list = [] for fileinfo in soup.find_all("a", class_=re.compile(".*video-feed-item-wrapper")): video_list.append(fileinfo.get("href")) vid_total = len(video_list) print("TOTAL VIDEO COUNT: %d" % vid_total) for vid in video_list: if args.t: subprocess.run(["torsocks", "youtube-dl", vid]) else: subprocess.run(["youtube-dl", vid]) time.sleep(1) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("html", nargs="?", help="Path to HTML of tiktok profile") parser.add_argument("-d", help="Directory to download to") parser.add_argument("-t", action="store_true", help="Enable Tor") args = parser.parse_args() if args.d: change_dir() download_videos()