$ show Avnsh1111/Instagram-Reels-Scraper-Auto-Poster
Reels-AutoPilot is a Python automation application that scrapes short-form video (Instagram Reels and YouTube Shorts) from configured creator accounts and reposts that content to the user's own Instagram account, including optional story cross-posting. The architecture is a small monolith of loosely coupled scripts sharing a SQLite database: app.py is the main orchestrator running an infinite scheduling loop, reels.py and shorts.py scrape content via instagrapi/yt-dlp, poster.py uploads clips and stories, remover.py purges posted files, and db.py/helpers.py provide SQLAlchemy persistence plus a config system where SQLite values override static defaults in config.py. A Rich-based terminal dashboard (dashboard.py) shows live posting status, and start.py is an interactive CLI setup wizard. The core data flow is: scrape → download to downloads/ → insert metadata row into the 'reels' table as unposted → poster loop picks the oldest unposted row → upload as an Instagram clip → mark posted → optionally trim to 15s and post as a story with mention/link/hashtag/media stickers → remover deletes the local file after a configurable interval. External dependencies are the unofficial Instagram client instagrapi, the YouTube Data API v3 with yt-dlp, moviepy for video trimming, SQLAlchemy, and Rich. The code is functional but rough: reels.py has a filter bug (a tuple instead of a boolean condition) that lets non-reel media into the database; dashboard.py compares string config values to integers so status toggles always render as 'Off'; start.py validates the wrong variable in two input loops; exceptions are silently swallowed; and Instagram credentials are stored in plaintext in both config.py and the SQLite DB, with database/sqlite.db committed to the repository (a credential-leak risk). There are no tests or CI, and the README advertises features (scheduling, multi-account, auto-hashtags, analytics) that do not exist in the code. Dependency versions are somewhat dated, with moviepy 1.0.3 (circa 2020) the most notable lag. The YouTube channel-resolution helpers and the instagrapi story-sticker composition are the most genuinely reusable pieces.
The LLM identified 3 files worth highlighting for reuse:
Two self-contained functions for YouTube channel discovery and short-form content identification. extract_channel_id resolves a channel URL (both /channel/ and /@handle/ forms) to a channel ID by regex first, then falls back to scraping the page's <meta itemprop="channelId"> tag — a robust pattern for handling YouTube's multiple URL formats. get_shorts_videos paginates the channel's uploads playlist via the YouTube Data API and filters for #shorts by scanning titles and descriptions. Both take only a channel link/API key as input and can be lifted into any YouTube content pipeline with minimal modification.
The post_to_story function composes an Instagram story from a video file with precisely positioned interactive stickers — a user mention, a clickable link back to the original reel, a hashtag, and a media attachment card — using instagrapi's StoryMention/StoryLink/StoryHashtag/StoryMedia types. It demonstrates non-obvious instagrapi idioms that are hard to discover from docs: the normalized sticker-positioning coordinates and resolving the media PK via api.media_pk_from_url to embed the same reel inside the story. It depends only on config.DOWNLOAD_DIR and the instagrapi client, making it extractable into another project nearly as-is.
A custom json.JSONEncoder that flattens instagrapi's Media model — nested objects like image_versions2 and location, datetime fields, and boolean flags — into a stable JSON dict suitable for SQLite storage. This encoder pattern (normalize an external SDK's object graph into plain serializable JSON) is directly reusable in any project that needs to persist third-party API models in a relational or document store, and it cleanly decouples the scraping layer from the storage layer.