# Profile Downloader Downloads posts and stories from a TikTok profile — through a local web UI where you pick exactly which posts you want, or from the command line. Built on [gallery-dl](https://github.com/mikf/gallery-dl), which (unlike yt-dlp) saves the actual images of photo posts, not just their background music. ## Setup ```bash pip install gallery-dl flask requests ``` ### Cookies (recommended) TikTok often refuses profile requests from logged-out visitors. Export your browser's TikTok cookies to `cookies.txt` in this folder (for example with the "Get cookies.txt LOCALLY" browser extension, while logged in to tiktok.com). It is picked up automatically; you can also point to another file, or turn cookies off. `cookies.txt` is git-ignored — never share it, it logs in as you. ## Web UI ```bash python app.py ``` Opens (use `--port` to change it, `--no-browser` to not open a tab). The server only listens on your own computer. 1. Enter a **username**, `@username`, profile URL, link to one of the profile's posts, or **secUid** (`MS4wLjABAAAA…`), then **Load profile**. 2. **Stories** are pinned at the top, followed by all **posts**, newest first. Each card shows the cover, date, caption, type (video length or number of photos) and whether it's already downloaded or failed before. 3. Select posts: - click a card (or press Space/Enter on it) to select or deselect it - Shift-click to select a range - **Select all** / **Deselect all** / **Select not downloaded** (these act on the current filter) - filter by **Videos**, **Photos** or **Not downloaded** 4. **Download selected**. A panel at the bottom shows progress and any failures; **Stop** ends the run after the current post. The post list is cached for an hour. Tick **Fetch fresh list** to reload it (e.g. to see new posts or stories). ### Favorites Put profiles you open often in `favorites.txt` in this folder, one per line (anything the profile box accepts: username, `@username`, profile URL, post link or secUid). Lines starting with `#` are ignored. They show up as buttons under the profile box; click one to load that profile. The file is read each time the page loads, so just reload after editing it. `favorites.txt` is git-ignored. ``` # favorites.txt some.username @another.user MS4wLjABAAAA... ``` ## Command line Downloads everything on the profile that isn't downloaded yet: ```bash python main.py some.username python main.py https://www.tiktok.com/@some.username --limit 20 python main.py some.username --retry-failed ``` | Option | Meaning | | --- | --- | | `--cookies FILE` | cookies file to use (default: `cookies.txt` here, if present) | | `--no-cookies` | don't use cookies | | `--refresh` | ignore the cached post list | | `--no-stories` | skip stories | | `--retry-failed` | only retry posts in `failed.txt` | | `--limit N` | download at most N posts this run, newest first | | `--delay SECONDS` | pause between posts (default 1.5, plus a random extra) | | `-v` | show gallery-dl's output when something fails | ## Where files go ``` downloads/profile// 2026-11-08 16-53-54 7705844899718958356 01.jpg photo post, slide 1 2026-11-08 16-53-54 7705844899718958356 02.jpg photo post, slide 2 2026-11-08 16-53-54 7705844899718958356.mp3 photo post music 2026-08-06 00-57-14 7670716372560727317.mp4 video 2026-11-21 20-37-01 7710726500621782294 story.mp4 video story 2026-11-21 20-37-01 7710726500621782295 01 story.jpg photo story, slide 1 .archive.txt IDs of downloaded posts (these are skipped / marked "Downloaded") failed.txt links of posts that failed; removed again once they succeed .profile.json the profile's IDs, so it doesn't need to be looked up again .listing_cache.json cached post list ``` The date is the post's upload time in your local time zone. Cover thumbnails are not saved. Files downloaded by the old version of this script (`2026-06-11 23-26 0001.image` and so on) are left as they are, and those posts stay marked as downloaded. ## When TikTok blocks requests TikTok rate-limits scrapers, usually with "403 Forbidden". - **Downloads** wait 30 s, 90 s and 180 s and retry. After 3 posts in a row stay blocked, the run stops so it doesn't burn through the whole list. Wait a while (or refresh your cookies) and download again; already-downloaded posts are skipped. - **Photo posts** are downloaded straight from the links in the post list, so they usually still work while post pages are blocked. Videos need their post page. - **Loading a profile by username** needs the profile page once. If that is blocked, it tries the pages of posts you already downloaded, then asks you to paste a **post link** or the **secUid**. After one successful load, the profile's IDs are remembered and the page isn't needed again. To find a secUid: open the profile in your browser, view the page source (Ctrl+U) and search for `"secUid":"`. ## Settings Environment variables: | Variable | Default | | --- | --- | | `PROFILE_DOWNLOAD_DIR` | `downloads/profile` in this folder | | `PROFILE_DELAY` | `1.5` seconds between posts | | `PROFILE_UI_PORT` | `5050` | ## Files | File | Purpose | | --- | --- | | `app.py` | web UI server (Flask) | | `static/index.html` | the web page | | `main.py` | command line | | `core.py` | listing, downloading, archive, retries — shared by both | | `favorites.txt` | your favorite profiles for the web UI (optional, git-ignored) | Failed-link bookkeeping is shared with the single-post downloader (`../downloader.py`).