Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ __pycache__/
# C extensions
*.so

# ignore Telegram Token
*.telegramToken
.telegramToken

# ignore .pem file
*.pem
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
24 changes: 21 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import telebot
from utils import search_download_youtube_video
from loguru import logger

from yt_dlp import YoutubeDL

class Bot:

Expand Down Expand Up @@ -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"""
Expand All @@ -61,14 +65,28 @@ 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()