Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 89 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,76 @@ All notable changes to PostParse are documented here. The format follows

## [Unreleased]

### Added

- **`postparse check instagram --import-session`**: imports the session of
the user's logged-in browser without a password. The `sessionid` cookie is
read from a hidden terminal prompt (`csrftoken` optional, generated when
empty; a `:`-decoded copy is normalized to `%3A`), verified with exactly one
request (with `feed_api = "web"` the first saved-feed page, see below) and
saved only when Instagram confirms the session (`InstagramCollector.import_session`). Needs an
interactive terminal; cannot be combined with `--login`. The value is never
shown or logged. Messages that tell how to log in now recommend it first and
`--login` as the alternative. See docs/operations.md.

### Changed

- **Session check over the web API, with the saved feed's first page**: with
`instagram.feed_api = "web"` (the default) the session check requests the
first page of the saved feed (`https://www.instagram.com/api/v1/feed/saved/posts/`),
exactly as the feed walk does and as the Instagram web app does when the
saved page is opened (same web client and headers, saved page as
`Referer`, single attempt), instead of `i.instagram.com` with instaloader's
iPad headers: one client identity per run, and a browser session is never
sent with iPad headers to `i.instagram.com`. An intermediate version asked
`www.instagram.com/api/v1/users/<id>/info/`, which the web app does not
normally call; Instagram answered a fresh `--import-session` there with 429.
The checked page is reused as the walk's first page, so `extract instagram
--limit 1 --stop-after-known 1` with a valid session makes exactly one
request (an import makes one as well). A 200 answer with `"status": "fail"`
to that page raises `InstagramFeedUnavailable` (not "logged out"); nothing is
saved. The feed does not name the viewer, so in web mode the account is the
one the `sessionid` belongs to; `feed_api = "iphone"` keeps the user-info
check with the username comparison.

- **No automatic Instagram password login**: `extract instagram` (also with
`--transcribe`), `transcribe run` re-fetches and all API jobs never log in
with `INSTAGRAM_PASSWORD`. Without a usable session (no session file,
unreadable file, session logged out) they raise `InstagramAuthRequired`
(exit code 2, `error_code: auth_required`) that names the reason and says to
run `postparse check instagram --login` in a terminal; the session file is
not touched. `InstagramCollector` has a new `allow_password_login` argument
(default `False`) that only `check instagram --login` sets; it prints a
warning before the password login. A scripted password login after a
session check had made Instagram flag the account (confirmation request /
login redirect on the first feed page).

### Fixed

- **`check instagram --login` saved an unusable session**: instaloader reports
a password login as successful as soon as Instagram answers
`authenticated: true`, even when no `sessionid` cookie came back, and keeps
its empty placeholder cookies in the jar (instaloader issue #2487). The
placeholders are now removed, a login without `sessionid` / `ds_user_id`
stops with `InstagramAuthRequired` ("Instagram accepted the password but
returned no session cookie ...; nothing was saved") and a new session is
verified with one session check before it is saved (also after a 2FA code).
Nothing is saved on any failure; the existing session file stays untouched.
A throttled check of a new session says "did not confirm the session after
the password login" (still `InstagramSessionCheckFailed`, exit code 3).
- **Cookie values in messages**: `"sessionid": "..."` (JSON) and bare
`sessionid` values are redacted as well.
- **Instagram's reason in messages**: logged-out sessions, confirmations,
feed refusals and rate limits quote Instagram's sanitized short reason
(`message "..."`, e.g. `checkpoint_required`, or a login redirect as
`scheme://host/path`); query strings, cookies, tokens and response bodies
are never included (at most 200 characters). A failed session check no
longer quotes the request URL.
- **No false "429" rate limits**: rate-limit markers are no longer matched
inside URLs or request paths (cursor and user ids such as `max_id=...3429...`);
an HTTP 429 / `TooManyRequestsException` is still a rate limit. A feed
refusal with such a cursor is reported as `feed_unavailable`.

