Skip to content

Commit

Permalink
Use environment variable for channels to make it easy for everyone to…
Browse files Browse the repository at this point in the history
… use it
  • Loading branch information
Stell0 committed Mar 22, 2024
1 parent 42d15fc commit 688397f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cron-run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ jobs:
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: docker run -e TELEGRAM_CHAT_ID -e TELEGRAM_BOT_TOKEN -e OPENAI_API_KEY stell0/youtubetelegramsummaries:latest
CHANNEL_LIST: ${{ env.CHANNEL_LIST }}
run: docker run -e TELEGRAM_CHAT_ID -e TELEGRAM_BOT_TOKEN -e OPENAI_API_KEY -e CHANNEL_LIST stell0/youtubetelegramsummaries:latest
3 changes: 2 additions & 1 deletion .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ jobs:
- name: Run the Docker container
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: docker run -e OPENAI_API_KEY stell0/youtubetelegramsummaries:latest
CHANNEL_LIST: ${{ env.CHANNEL_LIST }}
run: docker run -e OPENAI_API_KEY -e CHANNEL_LIST stell0/youtubetelegramsummaries:latest

4 changes: 3 additions & 1 deletion .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ jobs:
push: true
tags: stell0/youtubetelegramsummaries:S(date +%s)
- name: Run the Docker container
run: docker run stell0/youtubetelegramsummaries:latest
env:
CHANNEL_LIST: ${{ env.CHANNEL_LIST }}
run: docker run -e CHANNEL_LIST stell0/youtubetelegramsummaries:latest

69 changes: 55 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,79 @@
# YouTube to Telegram Summaries

- Check for new videos from a list of YouTube channels
This program use github actions to check every hour if there are new videos in a list of youtube channels, than if there is a new one, uses LangChain (OpenAI model) to summarize the content of the video and send the summary to a telegram group.

It only works with english at the moment.


TL;DR:
- Check for new videos from a list of YouTube channels

- When a new video is published, take the transcript and summarize it

- Send the summary to a Telegram channel
- Send the summary to a Telegram group

Needs an OpenAI api key to make the summary

## Launch using docker

Export variables
```
export OPENAI_API_KEY=xx-xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
export TELEGRAM_CHAT_ID=-123456789
export TELEGRAM_BOT_TOKEN=1234567890:XXX-XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
export CHANNEL_LIST=https://www.youtube.com/@allin https://www.youtube.com/@lexfridman https://www.youtube.com/@hubermanlab"
```

If a Telegram TELEGRAM_CHAT_ID and TELEGRAM_BOT_TOKEN environment variables are provided, summaries are also sent to the Telegram chat
And launch
```
docker run -e TELEGRAM_CHAT_ID -e TELEGRAM_BOT_TOKEN -e OPENAI_API_KEY -e CHANNEL_LIST stell0/youtubetelegramsummaries:latest
```


## Launch manually

Clone repo
```
git clone [email protected]:Stell0/youtubetelegramsummaries.git
cd youtubetelegramsummaries
```

## Telegram (optional):
Install requirements
```
TELEGRAM_CHAT_ID=-123456789
TELEGRAM_BOT_TOKEN=1234567890:XXX-XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
pip install -r requirements.txt
```

## Launch:
Export variables
```
export OPENAI_API_KEY=xx-xXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
export TELEGRAM_CHAT_ID=-123456789
export TELEGRAM_BOT_TOKEN=1234567890:XXX-XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxX
export CHANNEL_LIST=https://www.youtube.com/@allin https://www.youtube.com/@hubermanlab https://www.youtube.com/@JosephCarlsonShow"
```

And launch
```
python3 src/main.py
```

## How to setup your github action bot:

## Launch every hour using github actions:

- fork this repository
- add into your https://github.com/YOUR_USERNAME/youtubetelegramsummaries/settings/secrets/actions the following variables:
`DOCKERHUB_USERNAME`: your [dockerhub](https://hub.docker.com/) username
`DOCKERHUB_TOKEN`: dockerhub read/write access token https://hub.docker.com/settings/security

- add into your [action secrets](https://github.com/YOUR_USERNAME/youtubetelegramsummaries/settings/secrets/actions)
the following variables:

`TELEGRAM_CHAT_ID`: the [ID of the telegram chat](https://stackoverflow.com/questions/32423837/telegram-bot-how-to-get-a-group-chat-id) you whant your message to be sent
`TELEGRAM_BOT_TOKEN`: a telegram bot [token](https://core.telegram.org/bots/features#botfather)
`OPENAI_API_KEY`: OpenAI API key
- change all "stell0" occurrence in .github/workflows/*.yml with your username
`OPENAI_API_KEY`: your OpenAI API key

- Then add in your [action variables](https://github.com/YOUR_USERNAME/youtubetelegramsummaries/settings/variables/actions)the variable with the list of channels

`CHANNEL_LIST`: list of youtube channels, for instance:
```
https://www.youtube.com/@allin
https://www.youtube.com/@lexfridman
https://www.youtube.com/@hubermanlab
```

then wait ⏱️ (cron is launched every hour and take videos published during the previous hour)
5 changes: 0 additions & 5 deletions config/channels.txt

This file was deleted.

9 changes: 4 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import telegram_alert
from pytube import YouTube
import scrapetube


import os

def main():
# load channels
with open('config/channels.txt', 'r') as file:
channels = [line.strip() for line in file if line.strip()]
channels_list = os.environ.get("CHANNEL_LIST")
channels = channels_list.split()

for channel in channels:
try:
videos = scrapetube.get_channel(channel_url=channel,limit=1)
Expand Down

0 comments on commit 688397f

Please sign in to comment.