Major project structure rebase
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
44fff43553
commit
21dacbc8fb
|
|
@ -1 +1,6 @@
|
||||||
*config.env
|
*.env
|
||||||
|
*.ini
|
||||||
|
*auth_token.txt
|
||||||
|
*.pyc
|
||||||
|
downloads/*
|
||||||
|
data*
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
aria2c --dir ./download/ --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --max-connection-per-server=10 --rpc-max-request-size=1024M --seed-time=0.01 --min-split-size=10M --follow-torrent=mem --split=10 --daemon=true --allow-overwrite=true"
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
aria2c --dir ./download/ --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --max-connection-per-server=10 --rpc-max-request-size=1024M --seed-time=0.01 --min-split-size=10M --follow-torrent=mem --split=10 --daemon=true --allow-overwrite=true
|
||||||
57
bot.py
57
bot.py
|
|
@ -1,57 +0,0 @@
|
||||||
from telegram.ext import Updater,CommandHandler,run_async
|
|
||||||
import ariaTools
|
|
||||||
import logging
|
|
||||||
import gdriveTools
|
|
||||||
import ConfigParser
|
|
||||||
|
|
||||||
config = ConfigParser.ConfigParser()
|
|
||||||
|
|
||||||
config.read('config.env')
|
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
||||||
level=logging.INFO)
|
|
||||||
|
|
||||||
if (getConfig('_____REMOVE_THIS_LINE_____')):
|
|
||||||
logging.ERROR('The README.md file there to be read! Exiting now!')
|
|
||||||
|
|
||||||
|
|
||||||
def getConfig(var: str):
|
|
||||||
return config.get('BOT', var)
|
|
||||||
|
|
||||||
@run_async
|
|
||||||
def start(update, context):
|
|
||||||
print(update)
|
|
||||||
context.bot.send_message(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
|
|
||||||
|
|
||||||
@run_async
|
|
||||||
def mirror(update,context):
|
|
||||||
message = update.message.text
|
|
||||||
link = message.replace('/mirror','')[1:]
|
|
||||||
reply_msg = context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id, text="Starting Download")
|
|
||||||
download = ariaTools.add_download(link,[reply_msg,update])
|
|
||||||
ariaTools.progress_status(context,reply_msg,previous=None)
|
|
||||||
with open('data','r') as f:
|
|
||||||
file_name = f.read()
|
|
||||||
print("File-Name: "+file_name)
|
|
||||||
link = gdriveTools.upload(file_name)
|
|
||||||
msg = '<a href="{}">{}</a>'.format(link,file_name)
|
|
||||||
context.bot.edit_message_text(text=msg,message_id=reply_msg.message_id,chat_id=reply_msg.chat.id,parse_mode='HTMl')
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
BOT_TOKEN = getConfig('BOT_TOKEN')
|
|
||||||
updater = Updater(token=BOT_TOKEN, use_context=True)
|
|
||||||
|
|
||||||
start_handler = CommandHandler('start', start)
|
|
||||||
mirror_handler = CommandHandler('mirror',mirror)
|
|
||||||
dispatcher = updater.dispatcher
|
|
||||||
dispatcher.add_handler(start_handler)
|
|
||||||
dispatcher.add_handler(mirror_handler)
|
|
||||||
logging.info("Bot Started")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
updater.start_polling()
|
|
||||||
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
import logging
|
||||||
|
import configparser
|
||||||
|
from telegram.ext import Updater
|
||||||
|
|
||||||
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
|
level=logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read('bot/config.ini')
|
||||||
|
|
||||||
|
|
||||||
|
def getConfig(name: str):
|
||||||
|
return config['DEFAULT'][name]
|
||||||
|
|
||||||
|
LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if bool(config['DEFAULT']['_____REMOVE_THIS_LINE_____']):
|
||||||
|
logging.ERROR('The README.md file there to be read! Exiting now!')
|
||||||
|
exit()
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
BOT_TOKEN = getConfig('BOT_TOKEN')
|
||||||
|
updater = Updater(token=BOT_TOKEN, use_context=True)
|
||||||
|
dispatcher = updater.dispatcher
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
from telegram.ext import CommandHandler, run_async
|
||||||
|
from bot import dispatcher, LOGGER, updater
|
||||||
|
import bot.mirror
|
||||||
|
|
||||||
|
@run_async
|
||||||
|
def start(update, context):
|
||||||
|
print(update)
|
||||||
|
context.bot.send_message(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
|
||||||
|
|
||||||
|
LOGGER.info('__main__.py')
|
||||||
|
def main():
|
||||||
|
start_handler = CommandHandler('start', start)
|
||||||
|
dispatcher.add_handler(start_handler)
|
||||||
|
LOGGER.info("Bot Started!")
|
||||||
|
updater.start_polling()
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
class Config(object):
|
||||||
|
"""docstring for Config"""
|
||||||
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
#Remove this line before deploying
|
#Remove this line before deploying
|
||||||
_____REMOVE_THIS_LINE_____=True
|
_____REMOVE_THIS_LINE_____=True
|
||||||
[BOT]
|
[DEFAULT]
|
||||||
|
|
||||||
# ENTER BOT TOKEN( Get it from https://my.telegram.org)
|
# ENTER BOT TOKEN( Get it from https://my.telegram.org)
|
||||||
BOT_TOKEN=""
|
BOT_TOKEN =
|
||||||
|
G_DRIVE_CLIENT_ID =
|
||||||
|
G_DRIVE_CLIENT_SECRET =
|
||||||
|
GDRIVE_FOLDER_ID =
|
||||||
|
|
@ -1,15 +1,10 @@
|
||||||
import aria2p
|
import aria2p
|
||||||
import os
|
import os
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import logging
|
from bot import LOGGER
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
||||||
level=logging.INFO)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cmd = "aria2c --enable-rpc --rpc-listen-all=false --rpc-listen-port 6800 --max-connection-per-server=10 --rpc-max-request-size=1024M --seed-time=0.01 --min-split-size=10M --follow-torrent=mem --split=10 --daemon=true --allow-overwrite=true"
|
|
||||||
EDIT_SLEEP_TIME_OUT = 5
|
EDIT_SLEEP_TIME_OUT = 5
|
||||||
aria2_is_running = os.system(cmd)
|
|
||||||
|
|
||||||
aria2 = aria2p.API(
|
aria2 = aria2p.API(
|
||||||
aria2p.Client(
|
aria2p.Client(
|
||||||
|
|
@ -26,7 +21,7 @@ def check_metadata(gid):
|
||||||
file = aria2.get_download(gid)
|
file = aria2.get_download(gid)
|
||||||
if file.followed_by_ids[0] != None:
|
if file.followed_by_ids[0] != None:
|
||||||
new_gid = file.followed_by_ids[0]
|
new_gid = file.followed_by_ids[0]
|
||||||
logging.info("Changing GID "+gid+" to "+new_gid)
|
LOGGER.info("Changing GID "+gid+" to "+new_gid)
|
||||||
return new_gid
|
return new_gid
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
@ -36,12 +31,12 @@ def add_download(link,message):
|
||||||
if "magnet" in link:
|
if "magnet" in link:
|
||||||
download = aria2.add_magnet(link)
|
download = aria2.add_magnet(link)
|
||||||
allDls[message[0]] = [download,message[1]]
|
allDls[message[0]] = [download,message[1]]
|
||||||
logging.info("Adding: "+link)
|
LOGGER.info("Adding: "+link)
|
||||||
return download
|
return download
|
||||||
else:
|
else:
|
||||||
download = aria2.add_uris([link])
|
download = aria2.add_uris([link])
|
||||||
allDls[message[0]] = [download,message[1]]
|
allDls[message[0]] = [download,message[1]]
|
||||||
logging.info("Adding: "+link)
|
LOGGER.info("Adding: "+link)
|
||||||
return download
|
return download
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -77,7 +72,7 @@ def progress_status(context,update,previous):
|
||||||
sleep(5)
|
sleep(5)
|
||||||
progress_status(context,update,previous)
|
progress_status(context,update,previous)
|
||||||
else:
|
else:
|
||||||
logging.error(file.error_message)
|
LOGGER.error(file.error_message)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
|
|
@ -90,7 +85,7 @@ def progress_status(context,update,previous):
|
||||||
allDls[update][0] = download
|
allDls[update][0] = download
|
||||||
progress_status(context,update,previous=None)
|
progress_status(context,update,previous=None)
|
||||||
else:
|
else:
|
||||||
logging.info(file.name+" Completed.")
|
LOGGER.info(file.name+" Completed.")
|
||||||
msg = "<i>"+str(file.name) +"</i>:- Uploading."
|
msg = "<i>"+str(file.name) +"</i>:- Uploading."
|
||||||
context.bot.edit_message_text(text=msg,message_id=update.message_id,chat_id=update.chat.id,parse_mode='HTMl')
|
context.bot.edit_message_text(text=msg,message_id=update.message_id,chat_id=update.chat.id,parse_mode='HTMl')
|
||||||
with open('data','w') as f:
|
with open('data','w') as f:
|
||||||
|
|
@ -7,26 +7,22 @@ from oauth2client import file, client, tools
|
||||||
from mimetypes import guess_type
|
from mimetypes import guess_type
|
||||||
import httplib2
|
import httplib2
|
||||||
import os
|
import os
|
||||||
from config import Config
|
from bot import LOGGER, getConfig
|
||||||
import logging
|
|
||||||
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
||||||
level=logging.INFO)
|
|
||||||
|
|
||||||
|
|
||||||
G_DRIVE_TOKEN_FILE = "auth_token.txt"
|
G_DRIVE_TOKEN_FILE = "auth_token.txt"
|
||||||
# Copy your credentials from the APIs Console
|
# Copy your credentials from the APIs Console
|
||||||
CLIENT_ID = Config.G_DRIVE_CLIENT_ID
|
CLIENT_ID = getConfig('G_DRIVE_CLIENT_ID')
|
||||||
CLIENT_SECRET = Config.G_DRIVE_CLIENT_SECRET
|
CLIENT_SECRET = getConfig('G_DRIVE_CLIENT_SECRET')
|
||||||
# Check https://developers.google.com/drive/scopes for all available scopes
|
# Check https://developers.google.com/drive/scopes for all available scopes
|
||||||
OAUTH_SCOPE = "https://www.googleapis.com/auth/drive.file"
|
OAUTH_SCOPE = "https://www.googleapis.com/auth/drive.file"
|
||||||
# Redirect URI for installed apps, can be left as is
|
# Redirect URI for installed apps, can be left as is
|
||||||
REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"
|
REDIRECT_URI = "urn:ietf:wg:oauth:2.0:oob"
|
||||||
parent_id = Config.GDRIVE_FOLDER_ID
|
parent_id = getConfig('GDRIVE_FOLDER_ID')
|
||||||
G_DRIVE_DIR_MIME_TYPE = "application/vnd.google-apps.folder"
|
G_DRIVE_DIR_MIME_TYPE = "application/vnd.google-apps.folder"
|
||||||
|
|
||||||
|
|
||||||
if CLIENT_ID is None or CLIENT_SECRET is None or parent_id is None:
|
if CLIENT_ID is None or CLIENT_SECRET is None or parent_id is None:
|
||||||
logging.error("Please Setup Config Properly.")
|
LOGGER.error("Please Setup Config Properly.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -46,10 +42,10 @@ def upload(fileName):
|
||||||
file_name, mime_type = file_ops(fileName)
|
file_name, mime_type = file_ops(fileName)
|
||||||
try:
|
try:
|
||||||
g_drive_link = upload_file(http, file_name,file_name, mime_type,parent_id)
|
g_drive_link = upload_file(http, file_name,file_name, mime_type,parent_id)
|
||||||
logging.info("Uploaded To G-Drive: "+fileName)
|
LOGGER.info("Uploaded To G-Drive: "+fileName)
|
||||||
link = g_drive_link
|
link = g_drive_link
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(str(e))
|
LOGGER.error(str(e))
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
http = authorize(G_DRIVE_TOKEN_FILE, None)
|
http = authorize(G_DRIVE_TOKEN_FILE, None)
|
||||||
|
|
@ -57,11 +53,11 @@ def upload(fileName):
|
||||||
try:
|
try:
|
||||||
dir_id = create_directory(http, os.path.basename(os.path.abspath(fileName)), parent_id)
|
dir_id = create_directory(http, os.path.basename(os.path.abspath(fileName)), parent_id)
|
||||||
DoTeskWithDir(http,fileName, dir_id)
|
DoTeskWithDir(http,fileName, dir_id)
|
||||||
logging.info("Uploaded To G-Drive: "+fileName)
|
LOGGER.info("Uploaded To G-Drive: "+fileName)
|
||||||
dir_link = "https://drive.google.com/folderview?id={}".format(dir_id)
|
dir_link = "https://drive.google.com/folderview?id={}".format(dir_id)
|
||||||
link = dir_link
|
link = dir_link
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(str(e))
|
LOGGER.error(str(e))
|
||||||
pass
|
pass
|
||||||
return link
|
return link
|
||||||
# with open('data','w') as f:
|
# with open('data','w') as f:
|
||||||
|
|
@ -88,7 +84,7 @@ def create_directory(http, directory_name, parent_id):
|
||||||
file = drive_service.files().insert(body=file_metadata).execute()
|
file = drive_service.files().insert(body=file_metadata).execute()
|
||||||
file_id = file.get("id")
|
file_id = file.get("id")
|
||||||
drive_service.permissions().insert(fileId=file_id, body=permissions).execute()
|
drive_service.permissions().insert(fileId=file_id, body=permissions).execute()
|
||||||
logging.info("Created Gdrive Folder:\nName: {}\nID: {} ".format(file.get("title"), file_id))
|
LOGGER.info("Created Gdrive Folder:\nName: {}\nID: {} ".format(file.get("title"), file_id))
|
||||||
return file_id
|
return file_id
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
from telegram.ext import CommandHandler, run_async
|
||||||
|
from bot.helper import ariaTools, gdriveTools
|
||||||
|
import configparser
|
||||||
|
from bot import config, LOGGER, dispatcher
|
||||||
|
|
||||||
|
LOGGER.info('mirror.py')
|
||||||
|
@run_async
|
||||||
|
def mirror(update,context):
|
||||||
|
message = update.message.text
|
||||||
|
link = message.replace('/mirror','')[1:]
|
||||||
|
reply_msg = context.bot.send_message(chat_id=update.message.chat_id, reply_to_message_id=update.message.message_id, text="Starting Download")
|
||||||
|
download = ariaTools.add_download(link,[reply_msg,update])
|
||||||
|
ariaTools.progress_status(context,reply_msg,previous=None)
|
||||||
|
with open('data','r') as f:
|
||||||
|
file_name = f.read()
|
||||||
|
print("File-Name: "+file_name)
|
||||||
|
link = gdriveTools.upload(file_name)
|
||||||
|
msg = '<a href="{}">{}</a>'.format(link,file_name)
|
||||||
|
context.bot.edit_message_text(text=msg,message_id=reply_msg.message_id,chat_id=reply_msg.chat.id,parse_mode='HTMl')
|
||||||
|
|
||||||
|
|
||||||
|
mirror_handler = CommandHandler('mirror', mirror)
|
||||||
|
dispatcher.add_handler(mirror_handler)
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
class Config(object):
|
|
||||||
"""docstring for Config"""
|
|
||||||
G_DRIVE_CLIENT_ID = ""
|
|
||||||
G_DRIVE_CLIENT_SECRET = ""
|
|
||||||
GDRIVE_FOLDER_ID = ""
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
python-telegram-bot
|
||||||
google-api-python-client>=1.7.3
|
google-api-python-client>=1.7.3
|
||||||
google-auth>=1.5.0
|
google-auth>=1.5.0
|
||||||
google-auth-httplib2<=0.0.3
|
google-auth-httplib2<=0.0.3
|
||||||
|
|
@ -7,7 +8,5 @@ ndg-httpsclient>=0.4.0
|
||||||
oauth>=1.0.1
|
oauth>=1.0.1
|
||||||
pyasn1>=0.4.3
|
pyasn1>=0.4.3
|
||||||
pyasn1-modules>=0.2.1
|
pyasn1-modules>=0.2.1
|
||||||
pycurl>=7.43.0
|
|
||||||
uritemplate>=3.0.0
|
uritemplate>=3.0.0
|
||||||
urllib3>=1.23
|
urllib3>=1.23
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue