From 9458ac3e6c9e8e41b630d24be6808b331f72c93c Mon Sep 17 00:00:00 2001 From: naorx Date: Wed, 19 Oct 2022 19:29:33 +0300 Subject: [PATCH 1/5] U --- .gitignore | 2 +- requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bf0d076..73a4aa2 100644 --- a/.gitignore +++ b/.gitignore @@ -116,7 +116,7 @@ pip-selfcheck.json .idea/dictionaries .idea/vcs.xml .idea/jsLibraryMappings.xml - +.telegramtoken # Sensitive or high-churn files: .idea/dataSources.ids .idea/dataSources.xml diff --git a/requirements.txt b/requirements.txt index 1e50522..5238436 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ pyTelegramBotAPI -yt-dlp>=2022.6.29 +yt-dlp==2022.10.4 loguru \ No newline at end of file From 1130d1ed60ba6a4eee96bb45628e9748c479f444 Mon Sep 17 00:00:00 2001 From: naorx Date: Thu, 20 Oct 2022 00:04:46 +0300 Subject: [PATCH 2/5] U --- .gitignore | 2 +- app.py | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 73a4aa2..740173b 100644 --- a/.gitignore +++ b/.gitignore @@ -116,7 +116,7 @@ pip-selfcheck.json .idea/dictionaries .idea/vcs.xml .idea/jsLibraryMappings.xml -.telegramtoken +.telegramToken # Sensitive or high-churn files: .idea/dataSources.ids .idea/dataSources.xml diff --git a/app.py b/app.py index 45e12d7..6a4f04c 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ import telebot + from utils import search_download_youtube_video from loguru import logger @@ -41,7 +42,8 @@ def download_user_photo(self, quality=0): :return: """ if self.current_msg.content_type != 'photo': - raise RuntimeError(f'Message content of type \'photo\' expected, but got {self.current_msg["content_type"]}') + raise RuntimeError( + f'Message content of type \'photo\' expected, but got {self.current_msg["content_type"]}') file_info = self.bot.get_file(self.current_msg.photo[quality].file_id) data = self.bot.download_file(file_info.file_path) @@ -61,14 +63,25 @@ def handle_message(self, message): class YoutubeBot(Bot): - pass + def handle_message(self, message): + self.bot.send_message(self.current_msg.chat.id, "in order to start type start") + if message.text == 'start': + self.bot.send_message(self.current_msg.chat.id, "which song would you like me to search for you") + + search_download_youtube_video(self.current_msg) + self.send_text("your song has been downloaded") if __name__ == '__main__': with open('.telegramToken') as f: _token = f.read() - - my_bot = Bot(_token) - my_bot.start() - - + which_bot = input("which bot do you want: ") + if which_bot == "youtube": + my_bot = YoutubeBot(_token) + my_bot.start() + elif which_bot == "quotebot": + my_bot = QuoteBot(_token) + QuoteBot.start(my_bot) + elif which_bot == "bot": + my_bot = Bot(_token) + Bot.start(my_bot) From 82f5b9526f96972df2097faf3b437530dde0d428 Mon Sep 17 00:00:00 2001 From: naorx Date: Thu, 20 Oct 2022 17:31:49 +0300 Subject: [PATCH 3/5] U --- Dockerfile | 3 +++ app.py | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index ac0a3bb..ab68c18 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,8 @@ FROM python:3.8.12-slim-buster +COPY . . + +RUN pip install -r requirements.txt # YOUR COMMANDS HERE # .... # .... diff --git a/app.py b/app.py index 6a4f04c..81ac27d 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,7 @@ +import time + import telebot +import yt_dlp.YoutubeDL from utils import search_download_youtube_video from loguru import logger @@ -64,12 +67,14 @@ def handle_message(self, message): class YoutubeBot(Bot): def handle_message(self, message): - self.bot.send_message(self.current_msg.chat.id, "in order to start type start") - if message.text == 'start': - self.bot.send_message(self.current_msg.chat.id, "which song would you like me to search for you") - - search_download_youtube_video(self.current_msg) - self.send_text("your song has been downloaded") + if message.text == "start": + self.send_text("welcome to the youtubeBot") + time.sleep(2) + self.send_text("in order to find a song write its name") + + if message.text != "start": + search_download_youtube_video(message.text, 1) + self.send_text("your video has been downloaded") if __name__ == '__main__': From 7872cafdd1cf83adff0a236a5ad415f6953f7888 Mon Sep 17 00:00:00 2001 From: naorx Date: Sat, 22 Oct 2022 04:07:17 +0300 Subject: [PATCH 4/5] U --- Dockerfile | 5 ++--- app.py | 29 ++++++++++++----------------- utils.py | 4 ++-- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index ab68c18..6644060 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,9 @@ FROM python:3.8.12-slim-buster +WORKDIR /TelegramAI-Naor + COPY . . RUN pip install -r requirements.txt -# YOUR COMMANDS HERE -# .... -# .... CMD ["python3", "app.py"] \ No newline at end of file diff --git a/app.py b/app.py index 81ac27d..123e2ec 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,5 @@ import time - import telebot -import yt_dlp.YoutubeDL - from utils import search_download_youtube_video from loguru import logger @@ -67,26 +64,24 @@ def handle_message(self, message): class YoutubeBot(Bot): def handle_message(self, message): - if message.text == "start": + if self.is_current_msg_photo(): + self.download_user_photo(quality=3) + return + if message.text == "/start": self.send_text("welcome to the youtubeBot") time.sleep(2) self.send_text("in order to find a song write its name") + else: + link = search_download_youtube_video(message.text) + self.send_text(link[0].get("url")) - if message.text != "start": - search_download_youtube_video(message.text, 1) - self.send_text("your video has been downloaded") + time.sleep(2) + self.send_text("if you would like another song just write it's name (: ") if __name__ == '__main__': with open('.telegramToken') as f: _token = f.read() - which_bot = input("which bot do you want: ") - if which_bot == "youtube": - my_bot = YoutubeBot(_token) - my_bot.start() - elif which_bot == "quotebot": - my_bot = QuoteBot(_token) - QuoteBot.start(my_bot) - elif which_bot == "bot": - my_bot = Bot(_token) - Bot.start(my_bot) + +my_bot = YoutubeBot(_token) +my_bot.start() diff --git a/utils.py b/utils.py index e5426e0..9b6cc40 100644 --- a/utils.py +++ b/utils.py @@ -1,10 +1,10 @@ -import time + from yt_dlp import YoutubeDL def search_download_youtube_video(video_name, num_results=1): """ - This function downloads the first num_results search results from Youtube + 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 From 4b490a64f52abd62be1a1dabd9cb8a24ae394abc Mon Sep 17 00:00:00 2001 From: naorx Date: Tue, 25 Oct 2022 05:31:29 +0300 Subject: [PATCH 5/5] U --- app.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 123e2ec..29a650e 100644 --- a/app.py +++ b/app.py @@ -47,6 +47,8 @@ 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) + with open(file_info.file_path, 'wb') as new_file: + new_file.write(data) # TODO save `data` as a photo in `file_info.file_path` path @@ -67,14 +69,15 @@ def handle_message(self, message): if self.is_current_msg_photo(): self.download_user_photo(quality=3) return + if message.text == "/start": self.send_text("welcome to the youtubeBot") time.sleep(2) self.send_text("in order to find a song write its name") - else: + + if message.text is not self.is_current_msg_photo(): link = search_download_youtube_video(message.text) self.send_text(link[0].get("url")) - time.sleep(2) self.send_text("if you would like another song just write it's name (: ")