DEV Community

chris howe
chris howe

Posted on

Download Instagram Highlights, Then Prove the Archive Is Complete: A Python Check

If you download Instagram highlights, posts and Stories in several sittings, you end up with a folder you think is complete. Sessions get paused, Wi-Fi drops, a laptop goes to sleep halfway through a long profile. Before you delete anything from your phone or rely on that folder as a backup, it's worth checking it with a script. This post builds a small Python tool, standard library only, that does that.

The script doesn't download anything. It inspects a folder of media and answers four questions:

  1. Are there leftover partial downloads?
  2. Is every file actually the media type its extension claims, and not truncated?
  3. Are there duplicates (the same file saved twice under different names)?
  4. Compared with the last run, what's new and what has disappeared?

A note on what you should be saving

Keep backups to content you own or have permission to keep: your own posts, a client's account you manage, a collaborator who said yes. When you download Instagram highlights from your own profile, you're often rescuing old Stories. Expired Stories you posted yourself are a good example of something worth archiving, because once they're gone from Highlights you can't get them back.

The checks, one at a time

1. Partial downloads

Chrome writes in-progress downloads with a .crdownload extension. Other tools use .part or .tmp. Any of these left behind after a session means an interrupted file.

2. Magic bytes

An extension is just a name. The first bytes of the file tell you what it really is:

Format Signature
JPEG starts FF D8 FF, should end FF D9
PNG starts 89 50 4E 47 0D 0A 1A 0A
WebP RIFF at 0, WEBP at 8
MP4 / MOV / HEIC ftyp at offset 4

A JPEG missing its FF D9 end marker is usually a truncated download. The image may still open, with a grey band across the bottom.

3. Duplicates

Hash every file with SHA-256 and group by digest. Two names with one digest is a duplicate, which happens when a resumed session re-saves items it already fetched.

4. Diff against the last manifest

Write the results to manifest.json. On the next run, compare: files that vanished (moved, deleted, renamed) and files that are new since last time.

The script

#!/usr/bin/env python3
"""archive_check.py - verify a folder of downloaded media."""
import hashlib, json, sys
from pathlib import Path

PARTIAL = {".crdownload", ".part", ".tmp", ".download"}
MEDIA = {".jpg", ".jpeg", ".png", ".webp", ".mp4", ".mov", ".heic"}

def sha256(path, chunk=1 << 20):
    h = hashlib.sha256()
    with path.open("rb") as f:
        while block := f.read(chunk):
            h.update(block)
    return h.hexdigest()

def sniff(path):
    """Return (kind, ok) based on the file's own bytes."""
    size = path.stat().st_size
    with path.open("rb") as f:
        head = f.read(12)
        tail = b""
        if size >= 2:
            f.seek(-2, 2)
            tail = f.read(2)
    if head[:3] == b"\xff\xd8\xff":
        return "jpeg", tail == b"\xff\xd9"
    if head[:8] == b"\x89PNG\r\n\x1a\n":
        return "png", True
    if head[:4] == b"RIFF" and head[8:12] == b"WEBP":
        return "webp", True
    if head[4:8] == b"ftyp":
        return "isobmff", True
    return "unknown", False

def scan(root):
    files, problems = {}, []
    for p in sorted(root.rglob("*")):
        if not p.is_file() or p.name == "manifest.json":
            continue
        rel = str(p.relative_to(root))
        ext = p.suffix.lower()
        if ext in PARTIAL:
            problems.append(("partial", rel))
            continue
        if ext not in MEDIA:
            continue
        size = p.stat().st_size
        if size == 0:
            problems.append(("empty", rel))
            continue
        kind, ok = sniff(p)
        if kind == "unknown":
            problems.append(("not-media", rel))
        elif not ok:
            problems.append(("truncated", rel))
        files[rel] = {"sha256": sha256(p), "size": size, "kind": kind}
    return files, problems

def main(folder):
    root = Path(folder).expanduser()
    files, problems = scan(root)

    by_hash = {}
    for rel, info in files.items():
        by_hash.setdefault(info["sha256"], []).append(rel)
    dupes = [names for names in by_hash.values() if len(names) > 1]

    manifest = root / "manifest.json"
    old = json.loads(manifest.read_text()) if manifest.exists() else {}
    gone = sorted(set(old) - set(files))
    new = sorted(set(files) - set(old))

    print(f"{len(files)} media files checked")
    for kind, rel in problems:
        print(f"[{kind}] {rel}")
    for names in dupes:
        print("[duplicate] " + " = ".join(names))
    if old:
        print(f"{len(new)} new since last run, {len(gone)} missing")
        for rel in gone:
            print(f"[missing] {rel}")

    manifest.write_text(json.dumps(files, indent=1))
    return 1 if problems else 0

if __name__ == "__main__":
    sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "."))
Enter fullscreen mode Exit fullscreen mode

Run it against the folder:

python3 archive_check.py ~/Backups/instagram
Enter fullscreen mode Exit fullscreen mode

The exit code is non-zero when there are problems, so you can chain it in a shell script or a cron job and only get alerted when something's off.

Reading the output

  • [partial]: re-run that item in your downloader, then delete the stub.
  • [truncated]: same treatment. Don't trust a JPEG without its end marker.
  • [not-media]: often an HTML error page saved with a .jpg name. Delete and re-fetch.
  • [duplicate]: keep one copy. If you organise by folder (one per Highlight, say), keep the copy that sits in the right folder.
  • [missing]: something moved or was deleted since the last run. If you didn't do it, find out who or what did before trusting the backup.

Getting the files: how to download Instagram highlights in batches

Any tool that writes ordinary files to disk works with this script. If you want to collect from inside Instagram's website, I work on a Chrome extension for saving posts, Stories and Highlights. Its site describes batch downloads from an account that you can pause and resume, which is exactly the kind of multi-session download this check is meant for. It runs in Chrome while you're signed in to Instagram, and the files land in your own downloads folder.

Possible extensions

  • Add --json output and feed it into a dashboard.
  • Use ffprobe to check that videos decode end to end. ftyp only proves the header is there.
  • Store manifests by date (manifest-2026-11-17.json) to keep a history instead of overwriting.
  • Compare two machines' manifests to confirm a copy to an external drive matched byte for byte.

A backup you haven't verified is a guess. Fifty lines of Python turn it into something you can check.

Disclosure: I work on the Gramino team. Gramino is independent and not affiliated with Instagram or Meta. The script above is generic and works with files from any source.

Top comments (0)