Skip to content

Commit

Permalink
Leech & Heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkhatri137 committed Oct 13, 2021
1 parent 6d4ecce commit 84e39a2
Show file tree
Hide file tree
Showing 15 changed files with 531 additions and 26 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Manually Deploy to Heroku

on: workflow_dispatch

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: akhileshns/[email protected]
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: ${{secrets.HEROKU_APP_NAME}}
heroku_email: ${{secrets.HEROKU_EMAIL}}
usedocker: true
docker_heroku_process_type: web
stack: "container"
region: "eu"
env:
HD_CONFIG_FILE_URL: ${{secrets.CONFIG_FILE_URL}}
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v4.0.1
hooks:
- id: check-ast
- id: check-merge-conflict
Expand All @@ -10,7 +10,7 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v2.14.0
rev: v2.26.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
# RK137_Mirror Bot
## Leech bot [branch](https://github.com/rahulkhatri137/mirrorbot137/tree/leech)

Important - Read these points first
- Original repo is https://github.com/lzzy12/python-aria-mirror-bot
- I have collected some cool features from various repositories and merged them in one.
- So, credits goes to original repo holder, not to me. I have just collected them.
- This (or any custom) repo is not supported in official bot support group.
- So if you have any issue then check first that issue is in official repo or not, You are only allowed to report that issue in bot support group if that issue is also present in official repo.

## Features Coming soon....
- ~Custom Filename~ Added
```
Only for url, telegram files and ytdl.
Not for mega links and magnet/torrents
```
- Rename Drive files

Let's have some chit chat here - [@Magneto_chit_chat](https://t.me/magneto_chit_chat)
Note :- it is not a Bot Support group. It's only for discussing rubbish things bcoz i want your help to learn coding .

Expand All @@ -36,7 +28,6 @@ Note :- it is not a Bot Support group. It's only for discussing rubbish things b
3. Fix SSL handsake error
```


# What is this repo about?
This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive.

Expand Down Expand Up @@ -69,6 +60,7 @@ This project is heavily inspired from @out386 's telegram bot which is written i
- Extract password protected files (It's not hack, you have to enter password for extracting. LOL)
- Speedtest
- Heroku dyno usage
- Leech

- For extracting password protected files, using custom filename and download from password protected index links see these examples :-
> https://telegra.ph/Magneto-Python-Aria---Custom-Filename-Examples-01-20
Expand All @@ -93,7 +85,10 @@ stats - Bot Usage Stats
help - Get Detailed Help
speedtest - Check Speed of the host (Not working currently!)
log - Bot Log [owner only]
usage - check heroku dyno usage [owner only]
usage - Check heroku dyno usage [owner only]
leech - Start leeching
tarleech - Leech as tar (zipped) file
unzipleech - Leech & Extract files
```

<details>
Expand Down Expand Up @@ -146,6 +141,7 @@ Fill up all of the fields. Meaning of each fields are discussed below:
- **MEGA_USERNAME**: Your email id you used to sign up on mega.nz for using premium accounts (Leave th)
- **MEGA_PASSWORD**: Your password for your mega.nz account
- **BLOCK_MEGA_LINKS**: (Optional field) If you want to remove mega.nz mirror support (bcoz it's too much buggy and unstable), set it to `True`.
- **AS_DOCUMENT**: Set to true to upload all files as document on telegram
- **SHORTENER**: (Optional field) if you want to use shortener in Gdrive and index link, fill shotener url here. Examples :-

> exe.io
Expand Down Expand Up @@ -196,14 +192,17 @@ sudo docker build . -t mirror-bot
```
sudo docker run mirror-bot
```
## Deploy on git actions [workflow](https://github.com/rahulkhatri137/mirrorbot-workflow)

## Deploying on Heroku
## Heroku might suspend the bot so use [workflow](https://github.com/rahulkhatri137/mirrorbot-workflow) deploy.
Fork this repo then upload **token.pickle** to your forks

**NOTE**: If you didn't upload **token.pickle**, uploading will not work.

<p><a href="https://heroku.com/deploy"> <img src="https://img.shields.io/badge/Deploy%20To%20Heroku-blueviolet?style=for-the-badge&logo=heroku" width="200""/></a></p>

- Deploying on Heroku with Github Workflow
<p><a href="https://telegra.ph/Heroku-Deployment-10-04"> <img src="https://img.shields.io/badge/Deploy%20Guide-blueviolet?style=for-the-badge&logo=heroku" width="170""/></a></p>

<details>
<summary># Deploying on Heroku using heroku-cli</summary>

Expand Down
5 changes: 5 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
"BUTTON_FIVE_URL": {
"description": "Fill your URL if you are using extra buttons.",
"required": false
},
"AS_DOCUMENT": {
"description": "Should all the upload to Telegram be forced as documents or not, set it True or False",
"value": "True",
"required": false
}
}
}
8 changes: 8 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def getConfig(name: str):
download_dict = {}
# Stores list of users and chats the bot is authorized to use in
AUTHORIZED_CHATS = set()
AS_DOC_USERS = set()
AS_MEDIA_USERS = set()
if os.path.exists('authorized_chats.txt'):
with open('authorized_chats.txt', 'r+') as f:
lines = f.readlines()
Expand Down Expand Up @@ -216,6 +218,12 @@ def getConfig(name: str):
except KeyError:
USE_SERVICE_ACCOUNTS = False

try:
AS_DOCUMENT = getConfig('AS_DOCUMENT')
AS_DOCUMENT = AS_DOCUMENT.lower() == 'true'
except KeyError:
AS_DOCUMENT = False

try:
BLOCK_MEGA_LINKS = getConfig('BLOCK_MEGA_LINKS')
if BLOCK_MEGA_LINKS.lower() == 'true':
Expand Down
40 changes: 37 additions & 3 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from bot.helper.telegram_helper.message_utils import LOGGER, editMessage, sendLogFile, sendMessage
from .helper.ext_utils.bot_utils import get_readable_file_size, get_readable_time
from .helper.telegram_helper.filters import CustomFilters
from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, delete, speedtest, usage # noqa
from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, delete, leech_settings, speedtest, usage # noqa

from pyrogram import idle
from bot import app
Expand Down Expand Up @@ -83,6 +83,16 @@ def bot_help(update, context):
/{BotCommands.TarMirrorCommand} [download_url][magnet_link]: start mirroring and upload the archived (.tar) version of the download
/{BotCommands.LeechCommand} [download_url][magnet_link]: Start mirroring the link to google drive
/{BotCommands.UnzipLeechCommand} [download_url][magnet_link] : starts mirroring and if downloaded file is any archive , extracts it to google drive
/{BotCommands.TarLeechCommand} [download_url][magnet_link]: start mirroring and upload the archived (.tar) version of the download
/{BotCommands.LeechSetCommand}: Leech Settings
/{BotCommands.SetThumbCommand}: Reply photo to set it as Thumbnail
/{BotCommands.WatchCommand} [youtube-dl supported link]: Mirror through youtube-dl. Click /{BotCommands.WatchCommand} for more help.
/{BotCommands.TarWatchCommand} [youtube-dl supported link]: Mirror through youtube-dl and tar before uploading
Expand All @@ -97,13 +107,37 @@ def bot_help(update, context):
/{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Can only be invoked by owner of the bot)
/{BotCommands.UnAuthorizeCommand}: UnAuthorize a chat or a user to use the bot (Can only be invoked by owner of the bot)
/{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports
/{BotCommands.SpeedCommand}: Check Internet Speed of the Host
/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner only).
/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner only)
'''
sendMessage(help_string, context.bot, update)

botcmds = [
(f"{BotCommands.HelpCommand}", "Get detailed help"),
(f"{BotCommands.MirrorCommand}", "Start mirroring"),
(f"{BotCommands.TarMirrorCommand}", "Start mirroring and upload as .tar"),
(f"{BotCommands.UnzipMirrorCommand}", "Extract files"),
(f"{BotCommands.CloneCommand}", "Copy file/folder from GDrive"),
(f"{BotCommands.deleteCommand}", "Delete file from GDrive [owner only]"),
(f"{BotCommands.WatchCommand}", "Mirror Youtube-dl support link"),
(f"{BotCommands.TarWatchCommand}", "Mirror Youtube playlist link as .tar"),
(f"{BotCommands.ZipWatchCommand}", "Mirror Youtube playlist link as .zip"),
(f"{BotCommands.CancelMirror}", "Cancel a task"),
(f"{BotCommands.CancelAllCommand}", "Cancel all tasks [owner only]"),
(f"{BotCommands.StatusCommand}", "Get mirror status"),
(f"{BotCommands.StatsCommand}", "Bot usage stats"),
(f"{BotCommands.PingCommand}", "Ping the bot"),
(f"{BotCommands.RestartCommand}", "Restart the bot [owner only]"),
(f"{BotCommands.LogCommand}", "Get the bot log [owner only]"),
(f"{BotCommands.LeechCommand}", "Start leeching"),
(f"{BotCommands.LeechSetCommand}", "Leech Settings"),
(f"{BotCommands.TarLeechCommand}", "Start leeching and upload as .tar"),
(f"{BotCommands.UnZipLeechCommand}", "Start leeching and upload as .zip"),
]

def main():
fs_utils.start_cleanup()
Expand All @@ -113,7 +147,7 @@ def main():
chat_id, msg_id = map(int, f)
bot.edit_message_text("Restarted successfully!", chat_id, msg_id)
os.remove(".restartmsg")

bot.set_my_commands(botcmds)
start_handler = CommandHandler(BotCommands.StartCommand, start,
filters=CustomFilters.authorized_chat | CustomFilters.authorized_user, run_async=True)
ping_handler = CommandHandler(BotCommands.PingCommand, ping,
Expand Down
2 changes: 2 additions & 0 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def get_readable_time(seconds: int) -> str:
def is_mega_link(url: str):
return "mega.nz" in url or "mega.co.nz" in url

def is_gdrive_link(url: str):
return "drive.google.com" in url

def is_url(url: str):
url = re.findall(URL_REGEX, url)
Expand Down
22 changes: 22 additions & 0 deletions bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import magic
import tarfile
from .exceptions import NotSupportedExtractionArchive
from PIL import Image
from hachoir.parser import createParser
from hachoir.metadata import extractMetadata


def clean_download(path: str):
Expand Down Expand Up @@ -144,3 +147,22 @@ def get_mime_type(file_path):
mime_type = mime.from_file(file_path)
mime_type = mime_type if mime_type else "text/plain"
return mime_type

def take_ss(video_file):
des_dir = 'Thumbnails'
if not os.path.exists(des_dir):
os.mkdir(des_dir)
des_dir = os.path.join(des_dir, f"{time.time()}.jpg")
metadata = extractMetadata(createParser(video_file))
duration = metadata.get('duration').seconds if metadata.has("duration") else 5
duration = int(duration) / 2
subprocess.run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-ss", str(duration),
"-i", video_file, "-vframes", "1", des_dir])
if not os.path.lexists(des_dir):
return None

Image.open(des_dir).convert("RGB").save(des_dir)
img = Image.open(des_dir)
img.resize((480, 320))
img.save(des_dir, "JPEG")
return des_dir
61 changes: 61 additions & 0 deletions bot/helper/mirror_utils/status_utils/tg_upload_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from .status import Status
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
from bot import DOWNLOAD_DIR


class TgUploadStatus(Status):
def __init__(self, obj, size, gid, listener):
self.obj = obj
self.__size = size
self.uid = listener.uid
self.message = listener.message
self.__gid = gid

def path(self):
return f"{DOWNLOAD_DIR}{self.uid}"

def processed_bytes(self):
return self.obj.uploaded_bytes

def size_raw(self):
return self.__size

def size(self):
return get_readable_file_size(self.__size)

def status(self):
return MirrorStatus.STATUS_UPLOADING

def name(self):
return self.obj.name

def progress_raw(self):
try:
return self.obj.uploaded_bytes / self.__size * 100
except ZeroDivisionError:
return 0

def progress(self):
return f'{round(self.progress_raw(), 2)}%'

def speed_raw(self):
"""
:return: Upload speed in Bytes/Seconds
"""
return self.obj.speed()

def speed(self):
return f'{get_readable_file_size(self.speed_raw())}/s'

def eta(self):
try:
seconds = (self.__size - self.obj.uploaded_bytes) / self.speed_raw()
return f'{get_readable_time(seconds)}'
except ZeroDivisionError:
return '-'

def gid(self) -> str:
return self.__gid

def download(self):
return self.obj
Loading

0 comments on commit 84e39a2

Please sign in to comment.