- **Instagram session check**: the saved session is no longer verified with
instaloader's `test_login()` (legacy GraphQL `query_hash` d6f4427…, which
Instagram answers with 401 "Please wait a few minutes", and which reported
Expand All @@ -16,15 +84,34 @@ All notable changes to PostParse are documented here. The format follows
connection attempt). A throttled or failed check raises the new
`InstagramSessionCheckFailed` (a subclass of `InstagramRateLimited`, exit
code 3) and **never falls back to a password login**; the session file is
left untouched. The password login is only used when the session is
positively logged out.
left untouched. A password login (now only `check instagram --login`, see
above) is only used when the session is positively logged out.
- **Instagram saved feed**: collected through the private API
(`api/v1/feed/saved/posts/`, paginated with `max_id`) instead of
`Profile.own_profile().get_saved_posts()`, which use legacy GraphQL
`query_hash` queries. Owners, comment counts and carousel video children
(with durations) are read from the private API media structs.
- `AbortDownloadException` (checkpoint, login redirect) during a run is mapped
to `InstagramAuthRequired`.
- **Instagram saved feed via the web REST API**: with a web session the
private-API feed on `i.instagram.com` (iPad headers) was answered with 200
`"fail"` "We're sorry, but something went wrong" (and retried three times).
The feed is now requested like the Instagram web app does it:
`https://www.instagram.com/api/v1/feed/saved/posts/` with `X-IG-App-ID`,
`X-CSRFToken` (from the `csrftoken` cookie), `X-Requested-With`,
`X-ASBD-ID`, `X-IG-WWW-Claim` and the saved page as `Referer`, through
instaloader's session (cookies, rate controller). New option
`instagram.feed_api = "web" | "iphone"` (default `"web"`; invalid values are
reported by `config validate` and fail the run with a clear message).
- **Instagram feed refusals are not retried**: feed pages get one attempt
(network errors are still retried up to `max_connection_attempts`). A
`"fail"` answer raises the new `InstagramFeedUnavailable` (a `RateLimited`
subclass): CLI exit code 3 with a message that the session is fine, nothing
was lost and which `instagram.feed_api` to try; report `stopped_reason` and
job `error_code` `feed_unavailable`.
- **Instagram session outcome is shown**: `extract instagram` prints
"Instagram session verified (no password login)"; API jobs get the same
progress message.

## [0.2.0] - 2026-10-26

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ uv run postparse classify run --taxonomy topics # LLM labels for pending items
uv run postparse search items pasta --label topics:recipe
```

The first `extract` asks for the Telegram login code (and 2FA password) and, if
needed, an Instagram 2FA code; later runs reuse the saved sessions.
The first `extract` asks for the Telegram login code (and 2FA password); later
runs reuse the saved session. Instagram never logs in from `extract`: import the
session of your logged-in browser once with `postparse check instagram
--import-session` (hidden prompt for the `sessionid` cookie, no password; see
[Operations](docs/operations.md)).

Every step only processes what is pending and can be re-run at any time.
`classify run` uses the **default scope**: items collected after the taxonomy was
Expand Down
8 changes: 6 additions & 2 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ default_max_delay = 15.0 # ... jittered between min and max
refresh_min_delay = 5.0 # pause between `--refresh-dates` fetches; default: the
refresh_max_delay = 15.0 # default_min/max_delay values
request_timeout = 30.0 # instaloader request timeout (seconds)
max_connection_attempts = 3 # instaloader connection attempts
# user_agent = "..." # custom user agent; unset = instaloader default
max_connection_attempts = 3 # instaloader connection attempts (feed pages: network errors only)
feed_api = "web" # saved feed: "web" (www.instagram.com, like the web app; fits a
# browser/web session) or "iphone" (private API, i.instagram.com)
# user_agent = "..." # custom user agent; unset = instaloader default. After
# `check instagram --import-session` set it to the User-Agent
# of that browser (same browser identity as the session)

# ---------------------------------------------------------------------------
# REST API (`postparse serve`)
Expand Down
3 changes: 2 additions & 1 deletion docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ with `[...]`.
|---|---|---|
| POST | `/api/v1/telegram/extract` | Start a `telegram_extract` job. Body: `api_id`, `api_hash`, `phone` (override the env variables), `limit` (100), `force_update`. Never interactive: log in once with `postparse extract telegram`; the session in `sessions_dir` is reused. |
| GET | `/api/v1/telegram/messages`, `/api/v1/telegram/messages/{message_id}` | Saved Telegram messages |
| POST | `/api/v1/instagram/extract` | Start an `instagram_extract` job. Body: `username`, `password` (optional with a valid session), `limit` (50), `force_update`, `stop_after_known` (20), `refresh_dates`. `use_api=true` is not supported (400). |
| POST | `/api/v1/instagram/extract` | Start an `instagram_extract` job. Body: `username`, `password` (accepted, but jobs never log in with it: they use the saved session; import the browser session with `postparse check instagram --import-session` or log in with `postparse check instagram --login`), `limit` (50), `force_update`, `stop_after_known` (20), `refresh_dates`. `use_api=true` is not supported (400). |
| GET | `/api/v1/instagram/posts`, `/api/v1/instagram/posts/{shortcode}` | Saved Instagram posts (`offset` deprecated, use `cursor`) |

### Processing jobs
Expand Down Expand Up @@ -131,6 +131,7 @@ service raises or its report stops for a hard reason:
| `credentials_missing` | `TELEGRAM_*` / `INSTAGRAM_*` not set and not in the request |
| `auth_required` | session invalid, login code / 2FA needed (log in once via the CLI) |
| `rate_limited` | Telegram FloodWait above the threshold, Instagram 429 |
| `feed_unavailable` | Instagram refused the saved feed with a `"fail"` status ("something went wrong"); the session is fine, see `instagram.feed_api` |
| `suspected_block` | transcription stopped by the soft-block circuit breaker |
| `backend_unavailable` | ASR backend not installed or unreachable |
| `llm_error` | classification / summarization failed at the LLM |
Expand Down
39 changes: 30 additions & 9 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Running `postparse` without a command shows a welcome banner.
| `0` | success |
| `1` | error (also: a failed check in `config validate` / `check` / `db check`, ASR backend unavailable) |
| `2` | login required (`extract`, `transcribe run`: Telegram/Instagram session invalid or 2FA needed in non-interactive mode); also click usage errors |
| `3` | rate limited (Telegram FloodWait above the threshold, Instagram 429) or suspected Instagram soft block (`transcribe run`) |
| `3` | rate limited (Telegram FloodWait above the threshold, Instagram 429), Instagram refused the saved feed (`"fail"` status; see `instagram.feed_api`) or suspected Instagram soft block (`transcribe run`) |
| `130` | interrupted (Ctrl-C) |

`extract all` returns the most severe code of the platforms (3 > 2 > 1).
Expand All @@ -47,14 +47,14 @@ Usage: postparse check [OPTIONS] [COMMAND] [ARGS]...

Health checks (database, transcription, sessions, LLM providers).

Without a subcommand this runs `check all`. Only `--login` and `check llm`
talk to external services.
Without a subcommand this runs `check all`. Only `--login`,
`check instagram --import-session` and `check llm` talk to external services.

| Subcommand | Description |
|---|---|
| [`all`](#postparse-check-all) | Run all checks (no Telegram/Instagram network calls without --login). |
| [`db`](#postparse-check-db) | Database integrity, schema version and search index (= `db check`). |
| [`instagram`](#postparse-check-instagram) | Instagram session file and credentials (`--login` verifies online). |
| [`instagram`](#postparse-check-instagram) | Instagram session file and credentials (`--login` / `--import-session` go online). |
| [`llm`](#postparse-check-llm) | LLM providers: model list, discovered model, chat ping and latency. |
| [`telegram`](#postparse-check-telegram) | Telegram session file and credentials (`--login` verifies online). |
| [`transcription`](#postparse-check-transcription) | Transcription backend: faster-whisper / CUDA, or API endpoint reachability. |
Expand Down Expand Up @@ -101,20 +101,35 @@ Database integrity, schema version and search index (= `db check`).
Usage: postparse check instagram [OPTIONS]
```

Instagram session file and credentials (`--login` verifies online).
Instagram session file and credentials (`--login` / `--import-session` go online).

`--import-session` is the recommended way to log in: it takes the session
of your logged-in browser (no password login).

**Examples:**

```bash
postparse check instagram
postparse check instagram --import-session
postparse check instagram --login
```

| Option | Type | Default | Description |
|---|---|---|---|
| `--username` | TEXT | | Instagram username (default: INSTAGRAM_USERNAME) |
| `--session` | TEXT | | Session file (default: &lt;sessions_dir&gt;/instagram_&lt;username&gt;) |
| `--login` | flag | | Load the session or log in to Instagram (may prompt for a 2FA code) |
| `--login` | flag | | Verify the saved session; without a usable one log in with INSTAGRAM_PASSWORD (may prompt for a 2FA code). The only command that uses the password. |
| `--import-session` | flag | | Import the sessionid cookie of your logged-in browser (hidden prompt, no password), verify it with one request and save it. Needs a terminal. |

`--import-session` and `--login` cannot be combined (usage error, exit code
2). The import asks for the `sessionid` cookie (hidden input) and optionally
the `csrftoken` cookie (Enter generates one), makes exactly one request (the
session check: with `instagram.feed_api = "web"`, the default, the first page
of the saved feed, as the web app requests it when the saved page is opened;
with `"iphone"` the user info on `i.instagram.com`) and saves the session file
only when Instagram confirms the session; otherwise nothing is saved (exit
code 1).
See [Operations](operations.md#instagram-logging-in-checkpoint-2fa-soft-block).

### `postparse check llm`

Expand Down Expand Up @@ -634,8 +649,13 @@ Usage: postparse extract instagram [OPTIONS]

Collect saved Instagram posts (newest first, stops at known posts).

Credentials: INSTAGRAM_USERNAME and INSTAGRAM_PASSWORD from the environment
or config/.env (the password is only needed when the session is invalid).
Uses the saved session of INSTAGRAM_USERNAME (environment or config/.env)
and never logs in with the password: without a usable session it stops
with exit code 2. Import the session of your logged-in browser with
`postparse check instagram --import-session` in a terminal (no password),
or log in with `postparse check instagram --login` (the only command that
uses INSTAGRAM_PASSWORD; it may not yield a usable session, instaloader
#2487), then retry.

**Examples:**

Expand All @@ -651,7 +671,8 @@ postparse extract instagram --transcribe

```text
New posts are throttled (several seconds each). If Instagram asks for a
confirmation, confirm the login in the Instagram app and retry.
confirmation, confirm the login in the Instagram app, run
`postparse check instagram --import-session` (or `--login`) and retry.
```

| Option | Type | Default | Description |
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ below `./data`, no LLM providers, no taxonomies).
| `[summarization]` | `SummarizationService` | `provider`, `max_input_chars`, `output_retries` |
| `[enrichment]` | `EnrichmentService` | see [Enrichment](enrichment.md) |
| `[telegram]` | Telegram collector | batch size, FloodWait threshold, media download limits and pauses, Telethon retry settings |
| `[instagram]` | Instagram collector | pauses between posts (`default_min_delay` / `default_max_delay`) and date refreshes, instaloader timeout / attempts, `user_agent` |
| `[instagram]` | Instagram collector | pauses between posts (`default_min_delay` / `default_max_delay`) and date refreshes, instaloader timeout / attempts, `user_agent`, `feed_api` (`"web"`: saved feed like the web app on `www.instagram.com`, default; `"iphone"`: private API on `i.instagram.com`) |
| `[api]` and `[api.auth]`, `[api.cors]`, `[api.rate_limiting]`, `[api.cache]`, `[api.jobs]` | `serve`, FastAPI app | see [API reference](api-reference.md) |

### LLM provider example (llama.cpp)
Expand Down Expand Up @@ -79,7 +79,7 @@ provider only.
| Variable | Purpose |
|---|---|
| `TELEGRAM_API_ID`, `TELEGRAM_API_HASH`, `TELEGRAM_PHONE` | Telegram API credentials (phone optional, used for the first login) |
| `INSTAGRAM_USERNAME`, `INSTAGRAM_PASSWORD` | Instagram login (password optional while the session file is valid) |
| `INSTAGRAM_USERNAME`, `INSTAGRAM_PASSWORD` | Instagram account; the password is only used by `postparse check instagram --login`; extract and API jobs use the saved session (recommended: `postparse check instagram --import-session` imports the browser session, no password) |
| `OPENAI_API_KEY`, `ANTHROPIC_API_KEY` | LLM providers; the transcription API backend reads the variable named by `transcription.api.api_key_env` (default `OPENAI_API_KEY`) |
| `JWT_SECRET_KEY` | API authentication secret (fallback when `api.auth.secret_key` is not set) |
| `POSTPARSE_DATA_DIR`, `POSTPARSE_DB_PATH`, `POSTPARSE_SESSIONS_DIR`, `POSTPARSE_DOWNLOADS_DIR`, `POSTPARSE_TMP_DIR` | override the corresponding `[paths]` / `[database]` values |
Expand Down
Loading
Loading