Skip to content

Extract the media inside PDFs, web pages, MHTML and Safari web archives - #250

Merged
charpy4n6 merged 1 commit into
mainfrom
feat/media-from-documents
Oct 1, 2026
Merged

charpy4n6 merged 1 commit into
mainfrom
feat/media-from-documents

Conversation

@charpy4n6

@charpy4n6 charpy4n6 commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

A PDF, HTML page, MHTML file or Safari web archive was classed as "other" and dropped at ingest, so the pictures and videos inside one never reached a case. A saved offline page in Chrome or Brave, for example, holds every image the page showed.

What it does

New gleapp/docmedia.py. With Extract media from documents ticked at ingest (or "documents": true in a job file), each document is kept as a container, like a zip, and gleapp/nested.py registers what is inside, linked by container_id.

Document What comes out Bytes
PDF (pypdf) every image object, drawn on a page or not, and every attached file JPEG / JPEG 2000 streams byte for byte; other images are stored as pixels and rebuilt as PNG (named _rebuilt, hashes are GLEAPP's)
HTML images and videos in data: URIs (img, video, srcset, CSS url()) byte for byte
MHTML / web archive every image and video part, named from its URL, plus data: URIs in their HTML byte for byte
  • A PDF with no extension is recognized by its magic. An encrypted PDF that opens without a password is read.
  • Images under 32 px on a side are left out.
  • A plain src="photo.jpg" link is not content; that file sits beside the page and is ingested on its own.

Cases ingested without it

Extract media from documents in the sidebar goes back over the case's sources (folders, extraction archives and disk images, via archive.ingest_archive with only_documents) and adds what the first ingest left out. A second run adds nothing, and a source no longer where the case recorded it is named and skipped.

Gallery

  • Details pane: Found in (the document), Where in it (page, attachment or saved resource), Copy (byte for byte or rebuilt), and Show everything from this document.
  • Sidebar, "Archives and documents": plain counts for each, with Only files pulled from an archive / …from a document under its own button. Button tooltips say what each opens.
  • Type filter: "archive (container)" is split into Archives, Documents and App cache pieces (ExoPlayer). Plain kind=archive still means every container. A SQLite function on the case connection applies exoprobe's own rule for cache piece names.
  • The counts refresh as soon as extraction is done, before processing and hash matching finish.

Two gaps closed on the way

  • JPEG 2000 (.jp2 .j2k .j2c .jpf .jpx, the JP2 box and the codestream magic) was not an image anywhere in GLEAPP, so a PDF's JPXDecode image was dropped. It is now an image everywhere; the viewer and the report already convert non-browser formats.
  • AES-encrypted PDFs: pypdf decrypts AES only through pycryptodome or cryptography, not the pycryptodomex GLEAPP already had. pycryptodome is added beside pypdf (both BSD) and collected in the spec.

Dependencies

  • pypdf>=5.0 (BSD-3, pure Python)
  • pycryptodome>=3.20 (BSD-2 / public domain; same project and wheels as pycryptodomex, installs beside it)

Both credited in the manual and help.

Tests

  • tests/test_docmedia.py (21): each reader, byte-for-byte MD5s, rebuilt PNGs, attachments, size floor, AES/RC4 PDFs, JPEG 2000, folder and zip ingest, documents inside a zip, adding documents later (and a second run adding nothing), a missing source, details-pane info, container filters and counts, and the early count refresh.
  • test_back_to_place.py: one pinned line updated for the new "everything from this document" view.
  • Full suite locally on Windows: 842 passed, 6 skipped. Line endings, import smoke, the changed-file lint and check_wheel pass.
  • From source, on a synthetic set (12 documents among 15 files, with a list of expected MD5s): every expected item came out and every byte-for-byte MD5 matched.
  • In built exes, on two real extractions: an Android zip (Chrome and Brave offline pages gave 36 and 17 items) and a Windows E01 (1,020 documents registered, matching a direct count of its volumes).

Not covered

  • Images inline in a PDF's drawing instructions (BI … EI).
  • Web pages without an extension, deleted documents, and browser cache formats.

🤖 Generated with Claude Code

A PDF, an HTML page, an MHTML file or a Safari web archive was "other" and was
dropped at ingest, so the pictures and videos inside one never reached a case. A
saved offline page in Chrome or Brave, for one, holds every image the page showed.

gleapp/docmedia.py reads them. With "Extract media from documents" ticked at ingest
(or "documents": true in a job file), each one is kept as a container, like a zip,
and gleapp/nested.py registers what is inside, linked by container_id:

- PDF (pypdf): every image object, drawn on a page or not, and every attached file.
  A JPEG or JPEG 2000 stream is the file as the producer wrote it and comes out byte
  for byte; any other image is stored as pixels and is rebuilt as a PNG named
  _rebuilt, whose hashes are GLEAPP's. A PDF with no extension is recognized by
  its magic. An encrypted PDF that opens without a password is read.
- HTML: images and videos in data: URIs (img, video, srcset, CSS url()).
- MHTML and web archives: every image and video part, named from its URL, plus any
  data: URI in their HTML. Byte for byte.
- Images under 32 pixels on a side are left out.

A case ingested without documents can open them later: "Extract media from
documents" in the sidebar goes back over the sources (folders, extraction archives
and disk images, through archive.ingest_archive with only_documents) and adds what
the first ingest left out. A second run adds nothing; a source no longer where the
case recorded it is named and skipped.

In the gallery:
- The details pane says where an item was found (the document, the page, the
  attachment or the saved resource) and whether it is byte for byte or rebuilt,
  and "Show everything from this document" lists what came out of one.
- The sidebar section "Archives and documents" shows the counts for each, with a
  checkbox under each button for the files pulled out of an archive or a document.
- The Type filter's "archive (container)" is split into Archives, Documents and
  App cache pieces (ExoPlayer), told apart in SQL; a SQLite function on the case
  connection applies exoprobe's own rule for cache piece names.
- The counts refresh as soon as the extraction is done, before processing and
  hash matching finish.

Two gaps found on the way are closed here too. JPEG 2000 (.jp2, .j2k, .j2c, .jpf,
.jpx, and the JP2 box and codestream magic) was not an image anywhere in GLEAPP,
so a PDF's JPXDecode image was dropped. And pypdf decrypts AES only through
pycryptodome or cryptography, not the pycryptodomex GLEAPP already had, so
pycryptodome is added beside pypdf (both BSD).

The manual and help describe the option, the button, the sidebar and what each
document type yields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@charpy4n6
charpy4n6 merged commit 7c208e8 into main Oct 1, 2026
12 checks passed
@charpy4n6
charpy4n6 deleted the feat/media-from-documents branch October 1, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant