Skip to content

Repository files navigation

πŸ“ YouTube to Medium Automation

⚑️ The Game-Changer Script You Will Always Be Grateful For!

Automate the process of converting YouTube video content into Medium articles πŸŽ₯πŸ“

This program not only converts video transcripts extremely well into beautiful, SEO-optimized articles with images and captions, but also removes any "transcript-like" writing. It produces a real, professional article from a video instead.

Automation: Convert videos into articles

βš™οΈ Requirements

  • Python v3.7 or higher 🐍
  • A Google account with YouTube API access 🎬
  • An OpenAI API key 🧠
  • A Medium account with an integration token ✍️

πŸ“¦ Installation

  1. Clone this repository:

    git clone https://github.com/pH-7/youtube-to-medium-blog-posts-automation.git &&
    cd youtube-to-medium-blog-posts-automation
  2. Create and activate a virtual environment (recommended on macOS and other systems to avoid conflicts with system-managed Python installations; PEP 668 prevents modifying these environments directly):

    python3 -m venv .venv && source .venv/bin/activate
  3. Install the required Python packages:

    pip install -r requirements.txt
  4. Set up your configuration file:

    • Create a file named config.json in the project root directory

    • Add your API keys and YouTube Channel ID to the file as followed:

      {
        "PUBLISH_PLATFORMS": ["medium"], // Platforms to publish to
      
        "MEDIUM_ACCESS_TOKEN": "YOUR_MEDIUM_ACCESS_TOKEN",
        "MEDIUM_EN_PUBLICATION_ID": "OPTIONAL_ENGLISH_PUBLICATION_ID",
        "MEDIUM_FR_PUBLICATION_ID": "OPTIONAL_FRENCH_PUBLICATION_ID",
        "MEDIUM_TECH_PUBLICATION_ID": "OPTIONAL_TECH_PUBLICATION_ID",
        "POST_TO_PUBLICATION": true, // Whenever we want the post to be published to a specified Medium's publication ID or not
      
        "OPENAI_API_KEY": "YOUR_OPENAI_API_KEY",
        "OPENAI_MODEL": "gpt-4.1", // non-reasoning models like "gpt-4.1", "gpt-4.1-mini"
        "UNSPLASH_ACCESS_KEY": "YOUR_UNSPLASH_KEY",
        "PUBLISH_STATUS": "draft", // "draft" or "publish"
      
        // Niche configurations
        "NICHES": {
          "self-help": {
            "YOUTUBE_CHANNEL_ID": "YOUR_SELF_HELP_CHANNEL_ID",
            "SOURCE_LANGUAGE": "fr",
            "OUTPUT_LANGUAGES": ["en", "fr"],
            "UNSPLASH_PREFERRED_PHOTOGRAPHER": "pierrehenry", // Optional. Mention a preferred Unsplash photographer (e.g. pierrehenry)
            "ARTICLES_BASE_DIR": "articles"
          },
          "tech": {
            "YOUTUBE_CHANNEL_ID": "YOUR_TECH_CHANNEL_ID",
            "SOURCE_LANGUAGE": "en",
            "OUTPUT_LANGUAGES": ["en"],
            "UNSPLASH_PREFERRED_PHOTOGRAPHER": null,
            "ARTICLES_BASE_DIR": "articles/tech"
          }
        },
      
        // Active niche to process ("self-help" or "tech" or "all")
        "ACTIVE_NICHE": "all",
      
        // Optional: compile saved articles into books (see "Compile articles into a book")
        "BOOK": {
          "AUTHOR": "Your Name",
          "OUTPUT_DIR": "books",
          "FORMATS": ["epub", "pdf"], // "epub", "pdf", or both
          "PAGE_SIZE": "6in 9in", // KDP trim size for the PDF interior
          "EMBED_IMAGES": true,
          "MIN_PAGES": 90, // aim for a book of at least this many pages
          "MAX_PAGES": 110, // ...and at most this many
          "WORDS_PER_PAGE": 250, // used to estimate the page count
          "RIGHTS": "Copyright Β© 2026 Your Name. All rights reserved.",
          "COLLECTIONS": [
            {
              "title": "The Productivity System",
              "subtitle": "Focused work, less overwhelm",
              "source_dir": "articles",
              "language": "en",
              "topics": ["productivity", "time management", "focus"]
            }
          ]
        }
      }

      Publishing:

      • Set PUBLISH_PLATFORMS to ["medium"].
      • Medium receives HTML for reliable kicker, subtitle and image captions.
      • Medium is only used when its credentials are present; otherwise it is skipped with a clear message.
      • PUBLISH_STATUS ("draft" or "publish") is honoured.
      • The published URL is recorded in the saved article's Markdown metadata.

      Multi-Niche Support:

      • The script now supports multiple content niches (self-help and tech)
      • Each niche has its own YouTube channel, languages, and custom prompts
      • Set ACTIVE_NICHE to "all", "self-help", or "tech" to control which niches to process
      • Tech niche is optimized for "NextGen Dev: AI & Code" technical content

      Alternatively, you can refer to example.config.json in the project.

  5. Set up YouTube API credentials:

    • Go to the Google Developers Console
    • Create a new project and enable the YouTube Data API v3
    • Create credentials (OAuth 2.0 Client ID) for a desktop application. Select External for Use Type
    • Download the client configuration and save it as client_secrets.json in the project root directory
  6. Lastly, get your Unsplash Access Key at https://unsplash.com/oauth/applications/new

πŸͺ„ Usage

To run the script, use the following command in the project root directory:

python transform-youtube-videos-to-medium-posts.py

Selecting which niche to process:

  • Edit ACTIVE_NICHE in config.json:
    • "all" - processes all configured niches
    • "self-help" - processes only self-help niche
    • "tech" - processes only tech niche

