Skip to content

Commit

Permalink
make it compatible for Heroku ==> OS
Browse files Browse the repository at this point in the history
  • Loading branch information
SpEcHiDe committed Nov 15, 2019
1 parent 69727d4 commit cb35bdb
Show file tree
Hide file tree
Showing 23 changed files with 879 additions and 91 deletions.
661 changes: 661 additions & 0 deletions COPYING

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
worker: python3 bot.py
worker: python3 -m tobrot
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Telegram Torrent Leecher 🔥🤖

A Telegram Torrent (and youtube-dl) Leecher based on [Pyrogram](https://github.com/pyrogram/pyrogram)

## installing

#### The Easy Way

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy)

#### The Legacy Way
Simply clone the repository and run the main file:

```sh
git clone https://github.com/SpEcHiDe/PyroGramUserBot.git
cd PyroGramUserBot
virtualenv -p /usr/bin/python3 venv
. ./venv/bin/activate
pip install -r requirements.txt
# <Create config.py appropriately>
python3 -m tobrot
```

## Credits, and Thanks to

* [Dan Tès](https://telegram.dog/haskell) for his [Pyrogram Library](https://github.com/pyrogram/pyrogram)
* [Robots](https://telegram.dog/Robots) for their @UploadBot
* @AjeeshNair for his torrent.ajee.sh
* @gotstc, @aryanvikash, @HasibulKabir for their TORRENT groups
* [![CopyLeft](https://telegra.ph/file/b514ed14d994557a724cb.jpg)](https://telegra.ph/file/fab1017e21c42a5c1e613.mp4 "CopyLeft Credit Video")
76 changes: 76 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "Telegram Torrent Leecher",
"description": "A Telegram Torrent (and youtube-dl) Leecher based on Pyrogram. Powered by @ThankTelegram!",
"keywords": [
"telegram",
"best",
"indian",
"pyrogram",
"torrent",
"3",
"plugin",
"modular",
"productivity",
"youtube-dl",
"leecher"
],
"repository": "https://github.com/SpEcHiDe/PublicLeech",
"success_url": "https://telegram.dog/ThankTelegram",
"website": "https://github.com/SpEcHiDe/PublicLeech",
"env": {
"ENV": {
"description": "Setting this to ANYTHING will enable webhooks when in env mode",
"value": "ANYTHING"
},
"APP_ID": {
"description": "Get this value from https://my.telegram.org",
"value": ""
},
"API_HASH": {
"description": "Get this value from https://my.telegram.org",
"value": ""
},
"TG_BOT_TOKEN": {
"description": "get this value from @BotFather",
"value": ""
},
"AUTH_CHANNEL": {
"description": "should be an integer. The BOT API ID of the Telegram Group, where the Leecher should work.",
"value": ""
},
"CHUNK_SIZE": {
"description": "should be an integer",
"value": "128",
"required": false
},
"ARIA_TWO_STARTED_PORT": {
"description": "should be an integer. The port on which aria2c daemon must start, and keep listening.",
"value": "6800",
"required": false
},
"EDIT_SLEEP_TIME_OUT": {
"description": "should be an integer. Number of seconds to wait before editing a message.",
"value": "1",
"required": false
},
"MAX_TIME_TO_WAIT_FOR_TORRENTS_TO_START": {
"description": "should be an integer. Number of seconds to wait before cancelling a torrent.",
"required": false
}
},
"addons": [
],
"buildpacks": [{
"url": "https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest"
}, {
"url": "https://github.com/amivin/aria2-heroku"
}, {
"url": "heroku/python"
}],
"formation": {
"worker": {
"quantity": 1,
"size": "free"
}
}
}
Binary file removed thumb_image.jpg
Binary file not shown.
30 changes: 30 additions & 0 deletions tobrot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# (c) Shrimadhav U K

import os

# the secret configuration specific things
if bool(os.environ.get("ENV", False)):
from pyrobot.sample_config import Config
else:
from pyrobot.config import Development as Config


# TODO: is there a better way?
TG_BOT_TOKEN = Config.TG_BOT_TOKEN
APP_ID = Config.APP_ID
API_HASH = Config.API_HASH
AUTH_CHANNEL = Config.AUTH_CHANNEL
DOWNLOAD_LOCATION = Config.DOWNLOAD_LOCATION
MAX_FILE_SIZE = Config.MAX_FILE_SIZE
TG_MAX_FILE_SIZE = Config.TG_MAX_FILE_SIZE
FREE_USER_MAX_FILE_SIZE = Config.FREE_USER_MAX_FILE_SIZE
CHUNK_SIZE = Config.CHUNK_SIZE
DEF_THUMB_NAIL_VID_S = Config.DEF_THUMB_NAIL_VID_S
MAX_MESSAGE_LENGTH = Config.MAX_MESSAGE_LENGTH
PROCESS_MAX_TIMEOUT = Config.PROCESS_MAX_TIMEOUT
ARIA_TWO_STARTED_PORT = Config.ARIA_TWO_STARTED_PORT
EDIT_SLEEP_TIME_OUT = Config.EDIT_SLEEP_TIME_OUT
MAX_TIME_TO_WAIT_FOR_TORRENTS_TO_START = Config.MAX_TIME_TO_WAIT_FOR_TORRENTS_TO_START
MAX_TG_SPLIT_FILE_SIZE = Config.MAX_TG_SPLIT_FILE_SIZE
47 changes: 25 additions & 22 deletions bot.py → tobrot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,77 +13,80 @@

import os

# the secret configuration specific things
if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
from tobrot import (
DOWNLOAD_LOCATION,
TG_BOT_TOKEN,
APP_ID,
API_HASH,
AUTH_CHANNEL
)

from pyrogram import Client, Filters, MessageHandler, CallbackQueryHandler
from plugins.new_join_fn import new_join_f, help_message_f, rename_message_f
from plugins.incoming_message_fn import incoming_message_f, incoming_youtube_dl_f
from plugins.status_message_fn import status_message_f, cancel_message_f
from plugins.call_back_button_handler import button

from tobrot.plugins.new_join_fn import new_join_f, help_message_f, rename_message_f
from tobrot.plugins.incoming_message_fn import incoming_message_f, incoming_youtube_dl_f
from tobrot.plugins.status_message_fn import status_message_f, cancel_message_f
from tobrot.plugins.call_back_button_handler import button


if __name__ == "__main__" :
# create download directory, if not exist
if not os.path.isdir(Config.DOWNLOAD_LOCATION):
os.makedirs(Config.DOWNLOAD_LOCATION)
if not os.path.isdir(DOWNLOAD_LOCATION):
os.makedirs(DOWNLOAD_LOCATION)
#
app = Client(
"LeechBot",
bot_token=Config.TG_BOT_TOKEN,
api_id=Config.APP_ID,
api_hash=Config.API_HASH,
bot_token=TG_BOT_TOKEN,
api_id=APP_ID,
api_hash=API_HASH,
workers=343
)
#
incoming_message_handler = MessageHandler(
incoming_message_f,
filters=Filters.command(["leech"]) & Filters.chat(chats=Config.AUTH_CHANNEL)
filters=Filters.command(["leech"]) & Filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(incoming_message_handler)
#
incoming_youtube_dl_handler = MessageHandler(
incoming_youtube_dl_f,
filters=Filters.command(["ytdl"]) & Filters.chat(chats=Config.AUTH_CHANNEL)
filters=Filters.command(["ytdl"]) & Filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(incoming_youtube_dl_handler)
#
status_message_handler = MessageHandler(
status_message_f,
filters=Filters.command(["status"]) & Filters.chat(chats=Config.AUTH_CHANNEL)
filters=Filters.command(["status"]) & Filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(status_message_handler)
#
cancel_message_handler = MessageHandler(
cancel_message_f,
filters=Filters.command(["cancel"]) & Filters.chat(chats=Config.AUTH_CHANNEL)
filters=Filters.command(["cancel"]) & Filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(cancel_message_handler)
#
rename_message_handler = MessageHandler(
rename_message_f,
filters=Filters.command(["rename"]) & Filters.chat(chats=Config.AUTH_CHANNEL)
filters=Filters.command(["rename"]) & Filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(rename_message_handler)

help_text_handler = MessageHandler(
help_message_f,
filters=Filters.command(["help"]) & Filters.chat(chats=Config.AUTH_CHANNEL)
filters=Filters.command(["help"]) & Filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(help_text_handler)
#
new_join_handler = MessageHandler(
new_join_f,
filters=~Filters.chat(chats=Config.AUTH_CHANNEL)
filters=~Filters.chat(chats=AUTH_CHANNEL)
)
app.add_handler(new_join_handler)
#
group_new_join_handler = MessageHandler(
help_message_f,
filters=Filters.chat(chats=Config.AUTH_CHANNEL) & Filters.new_chat_members
filters=Filters.chat(chats=AUTH_CHANNEL) & Filters.new_chat_members
)
app.add_handler(group_new_join_handler)
#
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
import aria2p
import asyncio
import os
from plugins.upload_to_tg import upload_to_tg
from tobrot.helper_funcs.upload_to_tg import upload_to_tg

# the secret configuration specific things
if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
from tobrot import (
ARIA_TWO_STARTED_PORT,
MAX_TIME_TO_WAIT_FOR_TORRENTS_TO_START,
AUTH_CHANNEL,
EDIT_SLEEP_TIME_OUT
)


async def aria_start():
Expand All @@ -37,12 +38,12 @@ async def aria_start():
aria2_daemon_start_cmd.append("--max-connection-per-server=10")
aria2_daemon_start_cmd.append("--min-split-size=10M")
aria2_daemon_start_cmd.append("--rpc-listen-all=false")
aria2_daemon_start_cmd.append(f"--rpc-listen-port={Config.ARIA_TWO_STARTED_PORT}")
aria2_daemon_start_cmd.append(f"--rpc-listen-port={ARIA_TWO_STARTED_PORT}")
aria2_daemon_start_cmd.append("--rpc-max-request-size=1024M")
aria2_daemon_start_cmd.append("--seed-ratio=0.0")
aria2_daemon_start_cmd.append("--seed-time=1")
aria2_daemon_start_cmd.append("--split=10")
aria2_daemon_start_cmd.append(f"--bt-stop-timeout={Config.MAX_TIME_TO_WAIT_FOR_TORRENTS_TO_START}")
aria2_daemon_start_cmd.append(f"--bt-stop-timeout={MAX_TIME_TO_WAIT_FOR_TORRENTS_TO_START}")
#
LOGGER.info(aria2_daemon_start_cmd)
#
Expand All @@ -57,7 +58,7 @@ async def aria_start():
aria2 = aria2p.API(
aria2p.Client(
host="http://localhost",
port=Config.ARIA_TWO_STARTED_PORT,
port=ARIA_TWO_STARTED_PORT,
secret=""
)
)
Expand Down Expand Up @@ -150,7 +151,7 @@ async def call_apropriate_function(
for key_f_res_se in final_response:
local_file_name = key_f_res_se
message_id = final_response[key_f_res_se]
channel_id = str(Config.AUTH_CHANNEL)[4:]
channel_id = str(AUTH_CHANNEL)[4:]
private_link = f"https://t.me/c/{channel_id}/{message_id}"
message_to_send += "👉 <a href='"
message_to_send += private_link
Expand Down Expand Up @@ -194,7 +195,7 @@ async def check_progress_for_dl(aria2, gid, event, previous_message):
msg = file.error_message
await event.edit(f"`{msg}`")
return False
await asyncio.sleep(Config.EDIT_SLEEP_TIME_OUT)
await asyncio.sleep(EDIT_SLEEP_TIME_OUT)
await check_progress_for_dl(aria2, gid, event, previous_message)
else:
await event.edit(f"File Downloaded Successfully: `{file.name}`")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import os

# the secret configuration specific things
if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
from tobrot import (
DOWNLOAD_LOCATION
)


async def request_download(url, file_name, r_user_id):
directory_path = os.path.join(Config.DOWNLOAD_LOCATION, str(r_user_id), str(time.time()))
directory_path = os.path.join(DOWNLOAD_LOCATION, str(r_user_id), str(time.time()))
# create download directory, if not exist
if not os.path.isdir(directory_path):
os.makedirs(directory_path)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

import os

# the secret configuration specific things
if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
from tobrot import (
REAL_DEBRID_KEY
)


import aiohttp
Expand All @@ -34,7 +32,7 @@ async def fetch(session, url, data):

async def extract_it(restricted_link, custom_file_name):
async with aiohttp.ClientSession() as session:
url_to_send = BASE_URL + "/unrestrict/link?auth_token=" + Config.REAL_DEBRID_KEY
url_to_send = BASE_URL + "/unrestrict/link?auth_token=" + REAL_DEBRID_KEY
to_send_data = {
"link": restricted_link
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser

# the secret configuration specific things
if bool(os.environ.get("WEBHOOK", False)):
from sample_config import Config
else:
from config import Config
from tobrot import (
MAX_TG_SPLIT_FILE_SIZE
)


async def split_large_files(input_file):
Expand All @@ -45,7 +43,7 @@ async def split_large_files(input_file):
LOGGER.info(total_duration)
total_file_size = os.path.getsize(input_file)
LOGGER.info(total_file_size)
minimum_duration = (total_duration / total_file_size) * (Config.MAX_TG_SPLIT_FILE_SIZE)
minimum_duration = (total_duration / total_file_size) * (MAX_TG_SPLIT_FILE_SIZE)
LOGGER.info(minimum_duration)
# END: proprietary
start_time = 0
Expand Down Expand Up @@ -79,7 +77,7 @@ async def split_large_files(input_file):
"split",
"-d",
"--suffix-length=5",
"--bytes=1572863000",
f"--bytes={MAX_TG_SPLIT_FILE_SIZE}",
input_file,
o_d_t
]
Expand Down
Loading

0 comments on commit cb35bdb

Please sign in to comment.