From b5315145fcc05a4a453ca85895743dd9ac515dfb Mon Sep 17 00:00:00 2001 From: Ara0n Date: Sat, 15 Jan 2022 19:56:53 +0530 Subject: [PATCH] POC complete --- bot/bot.py | 35 ++++++++++++++++++++++++----------- bot/botUtils.py | 2 +- downloaderService/main.py | 1 + uploaderService/main.py | 8 ++++++-- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 716cb80..5629894 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -1,10 +1,14 @@ +from cgitb import text import logging import json from operator import truediv +from time import time from telegram.ext import Updater, CommandHandler, MessageHandler, Filters from telegram.update import Update from botUtils import showhelp,parse_search_query,getalltsfiles import subprocess +import datetime +import pytz @@ -19,17 +23,16 @@ API_TOKEN = configdata.get("bot_token") def start(update,context): - update.message.reply_text("Hello there!") + update.message.reply_text("Thanks for using Araon Bot(v:0.01)\nThis is a alpha built so expect delayed response and many bugs\nIf you spot any issue feel free to reach out") def help(update,context): text = showhelp() update.message.reply_text(text) - + def search(update, context): logger.info('Search function is called!') - update.message.reply_text('Searching....') def get(update, context): @@ -42,13 +45,10 @@ def get(update, context): update.message.reply_text(f"Checking Internal Db\nAnime: {userdata.get('series')}\nSeason: {userdata.get('season_id')}\nEpisode: {userdata.get('episode_id')}") download_status = subprocess.check_call("python downloaderService/main.py "+'"'+userdata.get('series')+'"'+ ' ' + userdata.get('episode_id') , shell=True) - update.message.reply_text(f"{userdata.get('series')} - {userdata.get('episode_id')} Downloaded!") - + update.message.reply_text(f"{userdata.get('series')} - {userdata.get('episode_id')} almost done downloading on the server side!") filepath = getalltsfiles() - print("getalltsfiles: ",filepath) - update.message.reply_text(f"{userdata.get('series')} - {userdata.get('episode_id')} Uploading Started!") + #update.message.reply_text(f"{userdata.get('series')} - {userdata.get('episode_id')} Uploading Started!") upload_status = subprocess.check_call("python uploaderService/main.py " +'"'+filepath+'"'+ ' ' + str(chat_id) + ' ' + (userdata.get('series')+str(userdata.get('episode_id'))), shell=True) - print(upload_status) else: update.message.reply_text("Please refer to /help") @@ -71,7 +71,7 @@ def check_document(update, context): caption = update.message.caption end_user_chat_id = caption.split(":")[0] #Keep in mind here i have to parse the chat_id from the caption above - context.bot.send_video(end_user_chat_id,file_id,supports_streaming=True) + context.bot.send_video(end_user_chat_id,file_id,supports_streaming=True,timeout=120) @@ -81,12 +81,24 @@ def debug_message(update, context): update.message.reply_text(str(user_id)) +def callback_minute(context): + context.bot.send_message(chat_id = configdata.get('agent_user_id'), text = 'Heart_beat <3') +# def check_for_update(): +# logger.info('Checking Update for Animdl') +# subprocess.check_call("python -m pip install git+https://www.github.com/justfoolingaround/animdl") + def main(): - updater = Updater(token=API_TOKEN, use_context=True, request_kwargs={'read_timeout': 100, 'connect_timeout': 100}) + updater = Updater(token=API_TOKEN, use_context=True, request_kwargs={'read_timeout': 10, 'connect_timeout': 10}) + + job = updater.job_queue + # Get the dispatcher to register handlers dp = updater.dispatcher + + job.run_repeating(callback_minute, interval=60,first=10) + #job.run_daily(check_for_update) # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) @@ -99,8 +111,9 @@ def main(): dp.add_handler(MessageHandler(Filters.video, check_document)) dp.add_error_handler(error) + - updater.start_polling() + updater.start_polling(timeout=120) updater.idle() diff --git a/bot/botUtils.py b/bot/botUtils.py index f1a2704..07d7393 100644 --- a/bot/botUtils.py +++ b/bot/botUtils.py @@ -14,7 +14,7 @@ example - /search Death Note import os def showhelp(): - helpText = "Here are the following bot commands\n\n/get - will download the anime episode you wanted\nexample - /get Death note, s1, ep3\n\n/getadd - will provide all the episode of an anime in a given season\nexample - /getall Death Note, s1\n\n/search - will provide deatails about an anime\nexample - /search Death Note" + helpText = "Here are the following bot commands\n\n/get - will download the anime episode you wanted(make sure you seperate the name and the season and ep with comma)\nexample - /get Death note, 1, 3\n\n/getall(still in development) - will provide all the episode of an anime in a given season\nexample - /getall Death Note, 1\n\n/search(still in development) - will provide deatails about an anime\nexample - /search Death Note" return helpText def parse_search_query(raw_input): diff --git a/downloaderService/main.py b/downloaderService/main.py index a30bfac..d8f6945 100644 --- a/downloaderService/main.py +++ b/downloaderService/main.py @@ -24,6 +24,7 @@ def convert2mp4(infile, outfile): subprocess.run(['ffmpeg','-i',infile,'-c:v','copy','-c:a','copy','-preset:v','ultrafast','-segment_list_flags','+live',outfile]) + def main(argv): search_query = argv[1] search_query_range = argv[2] diff --git a/uploaderService/main.py b/uploaderService/main.py index 1f68573..a1c7eb1 100644 --- a/uploaderService/main.py +++ b/uploaderService/main.py @@ -17,7 +17,10 @@ from telethon import TelegramClient from telethon.tl.types import DocumentAttributeVideo import asyncio import json +import logging +logging.basicConfig(format='%(levelname)s - %(asctime)s - %(name)s - %(message)s', level=logging.INFO) +logger = logging.getLogger(__name__) with open('uploaderService/config/agentConfig.json', 'r') as config: configdata = json.load(config) @@ -33,9 +36,9 @@ bot_name = configdata.get('bot_name') -def callback(current, total): +async def callback(current, total): # for upload progression - print('Uploaded: {:.2%}'.format(current / total)) + logger.info('Uploaded: {:.2%}'.format(current / total)) ''' @@ -45,6 +48,7 @@ chat_id = this is the end user chat_id, sent over caption to bot, so it can pars object_id = an internal id used for mapping of file_id and filename stored in the server(for optimization). ''' async def uploadVideo(bot_name,file_path,chat_id,object_id): + logger.info('UploadVideo Called') async with TelegramClient(entity, api_id, api_hash) as client: if not await client.is_user_authorized(): #await client.send_code_request(phone) #at the first start - uncomment, after authorization to avoid FloodWait I advise you to comment