Automate your blog with AI

⚠️
Disclaimer: I want to make it clear that the tools I'm discussing in this blog post are intended for enhancing productivity and automating tasks. I do not endorse or encourage any form of content theft or plagiarism. Always ensure that you have the proper rights to use any content and use these tools responsibly. I am not responsible for any misuse of these tools.

In the era of AI advancement, I've embraced AI tools to streamline my daily tasks as a software developer. The applications of AI are vast and seem almost limitless. Even as I write this, GitHub Copilot assists me in crafting this text.

AI tools like ChatGPT and Stable Diffusion, coupled with automation tools like make.com and n8n, offer a world of possibilities to simplify our lives. Still, it's important to understand the possible negative effects of AI, like its potential to be misused for creating fake news and deceptive videos.

In this post, I'm excited to demonstrate how we can leverage tools like ChatGPT combined with automation platforms such as make.com or n8n to automate the creation of blog posts. Our primary resource for this experiment will be the transcriptions of YouTube videos.

Resources

To effectively automate our blog posts, we need reliable sources to base our posts on. In this example, I'll be utilizing automatically generated video transcripts from YouTube videos. However, I want to stress the importance of using content responsibly and only drawing from sources that grant you permission or ownership rights.

For the purpose of this illustration, I'll be working with a video by tazzan.

Counter-Strike 2 Will Change Gaming Forever
In this video, I discuss how Counter-Strike 2 is probably going to change the scene of FPS gaming forever, especially with all the new features Valve added.…
Video used to create automated blog post

Remember, aside from YouTube videos, you can tap into various other resources such as RSS feeds, APIs from other social platforms, or even emails.

Toolkit

Let's explore the array of tools that I'll be relying on for this process:

ChatGPT

A household name in AI, ChatGPT will be our go-to tool for constructing the blog post. If you're fortunate enough to have access to the GPT-4 model, I recommend employing it for optimal results in generating the final blog post.

If you're inclined to explore alternatives, consider using your own self-hosted Language Models (LLMs) or similar tools in place of ChatGPT.

n8n

To orchestrate the automation, I'll be utilizing n8n in this guide. Personally, I work with my self-hosted instance, but tools like make.com or comparable alternatives can also be employed.

Ghost

For my blog infrastructure, I've opted for Ghost as the content management system. The strategies shared here should be adaptable to other blog systems that offer API interactions.

Automation workflow

n8n workflow

Process

Let's examine the process that lies beneath this automation:

1. We execute a bash script on our system that handles the download and
   refinement of the selected video's transcript. Subsequently, this script triggers
   n8n's webhook, passing along the transcript within the request body.

2. Initiate a call to the n8n webhook, passing the scrubbed transcript as the
   request body.

3. The n8n workflow is triggered, subsequently sending a request to the OpenAI
   API to generate the actual blog post.

4. As a last step, we create a draft post via the Ghost API, which we can further edit and publish.

The following Bash script downloads and refines the transcript of the specified YouTube video before dispatching it to the n8n webhook, thus initiating the process of generating a blog post.

#!/bin/bash

# Parse command-line arguments
while [[ $# -gt 0 ]]; do
    key="$1"

    case $key in
        --url)
        URL="$2"
        shift
        shift
        ;;
        *)
        echo "Unknown option: $1"
        exit 1
        ;;
    esac
done

if [[ -z "$URL" ]]; then
    echo "Please provide a YouTube video URL using --url option."
    exit 1
fi

# Download subtitles using yt-dlp and set custom filename
YTDL_OUTPUT=$(yt-dlp --write-sub --write-auto-sub --skip-download --output "yt_video_subs.%(ext)s" "$URL")

# Extracted subtitle content
SUBTITLE_CONTENT=$(cat "yt_video_subs.en.vtt")

# Delete downloaded subtitle file
rm "yt_video_subs.en.vtt"

# Remove HTML tags from the subtitles
CLEANED_SUBTITLES=$(echo "$SUBTITLE_CONTENT" | sed 's/<[^>]*>//g')

# Remove special character &nbsp;
CLEANED_SUBTITLES=$(echo "$CLEANED_SUBTITLES" | sed 's/&nbsp;//g')

# Remove lines which contain --> (e.g., " --> ")
CLEANED_SUBTITLES=$(echo "$CLEANED_SUBTITLES" | grep -v " --> ")

# Remove lines which are completly empty
CLEANED_SUBTITLES=$(echo "$CLEANED_SUBTITLES" | grep -v "^$")

# Remove empty lines between text lines
CLEANED_SUBTITLES=$(echo "$CLEANED_SUBTITLES" | sed '/^$/N;/^\n$/D')

# Remove duplicated lines
CLEANED_SUBTITLES=$(echo "$CLEANED_SUBTITLES" | awk '!seen[$0]++')

echo "$CLEANED_SUBTITLES"

# Store cleaned subtitles in a variable
FINAL_SUBTITLES="$CLEANED_SUBTITLES"

# Call n8n webhook with the subtitles in post as raw text in request body
curl --location 'https://n8n.your-instance.com/webhook/your-webhook-id' \
--header 'Content-Type: text/plain' \
--header 'Authorization: Basic your-basic-auth-credentials' \
--data "$FINAL_SUBTITLES"
ytsubs.sh

This script has exclusively been tested on an Arch Linux machine and necessitates the installation of the following packages: yt-dlp

You can find the download link to my n8n workflow template, which you can easily import, below:

Refining the Process

As an enhancement, you could consider integration image generation tools like Stable Diffusion or DALL-E.

Conclusion

AI-powered tools will be a big part of how we get things done in the future. When we use them thoughtfully, they can really change how we work and come up with new ideas. Just remember, it's important to use them responsibly so that we use technology in helpful ways.

Here's an example post that was made using the steps explained in this guide:

Unveiling Counter Strike 2: A Revolution in Gaming
ai test
Note: Images where added manually

Acknowledgement

I got inspired by this video from 'Bugswriter': When ChatGPT meet Lazy Linux user