YouTube Transcript to Article is a Docker-based Python project that provides an API for converting YouTube transcripts into professional articles using OpenAI's ChatGPT. This tool automates the creation of summaries or detailed articles from YouTube video content, making it easy to generate professional write-ups from video transcripts.
- Automatic Transcript Retrieval: Fetches the transcript of a YouTube video in its original language, handling both video URLs and IDs.
- Article Generation: Generates a professional article from the transcript, with options for brief or detailed formats.
- Customizable Output Language: Allows you to specify the output language, with the default being the video's language.
- Minimalist Web Interface: Provides a simple, user-friendly web interface to easily input video IDs or URLs and generate articles.
- Dockerized Deployment: Easy deployment with Docker, including integration options for Home Assistant and MQTT.
The project includes support for MQTT, enabling integration with various IoT platforms like Home Assistant. This allows for automated processing of YouTube videos when a video link or ID is published to a specific MQTT topic.
- Real-Time Processing: Automatically processes YouTube video links or IDs when published to a subscribed MQTT topic.
- Configurable Output: Supports specifying
detail_level
(summary or detailed) andtarget_lang
(output language) through MQTT. - Automatic Responses: Publishes the generated article to a specified MQTT topic.
- MQTT Authentication: Supports username and password authentication for connecting to MQTT brokers.
- Home Assistant Discovery: Automatically registers availability and last processed message sensors in Home Assistant using MQTT Discovery.
Ensure the following environment variables are set in your Docker setup:
MQTT_ACTIVE
: Set totrue
to enable MQTT functionality.MQTT_BROKER
: The MQTT broker address (default:localhost
).MQTT_PORT
: The port for the MQTT broker (default:1883
).MQTT_USERNAME
: The username for MQTT authentication (optional).MQTT_PASSWORD
: The password for MQTT authentication (optional).MQTT_TOPIC_SUB
: The MQTT topic to subscribe to for incoming video links/IDs (default:video/input
).MQTT_TOPIC_PUB
: The MQTT topic to publish the generated articles to (default:article/output
).MQTT_CLIENT_ID
: A unique client ID for the MQTT connection.
To trigger the processing of a video through MQTT, publish a JSON-formatted message to the subscribed topic (MQTT_TOPIC_SUB
):
{
"video_id": "YOUR_YOUTUBE_VIDEO_URL_OR_ID",
"detail_level": "summary", // Options: "summary", "detailed"
"target_lang": "en" // Optional, specify if you want a different language
}
The generated article will be published to the MQTT_TOPIC_PUB
topic.
You can easily integrate this project with Home Assistant using MQTT Discovery, which automatically configures sensors in Home Assistant to monitor the service's availability and display the last processed video and article.
When MQTT is enabled, the service will automatically register the following sensors in Home Assistant:
- Service Availability: A binary sensor that shows whether the service is online or offline.
- Last Processed Message: A sensor that displays the last processed video URL and the corresponding article.
If you are using docker-compose
, here’s an example configuration for integrating this service with Home Assistant:
version: '3'
services:
youtube-transcript-to-article:
image: patrickstigler/youtube-transcript-to-article
container_name: youtube_transcript_to_article
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- MQTT_ACTIVE=true
- MQTT_BROKER=your_mqtt_broker_address
- MQTT_PORT=1883
- MQTT_USERNAME=your_mqtt_username
- MQTT_PASSWORD=your_mqtt_password
- MQTT_TOPIC_SUB=video/input
- MQTT_TOPIC_PUB=article/output
- MQTT_CLIENT_ID=youtube_article_generator
ports:
- "5000:5000"
The Docker image for this project is available on Docker Hub:
- Docker Hub:
patrickstigler/youtube-transcript-to-article
To pull and run the Docker image, use the following commands:
docker pull patrickstigler/youtube-transcript-to-article
docker run -p 5000:5000 patrickstigler/youtube-transcript-to-article
This application is also available on unRAID as youtube-transcript-to-article
. To install it on unRAID:
- Open the unRAID web interface.
- Navigate to the Apps tab.
- Search for
youtube-transcript-to-article
. - Click Install and follow the prompts to set up the application.
- Docker installed on your system.
- OpenAI API key.
-
Clone the repository:
git clone https://github.com/yourusername/youtube-transcript-to-article.git cd youtube-transcript-to-article
-
Set up your environment variables:
Ensure your OpenAI API key is set in your environment:
export OPENAI_API_KEY=your_openai_api_key
-
Build the Docker image:
docker build -t youtube-transcript-to-article .
-
Run the Docker container:
docker run -p 5000:5000 youtube-transcript-to-article
-
URL:
http://localhost:5000/api/generate
-
Method:
POST
-
Payload Example:
{ "video_id": "YOUR_YOUTUBE_VIDEO_URL_OR_ID", "detail_level": "summary", // Options: "summary", "detailed" "target_lang": "en" // Optional, specify if you want a different language }
-
Response Example:
{ "article": "Generated article text here..." }
Access the minimalist web interface by navigating to http://localhost:5000
in your browser. Here, you can input the YouTube video URL or ID, choose the detail level, and specify a target language if desired.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request or open an issue.