Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Instagram to YouTube Automation in Python

Automate-YT-Channel is a production-oriented Python workflow for transforming authorized Instagram media into branded YouTube Long-form videos and Shorts, generating metadata, and publishing through the YouTube Data API.

Author: Diwas Khatri — Nepali developer focused on Python automation, content workflows, developer tools, and practical AI-assisted systems.

Python YouTube Data API Instagram Automation Windows Friendly

Overview

This project automates an Instagram-to-YouTube content pipeline for accounts that the operator owns or is explicitly authorized to manage. It supports bounded media discovery, oldest-first or newest-first selection, local download, Long-form and Short rendering, caption-based title and description generation, YouTube upload, format-level duplicate protection, logs, and continuous scheduling.

The default production profile checks every 20 minutes, selects up to two pending Instagram media items per cycle, and can create one Long-form video plus one Short for each selected item. That produces a maximum of four uploads in a fully populated cycle. The workflow is intentionally bounded and stateful so the same Instagram media format is not uploaded repeatedly.

Important: Use this project only with media and accounts you own or have permission to republish. Do not use it to bypass authentication, scrape private accounts, evade platform restrictions, or repost copyrighted music or video without the required rights.

Demo

The verified test channel is Diwas Khatri on YouTube.

Account Format Public demo
diwas_khatrii Long-form Watch on YouTube
diwas_khatrii Short Watch on YouTube
codebynitesh Long-form Watch on YouTube
codebynitesh Short Watch on YouTube
uncrustamemes Long-form Watch on YouTube
uncrustamemes Short Watch on YouTube
zost.memes Long-form Watch on YouTube
zost.memes Short Watch on YouTube

Live worker screenshot

Windows live worker setup and logs

The screenshot shows the Windows launcher using bundled FFmpeg, saving local Instagram settings, copying the YouTube OAuth client file, enabling live mode, and starting the continuous worker.

Additional documentation screenshots are available in docs/screenshots/:

User-provided demonstration clips are available in docs/demo-media/:

For the complete operator walkthrough, read docs/COMPLETE_TUTORIAL.md.

Key features

Capability Description
Instagram media import Uses the optional instagrapi session adapter for explicitly authorized source accounts.
Older-media support Uses bounded cursor-aware scanning with configurable oldest-first or newest-first ordering.
Dual-format rendering Creates a Long-form MP4 and a vertical Short MP4 for each selected source item.
Metadata automation Builds titles, descriptions, tags, source attribution, and Shorts hashtags from the source caption.
YouTube publishing Uploads through the official YouTube Data API OAuth flow.
Duplicate protection Tracks Instagram media IDs and completed formats in local state. A successful Long upload does not suppress a missing Short upload.
Continuous operation Runs a 20-minute worker loop with a two-media batch limit and restart-safe state.
Windows-friendly startup START_AUTOMATION.py installs dependencies, prompts for local credentials, resolves bundled FFmpeg, and starts the worker without requiring BAT execution.
Safe packaging Secrets, tokens, downloaded source media, generated videos, logs, and local publishing state are excluded from version control.

Architecture

Authorized Instagram accounts
          |
          v
Bounded instagrapi importer
          |
          v
Oldest/newest selection + duplicate state
          |
          v
Local source media download
          |
          +----------------------+
          |                      |
          v                      v
Long-form renderer          Shorts renderer
          |                      |
          +----------+-----------+
                     v
Caption-based metadata generator
                     |
                     v
YouTube Data API OAuth upload
                     |
                     v
Local format-level publish state + logs

Quick start on Windows

Requirements

Install Python 3.10 or newer. The launcher installs the Python packages automatically and uses the bundled imageio-ffmpeg executable, so a system FFmpeg installation is not required. A Google OAuth Desktop App client file named client_secrets.json is required for YouTube upload authorization.

First setup

Clone the repository and open PowerShell in the project directory:

git clone https://github.com/DiwasKhatri07/Automate-YT-Channel.git
cd Automate-YT-Channel
python START_AUTOMATION.py

On the first run, the launcher creates a virtual environment, installs dependencies, prompts locally for the Instagram login username, hides the session ID input, asks for authorized source usernames, and asks for the path to client_secrets.json. It then creates a local .env file. The session ID is never required in the README or in a public issue.

The launcher starts in safe test/private mode unless you type LIVE at the local prompt. Review the generated output first. For intentional public publishing, set:

YOUTUBE_TEST_MODE=false
YOUTUBE_PRIVACY_STATUS=public

Then run the launcher again:

python START_AUTOMATION.py

Keep the PowerShell window open while the automation is running. The worker writes progress to logs/instagrapi_worker.log and restarts after an unexpected worker exit.

Configuration

The important .env settings are:

# YouTube
YOUTUBE_CLIENT_SECRETS=client_secrets.json
YOUTUBE_TOKEN_FILE=data/youtube_token.json
YOUTUBE_TEST_MODE=true
YOUTUBE_PRIVACY_STATUS=private

# Continuous schedule and batch sizing
INTERVAL_MINUTES=20
MAX_BATCH_MEDIA=2
MAX_DAILY_IMPORT_UPLOADS=100
PUBLISH_LONGFORM=true
PUBLISH_SHORTS=true

# Instagram session adapter
INSTAGRAM_USERNAME=your_login_username
INSTAGRAM_SESSION_ID=your_current_local_session
INSTAGRAM_SOURCE_USERNAMES=your_account,authorized_source_account
MAX_INSTAGRAM_MEDIA_PER_ACCOUNT=2
INSTAGRAM_MEDIA_ORDER=oldest
INSTAGRAM_MEDIA_SCAN_LIMIT=100
INSTAGRAM_MEDIA_PAGE_SIZE=20

With both PUBLISH_LONGFORM=true and PUBLISH_SHORTS=true, two selected source media items can produce four YouTube uploads in a cycle: two Long-form videos and two Shorts. The MAX_DAILY_IMPORT_UPLOADS limit is an application-level safety ceiling. If a video format fails after its paired format succeeds, the next cycle retries only the missing format.

Manual commands

The recommended entry point is START_AUTOMATION.py. For debugging or one-shot operation, use the following commands:

Purpose Command
Import Instagram media only python workflow_cli.py instagrapi-import
One test-mode worker cycle python workflow_cli.py instagrapi-worker-once
One live worker cycle python workflow_cli.py instagrapi-worker-once with YOUTUBE_TEST_MODE=false
Continuous worker loop python workflow_cli.py instagrapi-worker-loop
Local render test python workflow_cli.py process-only

The CLI requires a command. Running python workflow_cli.py without a command prints its usage help and exits.

YouTube OAuth setup

Create an OAuth Desktop App credential in Google Cloud, enable YouTube Data API v3, and save the downloaded JSON file as client_secrets.json in the project directory. On the first upload, the Google authorization flow opens in a browser. After consent, the refresh token is stored locally at data/youtube_token.json.

The project uses the official YouTube upload scope. Review YouTube’s upload guidance before operating a public channel.1

Instagram account and rights requirements

The official Meta Instagram Platform is designed for eligible professional accounts and owned media access.2 This repository includes a session-based adapter for accounts the operator owns or is authorized to manage. Keep Instagram sessions local, rotate an exposed session, and do not commit session IDs to Git.

Only upload media for which you have the necessary rights, including rights to music, video, captions, and logos. Instagram media can contain licensed audio that is not cleared for YouTube redistribution. The workflow does not grant ownership or distribution rights.

Testing and verification

The project was tested with an isolated Python environment, deterministic local rendering, the bundled FFmpeg fallback, authorized Instagram import, test-mode Long and Short rendering, YouTube OAuth, live public uploads, and a second duplicate-protection pass.

The verified live batch completed seven new public uploads and one earlier public Long-form upload, covering four available media items with Long and Short formats. The detailed report is available in TEST_REPORT.md, and the full operational runbook is available in INSTAGRAM_TO_YOUTUBE_RUNBOOK.md.

Repository structure

.
├── START_AUTOMATION.py              # Python-only Windows launcher
├── workflow_cli.py                  # Command-line entry point
├── instagrapi_importer.py           # Authorized Instagram session importer
├── instagrapi_publish_worker.py     # Batch worker and duplicate state
├── source_processor.py              # Downloaded-media transformation
├── video_builder.py                 # Quiz/card video rendering
├── content_templates.py             # Caption-based metadata templates
├── youtube_upload.py                # YouTube Data API upload helper
├── media_tools.py                   # System/bundled FFmpeg resolver
├── .env.example                     # Safe configuration template
├── SIMPLE_START.md                  # Short setup guide
├── INSTAGRAM_TO_YOUTUBE_RUNBOOK.md  # Full operating runbook
├── TEST_REPORT.md                   # Test and upload report
├── docs/COMPLETE_TUTORIAL.md       # Full step-by-step tutorial
├── docs/screenshots/                # Public documentation screenshots
└── docs/demo-media/                 # User-provided demo clips

Security model

Never commit .env, client_secrets.json, data/youtube_token.json, Instagram session IDs, downloaded source media, generated output videos, logs, SQLite files, or publish state. The repository’s .gitignore excludes these paths. If a token or session is exposed, revoke or rotate it before continuing.

Do not place credentials in GitHub Issues, pull requests, README files, screenshots, terminal recordings, or public logs. The launcher prompts for the Instagram session locally and keeps it in the local .env file.

Author

Diwas Khatri is a Nepali developer building practical Python automation tools for content workflows, developer productivity, and AI-assisted media systems.

References

About

Instagram to YouTube automation in Python: authorized media import, Long-form and Shorts rendering, metadata generation, YouTube Data API uploads, duplicate protection, and continuous scheduling.

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages