Skip to content

About

Turns Instagram-shared music screenshots into a YouTube playlist automatically

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Share Pile

Turns Instagram-shared music screenshots into a running YouTube playlist, automatically, once a week. Pulls screenshots from either a self-hosted Immich instance (any device synced into it) or, if you don't run Immich, a plain local folder.

How it works

  1. immich_source.py (or local_source.py — see SOURCE in Config below) pulls every new photo since the last run.
  2. ocr_filter.detect_service() crops the top ~30% of each image and OCRs just that, checking for the watermark text each streaming service stamps onto a shared card (Spotify, YouTube Music, Tidal, Qobuz). Non-matches are skipped. No LLM involved in this step.
  3. It OCRs the full image and walks the text-line geometry around the watermark to pull out title + artist. Spotify (title/artist sit just above the watermark) and YouTube Music (different card shape — title/artist sit in a card much further down the screenshot, artist line ends in • Song) are verified against real screenshots. Tidal and Qobuz run fully automatically too, using the same "title/artist above the watermark" convention as Spotify, but this is a best-effort guess — real samples of those two were too sparse (Qobuz: zero found; Tidal: one, and it wasn't even a normal single-track card) to actually verify the layout. Autonomy was prioritized over waiting for proof; the looks_garbled() check and the "no YouTube match found" fallback in run.py are the safety net catching bad extractions instead. Worth periodically checking needs_review.txt and added_log.tsv for tidal/qobuz rows to see how well it's actually doing, and tightening extract_tidal/extract_qobuz in ocr_filter.py once more real examples turn up. Add a new service by writing a detect/extract pair and registering it in _EXTRACTORS.
  4. youtube_client.py searches the YouTube Data API v3 for "{title} {artist}", scores the candidates (prefers auto-generated "- Topic" channels and official uploads over lyric videos / covers / live versions), and adds the best match to a private "The Share Pile" playlist.
  5. Anything the OCR can't read confidently — unsupported service, garbled text, extraction failure, even a corrupt/unreadable image file — gets logged to needs_review.txt instead of being guessed at. The photo is still marked processed so it isn't retried forever, but you can search for the song by hand later.
  6. state.json remembers the last run time and every asset (Immich UUID, or file path for the local source) already processed, so nothing is ever re-added. youtube_client.list_playlist_video_ids() also checks the live playlist directly before adding, so a song already there — however it got there — won't be duplicated even if two different screenshots resolve to the same video.

Nothing here calls an LLM at runtime — the whole pipeline is deterministic OCR + API calls, so it can run unattended.

One-time setup

1. Python deps

pip install -r requirements.txt

Also needs Tesseract OCR installed locally (default expected path C:\Program Files\Tesseract-OCR\tesseract.exe — edit the path at the top of ocr_filter.py if yours differs).

2. Pick a screenshot source

Immich (recommended if you already self-host it — picks up screenshots from every synced device): Immich → Account Settings → API Keys → New API Key. Needs asset.read and search permissions. Set SOURCE=immich, IMMICH_URL, IMMICH_API_KEY in .env.

Local folder (no Immich needed): point LOCAL_FOLDER in .env at any folder your screenshots already land in — an iCloud/Google Photos download folder, Dropbox Camera Uploads, whatever your phone syncs to. It's scanned recursively; "new since last run" is based on file modified time, so don't touch the mtimes of files you haven't processed yet. Set SOURCE=local.

3. YouTube OAuth (Google Cloud Console)

  1. console.cloud.google.com → new project.
  2. APIs & Services → Library → enable YouTube Data API v3.
  3. APIs & Services → OAuth consent screen → External → fill in the minimum required fields, add yourself as a test user.
  4. APIs & Services → Credentials → Create Credentials → OAuth client ID → Application type Desktop app. Download the JSON, save it as client_secret.json in this folder (path is set via YOUTUBE_CLIENT_SECRETS in .env).
  5. Run py -3 run.py --dry-run once by hand — it'll open a browser for you to log in as the YouTube account that should own the playlist and grant access. This writes youtube_token.json, which is what the unattended weekly run uses afterward.

Known caveat: while the Cloud Console OAuth consent screen is left in "Testing" status, Google can expire the refresh token after a matter of days regardless of activity, which would silently break the Monday run. Watch added_log.tsv / needs_review.txt for the first few weeks; if the script stops running (check Task Scheduler's history for the "Share Pile Weekly" task), the fix is either re-running the interactive login once, or publishing the OAuth consent screen out of Testing. This is a real limitation of using a personal OAuth client for a personal cron job that I haven't fully solved — flagging it rather than pretending it's bulletproof.

4. Config

Copy .env.example to .env and fill in your chosen source's settings and the YouTube paths.

5. Schedule it

py -3 run.py --dry-run --limit 5      # sanity check first, doesn't touch YouTube or state.json
py -3 run.py --dry-run                # full dry run against everything new since state.json's last_run_iso
py -3 run.py                           # for real

Once that's clean, run task_scheduler_setup.ps1 as Administrator to register the weekly Monday 9am job.

Files

  • run.py — orchestrator / entry point
  • immich_source.py — Immich search + download
  • local_source.py — plain-folder alternative to immich_source.py
  • ocr_filter.py — per-service card detection + title/artist extraction
  • youtube_client.py — OAuth, search, playlist add
  • state.py — state.json read/write helpers
  • needs_review.txt — screenshots OCR couldn't confidently parse
  • added_log.tsv — everything successfully added, for a record/audit trail

About

Turns Instagram-shared music screenshots into a YouTube playlist automatically

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages