From 688397f909759ff665e976cd41574b421bf20093 Mon Sep 17 00:00:00 2001 From: Stefano Fancello Date: Fri, 22 Mar 2024 22:50:00 +0100 Subject: [PATCH] Use environment variable for channels to make it easy for everyone to use it --- .github/workflows/cron-run.yml | 3 +- .github/workflows/image-build.yml | 3 +- .github/workflows/pr-build.yml | 4 +- README.md | 69 ++++++++++++++++++++++++------- config/channels.txt | 5 --- src/main.py | 9 ++-- 6 files changed, 66 insertions(+), 27 deletions(-) delete mode 100644 config/channels.txt diff --git a/.github/workflows/cron-run.yml b/.github/workflows/cron-run.yml index b96fe24..b508355 100644 --- a/.github/workflows/cron-run.yml +++ b/.github/workflows/cron-run.yml @@ -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 diff --git a/.github/workflows/image-build.yml b/.github/workflows/image-build.yml index 4611480..935c36d 100644 --- a/.github/workflows/image-build.yml +++ b/.github/workflows/image-build.yml @@ -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 diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index bbcccaa..58ad251 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -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 diff --git a/README.md b/README.md index 713e4fc..085cf4b 100644 --- a/README.md +++ b/README.md @@ -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 git@github.com: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 \ No newline at end of file +`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) diff --git a/config/channels.txt b/config/channels.txt deleted file mode 100644 index c4e51c3..0000000 --- a/config/channels.txt +++ /dev/null @@ -1,5 +0,0 @@ -https://www.youtube.com/@allin -https://www.youtube.com/@CoinBureau -https://www.youtube.com/@JosephCarlsonShow -https://www.youtube.com/@Bitcoin_University -https://www.youtube.com/@Aimston diff --git a/src/main.py b/src/main.py index a3b98f6..0e19a00 100644 --- a/src/main.py +++ b/src/main.py @@ -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)