From 41a482f2e21524046683d5798e8ec7c760a48a04 Mon Sep 17 00:00:00 2001 From: ehershber Date: Fri, 14 Oct 2022 09:49:59 +0300 Subject: [PATCH 1/3] telegramignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index bf0d076..ee39d48 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ __pycache__/ # C extensions *.so +# ignore Telegram Token +*.telegramToken +.telegramToken # ignore .pem file *.pem From 63d1698632266abf027579df71fd178f8a3c52a1 Mon Sep 17 00:00:00 2001 From: ehershber Date: Fri, 4 Nov 2022 12:57:15 +0200 Subject: [PATCH 2/3] python_ex --- app.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 45e12d7..2fa8be7 100644 --- a/app.py +++ b/app.py @@ -1,7 +1,7 @@ import telebot from utils import search_download_youtube_video from loguru import logger - +from yt_dlp import YoutubeDL class Bot: @@ -46,7 +46,11 @@ def download_user_photo(self, quality=0): file_info = self.bot.get_file(self.current_msg.photo[quality].file_id) data = self.bot.download_file(file_info.file_path) + + # TODO save `data` as a photo in `file_info.file_path` path + with open(file_info.file_path, 'wb') as photo: + photo.write(data) def handle_message(self, message): """Bot Main message handler""" @@ -61,14 +65,26 @@ def handle_message(self, message): class YoutubeBot(Bot): - pass + def handle_message(self, video_name): + if self.is_current_msg_photo(): + return self.download_user_photo(quality=0) + """ + This function downloads the first num_results search results from Youtube + :param video_name: string of the video name + :param num_results: integer representing how many videos to download + :return: list of paths to your downloaded video files + """ + results = search_download_youtube_video(video_name.text) + self.send_text(results[0]['url']) + + if __name__ == '__main__': with open('.telegramToken') as f: _token = f.read() - my_bot = Bot(_token) + my_bot = YoutubeBot(_token) my_bot.start() From 6366030cbb46fd838f28808ac363626390fdba62 Mon Sep 17 00:00:00 2001 From: ehershber Date: Sun, 6 Nov 2022 17:11:53 +0200 Subject: [PATCH 3/3] python_ex_final --- Dockerfile | 6 +++--- app.py | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index ac0a3bb..fc3f85b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM python:3.8.12-slim-buster -# YOUR COMMANDS HERE -# .... -# .... +WORKDIR /TelegramAI +COPY . . +RUN pip install -r requirements.txt CMD ["python3", "app.py"] \ No newline at end of file diff --git a/app.py b/app.py index 2fa8be7..574394e 100644 --- a/app.py +++ b/app.py @@ -68,6 +68,8 @@ class YoutubeBot(Bot): def handle_message(self, video_name): if self.is_current_msg_photo(): return self.download_user_photo(quality=0) + + """ This function downloads the first num_results search results from Youtube :param video_name: string of the video name