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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM python:3.8.12-slim-buster

# YOUR COMMANDS HERE
# ....
# ....
WORKDIR /TelegramAI-Naor

COPY . .

RUN pip install -r requirements.txt

CMD ["python3", "app.py"]
28 changes: 22 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import telebot
from utils import search_download_youtube_video
from loguru import logger
Expand Down Expand Up @@ -41,10 +42,13 @@ 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)
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

Expand All @@ -61,14 +65,26 @@ def handle_message(self, message):


class YoutubeBot(Bot):
pass
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")

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 (: ")


if __name__ == '__main__':
with open('.telegramToken') as f:
_token = f.read()

my_bot = Bot(_token)
my_bot.start()


my_bot = YoutubeBot(_token)
my_bot.start()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pyTelegramBotAPI
yt-dlp>=2022.6.29
yt-dlp==2022.10.4
loguru
4 changes: 2 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down