Add profile downloader with web UI; optional cookies for downloader
Profile downloader (profile-downloader/), now built on gallery-dl: - Local web UI (app.py): load a profile by username, URL, post link or secUid; stories shown above posts; select all/none/not downloaded, shift-click ranges, filters; live download progress with Stop - CLI (main.py) replaces the hard-coded script: --cookies, --refresh, --retry-failed, --limit, --no-stories - Photo posts save their slide images and music; cover thumbnails are no longer saved; filenames include seconds and the post ID so posts from the same minute cannot collide; partial files are cleaned up - Backoff and retry when TikTok blocks requests, stopping after three blocked posts in a row; per-profile failed.txt - Profile IDs are cached and looked up from a post page when the profile page is blocked; photo posts download straight from the post-list links - README for the profile downloader downloader.py: - Optional --cookies FILE (or TIKDOWN_COOKIES) - Failed-URL helpers accept a file path so the profile tool reuses them Ignore cookies.txt and __pycache__ in every folder.
This commit is contained in:
1 parent
1c17487ce4
commit
d12483d53c
9 files changed
+1436
-15
No files matched your search
+28
-11
@@ -149,32 +149,35 @@ def save_downloaded_id(video_id: str) -> None:
|
||||
f.write(video_id + "\n")
|
||||
|
||||
|
||||
def _read_failed() -> List[str]:
|
||||
if not os.path.exists(FAILED_FILE):
|
||||
def read_failed_urls(path: Optional[str] = None) -> List[str]:
|
||||
"""Returns the URLs listed in a failed-URLs file (failed.txt by default)."""
|
||||
path = path or FAILED_FILE
|
||||
if not os.path.exists(path):
|
||||
return []
|
||||
with open(FAILED_FILE, "r", encoding="utf-8") as f:
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
return [line.strip() for line in f if line.strip()]
|
||||
|
||||
|
||||
def log_failed_url(url: str) -> None:
|
||||
def log_failed_url(url: str, path: Optional[str] = None) -> None:
|
||||
"""Records a failed URL in failed.txt (once; repeated failures are not duplicated)."""
|
||||
url = url.strip()
|
||||
url, path = url.strip(), path or FAILED_FILE
|
||||
with _file_lock:
|
||||
if url in _read_failed():
|
||||
if url in read_failed_urls(path):
|
||||
return
|
||||
with open(FAILED_FILE, "a", encoding="utf-8") as f:
|
||||
os.makedirs(os.path.dirname(os.path.abspath(path)), exist_ok=True)
|
||||
with open(path, "a", encoding="utf-8") as f:
|
||||
f.write(url + "\n")
|
||||
|
||||
|
||||
def clear_failed_urls(urls: Iterable[str], ids: Iterable[str] = ()) -> None:
|
||||
def clear_failed_urls(urls: Iterable[str], ids: Iterable[str] = (), path: Optional[str] = None) -> None:
|
||||
"""Removes now-successful URLs (matched by URL or post ID) from failed.txt."""
|
||||
urls, ids = {u.strip() for u in urls}, set(ids)
|
||||
urls, ids, path = {u.strip() for u in urls}, set(ids), path or FAILED_FILE
|
||||
with _file_lock:
|
||||
current = _read_failed()
|
||||
current = read_failed_urls(path)
|
||||
kept = [u for u in current if u not in urls and extract_tiktok_id(u) not in ids]
|
||||
if len(kept) == len(current):
|
||||
return
|
||||
with open(FAILED_FILE, "w", encoding="utf-8") as f:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.writelines(u + "\n" for u in kept)
|
||||
|
||||
|
||||
@@ -355,6 +358,11 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
parser.add_argument("--delay", type=float, default=DOWNLOAD_DELAY, help="seconds between downloads")
|
||||
parser.add_argument("--force", action="store_true", help="re-download IDs already in downloaded_ids.txt")
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help="show yt-dlp output on errors")
|
||||
parser.add_argument(
|
||||
"--cookies",
|
||||
metavar="FILE",
|
||||
help="optional cookies.txt exported from your browser (for private or age-restricted posts)",
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
logging.basicConfig(
|
||||
@@ -362,6 +370,15 @@ def main(argv: Optional[List[str]] = None) -> int:
|
||||
level=logging.DEBUG if args.verbose else logging.INFO,
|
||||
)
|
||||
|
||||
global COOKIES_FILE
|
||||
if args.cookies:
|
||||
COOKIES_FILE = args.cookies
|
||||
if COOKIES_FILE:
|
||||
if not os.path.isfile(COOKIES_FILE):
|
||||
logger.error(f"Cookies file not found: {COOKIES_FILE}")
|
||||
return 2
|
||||
logger.info(f"Using cookies from {COOKIES_FILE}")
|
||||
|
||||
urls: List[str] = []
|
||||
for item in args.inputs:
|
||||
if os.path.isfile(item):
|
||||
|
||||
Reference in new issue
Block a user