Profile downloader: favorites list in the web UI; mark story filenames
- favorites.txt (git-ignored): profiles listed there show as buttons in the web UI that load the profile with one click - stories are saved as '<date> <id> story.<ext>' so they stand apart from posts
This commit is contained in:
1 parent
d12483d53c
commit
3dc4b0757f
5 files changed
+99
-9
No files matched your search
@@ -33,12 +33,18 @@ LISTING_CACHE_TTL = 3600 # seconds before a cached profile listing is fetched a
|
||||
DOWNLOAD_DELAY = float(os.getenv("PROFILE_DELAY", "1.5")) # seconds between posts (plus jitter)
|
||||
DOWNLOAD_TIMEOUT = 900 # seconds before one post's download is abandoned
|
||||
|
||||
# "<local date+time> <post id>[ <slide no.>].<ext>", e.g.
|
||||
# "<local date+time> <post id>[ <slide no.>][ story].<ext>", e.g.
|
||||
# 2026-11-08 16-53-54 7705844899718958356 01.jpg (photo post slide)
|
||||
# 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 (story)
|
||||
# Seconds + post ID keep posts made in the same minute from colliding.
|
||||
FILENAME_FORMAT = "{date:Olocal/%Y-%m-%d %H-%M-%S} {id}{num:? //>02}.{extension}"
|
||||
STORY_SUFFIX = " story"
|
||||
|
||||
|
||||
def _filename_format(kind: str) -> str:
|
||||
suffix = STORY_SUFFIX if kind == "story" else ""
|
||||
return "{date:Olocal/%Y-%m-%d %H-%M-%S} {id}{num:? //>02}" + suffix + ".{extension}"
|
||||
|
||||
BACKOFF_WAITS = (30, 90, 180) # seconds to wait before retrying a blocked request
|
||||
MAX_BLOCKED_IN_A_ROW = 3 # stop the run after this many posts in a row stay blocked
|
||||
@@ -430,9 +436,10 @@ def _download_photo_post_direct(record: dict, directory: str) -> Outcome:
|
||||
if not media.get("images") or not all(media["images"]):
|
||||
return Outcome(False, error="no direct links")
|
||||
stamp = datetime.fromtimestamp(record["timestamp"]).strftime("%Y-%m-%d %H-%M-%S")
|
||||
targets = [(f"{stamp} {record['id']} {n:02}", url) for n, url in enumerate(media["images"], start=1)]
|
||||
suffix = STORY_SUFFIX if record.get("kind") == "story" else ""
|
||||
targets = [(f"{stamp} {record['id']} {n:02}{suffix}", url) for n, url in enumerate(media["images"], start=1)]
|
||||
if media.get("music"):
|
||||
targets.append((f"{stamp} {record['id']}", media["music"]))
|
||||
targets.append((f"{stamp} {record['id']}{suffix}", media["music"]))
|
||||
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
session = requests.Session()
|
||||
@@ -467,13 +474,14 @@ def download_record(record: dict, directory: str, cookies: Optional[str]) -> Out
|
||||
return outcome
|
||||
_remove_partials(directory, record["id"])
|
||||
logger.debug("Direct download of %s failed (%s), using gallery-dl", record["id"], outcome.error)
|
||||
return download_post(record["url"], record["id"], directory, cookies)
|
||||
return download_post(record["url"], record["id"], directory, cookies, record.get("kind", "post"))
|
||||
|
||||
|
||||
def download_post(url: str, post_id: str, directory: str, cookies: Optional[str]) -> Outcome:
|
||||
"""Downloads one post (all photo slides + music, or the video) with gallery-dl."""
|
||||
def download_post(url: str, post_id: str, directory: str, cookies: Optional[str],
|
||||
kind: str = "post") -> Outcome:
|
||||
"""Downloads one post or story (all photo slides + music, or the video) with gallery-dl."""
|
||||
os.makedirs(directory, exist_ok=True)
|
||||
cmd = [sys.executable, "-P", "-m", "gallery_dl", "-D", directory, "-f", FILENAME_FORMAT]
|
||||
cmd = [sys.executable, "-P", "-m", "gallery_dl", "-D", directory, "-f", _filename_format(kind)]
|
||||
if cookies:
|
||||
cmd += ["--cookies", cookies]
|
||||
cmd.append(url)
|
||||
|
||||
Reference in new issue
Block a user