The script will:

  1. Fetch recent videos from your YouTube channel(s)
  2. Transcribe each video
  3. Generate an exceptional well-written article for each video transcript
  4. Create 5 most relevant tags for the article
  5. Generate an engaging article title
  6. Fetch relevant images from Unsplash for the article (one for article header, and 1-2 for content)
  7. Embed a few images in the article content using Medium-compatible Markdown format.
  8. Publish the article to Medium with correctly formatted HTML
  9. Save the generated article locally as a Markdown file, so you always keep a copy, with article's details (incl. the Medium URL) in a markdown yaml-like metadata
  10. Clearly mentioning any issues for each publishing step till the end, right in the terminal
  11. Automatically wait a few minutes (for each iteration) before publishing a new article to Medium, to prevent being wrongly flagged as spam
  12. Sit and relax. Enjoy the work!

Note: The script posts articles as drafts by default. To change this, modify the PUBLISH_STATUS to "publish" in the config.json file.

πŸ“– Compile articles into a book

Once you have a folder of generated articles, you can bundle them into a polished, ready-to-publish EPUB/PDF book β€” perfect for Amazon KDP, Apple Books, Kobo, or simply sharing a PDF.

python transform-youtube-videos-to-medium-posts.py --make-book

Each book is curated around one coherent topic and trimmed to a target page count (e.g. 90-110 pages), so every volume reads like a real, focused book rather than a dump of every article.

Not sure which topics you have enough material for? List them first:

python transform-youtube-videos-to-medium-posts.py --list-topics

Then compile the books defined in your config.json:

python transform-youtube-videos-to-medium-posts.py --make-book

This reads the optional BOOK section of config.json and produces one book per entry in COLLECTIONS:

Option Description
AUTHOR Author name written into the book metadata and title page.
OUTPUT_DIR Where the generated .epub/.pdf files are written (default books).
FORMATS Any of "epub", "pdf" (default both).
PAGE_SIZE PDF trim size, e.g. "6in 9in" (a common KDP paperback size).
EMBED_IMAGES Download and embed article images so the book is self-contained.
MIN_PAGES / MAX_PAGES Target page range; chapters are added until the range is reached.
WORDS_PER_PAGE Words-per-page used to estimate length (default 250, calibrated for 6x9in).
RIGHTS Copyright-page text (a sensible default is generated when omitted).
COLLECTIONS One book per entry (see below).

Each collection supports: title, subtitle, source_dir, topics (tags that define the book's subject), exclude_topics, match ("any" or "all"), min_pages, max_pages, max_chapters, words_per_page, language, recursive, cover_image, page_size, embed_images, and rights.

If COLLECTIONS is omitted, one book is compiled per configured niche using its ARTICLES_BASE_DIR.

How chapters are built:

  • Each Markdown article becomes one chapter, titled from its optimized_title metadata.
  • Duplicate articles (e.g. accented vs. un-accented file names) are removed automatically.
  • Only chapters whose tags match the collection's topics are included, so the book stays on one accurate subject.
  • Chapters are ordered chronologically (oldest first) and added until the MIN_PAGES/MAX_PAGES range is met; the estimated page count is printed as it compiles.
  • Unpublished drafts (not_published_*) are skipped.
  • Blog-only bits (embedded YouTube videos, the leading kicker line, the trailing "listen to my podcast / join my mailing list" promo) are stripped; images and their captions are kept as proper figures.
  • Both formats get a title page and a copyright page; the PDF also gets a table of contents with page numbers and page numbering, ready for Amazon KDP.

About PDF generation: the EPUB exporter is pure Python and always works. The PDF exporter uses weasyprint, which needs native libraries. On macOS:

brew install pango
pip install weasyprint

If weasyprint is unavailable, the PDF step is skipped with a clear message and the EPUB is still produced.

πŸ™ƒ Enjoying this project? Offer me a coffee (spoiler alert: I love almond flat white πŸ˜‹)

Script running, converting YouTube videos to Medium articles

πŸ› οΈ Configuration

You can modify the following in the script:

  • The number of videos to process (change maxResults in ``get_videos_pagefunctio, which is declared inget_channel_videos`)
  • The length of the generated article (change max_tokens in generate_article function)
  • The number of tags to generate (modify the prompt in generate_tags function)

🎬 Demo

See the script in action with these demonstration videos:

Articles conversion in French language

generating-french-blog-post-medium-articles-output-from-youyube-video-transcripts.mp4

Article conversion from English videos

demo-turn-videos-to-medium-posts.mp4

πŸŽ₯ I show you EVERYTHING 🀫

I've built a script that automatically publishes my videos to well-written English articles

β–Ά Here to Watch on YouTube

πŸ‘¨β€πŸ³ Who created this transformation script?

Pierre-Henry Soria

Pierre-Henry Soria. A super passionate engineer who loves automating efficiently content creation! πŸš€ Enthusiast for YouTube, AI, learning, and writing of course! 😊 Find me at pH7.me πŸ’«

β˜•οΈ Enjoying this project? Offer me a coffee (spoiler alert: I love almond flat white πŸ˜‹)

@phenrysay YouTube Tech Videos pH-7 BlueSky

⚠️ Disclaimer

Please keep in mind that this Videos to (Medium) Posts Converter project is for educational purposes only. Ensure you always comply with YouTube's terms of service and Medium's API usage guidelines and policy when using this script.

βš–οΈ License

YouTube to Medium Automation script is generously distributed under the MIT License πŸŽ‰ Enjoy!

About

Turn any YouTube videos into well-written Medium blog posts with this automation script (made with lots of love). Writes a delightful and professional article from a given full YouTube channel.

Topics

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages