The Al Content Machine: How to Automate Viral Scriptwriting with Cursor and n8n.

Workflow - Code Included

I was burning out creating content. So I cloned my favorite YouTuber with AI, and now it writes scripts that get 500k+ views.

Alright, I have a confession to make. For the last year, I’ve been on the content creation hamster wheel, and honestly, it was grinding me down. I’d spend 6+ hours agonizing over a single script, trying to get it perfect. Meanwhile, I'd watch guys like Varun Mayya who just effortlessly drop videos that get millions of views. It was frustrating. I kept thinking, "What's the secret? What does he know that I don't?"

One night, instead of just being jealous, I had a crazy idea. What if I could quantify his "secret sauce"? What if I could stop guessing and actually teach an AI to write just like him?

So I went full nerd mode. I scraped over 40 of his most viral video scripts and fed them into Cursor AI. But I didn't just dump the data. I built a custom "brain" for it with layers of instructions. And the results… honestly blew my mind.

  • First script it generated: 487K views in just 3 days.
  • My average engagement: Shot up by 340%.
  • Time to create a script: Went from 6+ hours to 15 minutes.

It’s been a total game-changer. I feel like I've finally cracked the code, and a few people have asked how I did it, so I decided to write up the full process.


Here's My Exact Blueprint:

Step 1: Data Collection - The Raw Material

First, I needed the source material. I built a Python script to automatically scrape the transcripts from over 40 of Varun's most viral videos. I didn't just grab the text; I organized it all into clean CSV files to make it easy for the AI to process. As I reviewed the data, I started seeing clear patterns—the specific way he phrases his hooks, the fast pacing, his word choices, and the psychological triggers he uses to keep you watching.

Step 2: Multi-Layer Training - Giving the AI a Brain

This is where the magic happens. Just dumping raw text into an AI gives you garbage results. You have to teach it the why. So, I created four different instruction "Rule" files in Cursor AI. Each one acts as a different layer of the AI's "brain."

  1. Basic Writing Guide (400+ lines): This laid down the fundamentals—write in a conversational tone, use short sentences, active voice, etc.
  2. Psychological Analysis Framework: This taught the AI why certain phrases work. It included instructions on creating curiosity gaps, using social proof, and tapping into FOMO.
  3. Human Touch Elements: This was key to making it sound natural. I gave it rules like "maintain an 8th-grade reading level" and "use contractions like 'it's' and 'you're'."
  4. Hook-Specific Guide: The first 3 seconds are everything. I created a separate, highly detailed guide just for writing irresistible hooks.

Step 3: The Automation Engine with n8n

Once the AI was trained, I automated the whole process using n8n. I built a workflow that triggers when I add a new video idea to a Google Sheet. It sends the topic to my AI, which then writes the script based on all my rules and drops the finished text right into my content calendar in Notion. It’s a completely hands-off process.

The breakthrough moment:

I tested it on a random tech story about MIT turning soda cans into hydrogen fuel. Here's the hook it generated instantly:

*“MIT scientists just found a way to turn your empty soda cans into clean hydrogen fuel and it's absolutely wild. They're using recycled aluminum and seawater to produce hydrogen with 87% fewer emissions than traditional methods. But here's where it gets crazy - they discovered that adding coffee grounds makes the reaction 24 times faster..."*

That script got nearly 500K views. The hook was perfect, the pacing felt natural, and people couldn't stop watching.


Want to Try It? Here Are All My Files and Workflows.

I'm sharing everything. The Python script, all four instruction files, and the n8n workflow JSON. Fair warning though - this process takes some serious iteration to get right, but the results are worth it.

Part 1: The Python Script for Scraping Transcripts

First, you'll need to install the library: pip install youtube-transcript-api. Then, save this as a Python file (e.g., scraper.py) and run it. It will create a scraped_transcripts.csv file in the same folder.

# requirements.txt
# youtube_transcript_api

import csv
from youtube_transcript_api import YouTubeTranscriptApi

def get_video_id(url):
    """Extracts the video ID from a YouTube URL."""
    # Handles both standard and short URLs
    if "v=" in url:
        return url.split("v=")[1].split("&")[0]
    elif "youtu.be/" in url:
        return url.split("youtu.be/")[1].split("?")[0]
    return None

def scrape_transcripts(video_urls, output_csv_file):
    """
    Scrapes transcripts from a list of YouTube video URLs and saves them to a CSV file.

    Args:
        video_urls (list): A list of YouTube video URLs.
        output_csv_file (str): The path to the output CSV file.
    """
    with open(output_csv_file, 'w', newline='', encoding='utf-8') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerow(['video_id', 'transcript_text'])

        for url in video_urls:
            try:
                video_id = get_video_id(url)
                if not video_id:
                    print(f"Could not find video ID for URL: {url}")
                    continue
                    
                transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
                
                # Joining all text parts into a single string for the transcript
                full_transcript = " ".join([item['text'] for item in transcript_list])
                
                writer.writerow([video_id, full_transcript])
                print(f"Successfully scraped transcript for video ID: {video_id}")

            except Exception as e:
                print(f"Could not retrieve transcript for {url}. Error: {e}")

if __name__ == "__main__":
    # ------------------------------------------------------------------
    # IMPORTANT: Replace these with the actual URLs you want to scrape!
    # ------------------------------------------------------------------
    target_video_urls = [
        '[https://www.youtube.com/watch?v=dQw4w9WgXcQ](https://www.youtube.com/watch?v=dQw4w9WgXcQ)',
        '[https://www.youtube.com/watch?v=examplevideo2](https://www.youtube.com/watch?v=examplevideo2)',
        '[https://www.youtube.com/watch?v=examplevideo3](https://www.youtube.com/watch?v=examplevideo3)',
        # Add 40+ of your target YouTuber's video URLs here for best results
    ]
    
    output_file = 'scraped_transcripts.csv'
    scrape_transcripts(target_video_urls, output_file)
    print(f"\nAll transcripts have been saved to {output_file}")

Part 2: The Four Cursor AI "Rule" Files
These are the exact instruction files I created. You would set these up as "Rules" within Cursor AI so it always follows them.
File 1: basic_writing_guide.txt
# Rule File 1: The Basic Writing Guide

- Write in a conversational and engaging tone, as if explaining something interesting to a smart friend.
- Use the active voice and eliminate the passive voice.
- Keep sentences short and punchy, ideally under 15 words, to create a fast, energetic pace.
- Break down complex ideas and technical topics into simple, easy-to-understand concepts.
- Use clear and concise language. Avoid jargon unless it's the subject, and if so, explain it simply.
- Structure the script with a clear beginning (hook), middle (elaboration and value), and end (conclusion/call-to-action).
- Ensure a logical flow between paragraphs. Use smooth transitions to guide the viewer from one idea to the next.
- Vary sentence structure to avoid monotony and keep the rhythm interesting.
- Write with a tone of confidence and authority on the subject matter.

File 2: psychological_framework.txt
# Rule File 2: Psychological Analysis Framework

- When introducing a new concept, immediately create a curiosity gap by asking a question the viewer wants answered.
- In the introduction, directly address a common pain point or a strong desire of the target audience to make it instantly relatable.
- Build credibility by using social proof: cite reputable sources, reference experts, or mention compelling data.
- Frame the core message to tap into FOMO (Fear Of Missing Out) by highlighting its importance, urgency, or how it gives the viewer an edge.
- Use classic storytelling techniques: present a clear problem, introduce a novel solution (the video's topic), and show the powerful transformation or result.
- Engineer a "wow" moment or a surprising twist, often prefaced with phrases like "But here's where it gets crazy...," "And the results were shocking," or "But they discovered something unexpected."
- Speak directly to the viewer using "you" and "your" consistently to create a one-on-one conversation.

File 3: human_touch_elements.txt
# Rule File 3: The Human Touch Elements

- Strictly maintain an 8th-grade reading level for maximum clarity and accessibility.
- Use common contractions like "it's," "you're," "that's," "I'm," and "can't" to create a natural, conversational feel.
- Inject personality and genuine enthusiasm with adverbs and phrases like "honestly," "literally," "actually," "insane," "mind-blowing," and "absolutely wild."
- The tone should feel authentic. Read the script aloud in your mind to ensure it sounds like a real person talking, not a robot.
- Use simple vocabulary. Replace complex words with simpler alternatives (e.g., use "use" instead of "utilize").

File 4: hook_specific_guide.txt
# Rule File 4: The Hook-Specific Guide (For the first 3-5 seconds)

- The very first sentence must be a bold, attention-grabbing statement that makes the user stop scrolling.
- The hook must immediately establish the video's value and answer the viewer's question: "What's in it for me?"
- Absolutely never start with cliché openings like "In this video..." or "Today, we're going to talk about..."
- Pose a provocative question that the viewer will feel compelled to see answered.
- Present a shocking or counter-intuitive fact, statistic, or claim.
- Start with a highly relatable problem or a powerful "what if" scenario.
- Make a strong, specific promise about what the viewer will learn, gain, or be able to do by the end of the video.
- The hook must be extremely concise and deliver a powerful punch in under 15 seconds. It is 80% of the video's success.

Part 3: The n8n Automation Workflow (JSON)
This is the JSON for the n8n workflow. You can copy this and import it directly into your n8n canvas. This example uses a manual trigger and a generic AI node, but you can easily swap the trigger for a Google Sheet and connect it to your AI of choice.
{
  "name": "AI Viral Script Generator",
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "video_topic",
              "value": "MIT scientists turning soda cans into hydrogen fuel with coffee grounds"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Video Topic",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "content": "You are an expert scriptwriter for viral YouTube videos in the style of Varun Mayya.\n\n**Your Instructions:**\n\n**Rule 1: Basic Writing Guide**\n- Write in a conversational, engaging tone.\n- Use active voice.\n- Keep sentences short (under 15 words).\n- Simplify complex ideas.\n\n**Rule 2: Psychological Framework**\n- Create curiosity gaps.\n- Address viewer pain points.\n- Use social proof.\n- Incorporate FOMO.\n\n**Rule 3: Human Touch**\n- Maintain an 8th-grade reading level.\n- Use contractions (it's, you're).\n- Inject personality (honestly, absolutely).\n\n**Rule 4: The Hook**\n- The first sentence must be a bold, attention-grabbing statement.\n- Never start with 'In this video...'\n- Pose a provocative question or a surprising fact.\n\n**Today's Topic:**\n{{$json[\"video_topic\"]}}\n\nNow, write the script.",
        "options": {}
      },
      "name": "Construct Prompt",
      "type": "n8n-nodes-base.prompt",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "model": "gpt-4-turbo",
        "prompt": "{{$json.content}}",
        "options": {}
      },
      "name": "Call AI Model",
      "type": "n8n-nodes-base.openAi",
      "typeVersion": 3,
      "position": [
        850,
        300
      ],
      "credentials": {
        "openAiApi": {
          "id": "YOUR_AI_CREDENTIAL_ID",
          "name": "Your OpenAI Credential"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "final_script",
              "value": "{{$json.choices[0].message.content}}"
            }
          ]
        },
        "options": {}
      },
      "name": "Set Final Script",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Video Topic",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Video Topic": {
      "main": [
        [
          {
            "node": "Construct Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Construct Prompt": {
      "main": [
        [
          {
            "node": "Call AI Model",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call AI Model": {
      "main": [
        [
          {
            "node": "Set Final Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Has anyone else tried training AI on specific creators? I'm curious if this works across different niches or if I just got lucky with the tech/science space. Let me know your thoughts!

Posted Jul 4, 2025, 12:05 PM UTC

10
Loading comments…