Skip to content

Commit

Permalink
mirror: Premium, Multi links support
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkhatri137 committed Aug 31, 2022
1 parent b9c986b commit fba6c0b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 8 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ 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 password protected files, using custom filename and download
- Update bot at startup and with restart command using `UPSTREAM_REPO`
- Log Chat for mirror messages
- Telegram Premium 4GB upload
- Custom Name for all links except torrents. Must add extension except stream/yt links.

## Multi Search IDs
To use list from multi TD/folder. Run driveid.py in your terminal and follow it. It will generate **drive_folder** file or u can simply create `drive_folder` file in working directory and fill it, check below format:
Expand Down Expand Up @@ -155,7 +158,9 @@ Fill up rest of the fields. Meaning of each field is discussed below:
- `CLONE_LIMIT`: To limit the size of Google Drive folder/file which you can clone. Don't add unit. Default unit is `GB`.
- `VIEW_LINK`: View Link button to open file Index Link in browser instead of direct download link, you can figure out if it's compatible with your Index code or not, open any video from you Index and check if its URL ends with `?a=view`, if yes make it `True`, compatible with [BhadooIndex](https://gitlab.com/ParveenBhadooOfficial/Google-Drive-Index) Code. Default is `False`. `Bool`
- `IGNORE_PENDING_REQUESTS`: Ignore pending requests after restart. Default is `False`. `Bool`
- `TG_SPLIT_SIZE`: Size of split in bytes. Default is `2GB`.
- `SESSION_STRING`: To download/upload from your telegram account. To generate session string use this command `python3 generate_string_session.py` after mounting repo folder for sure.
- **NOTE**: You can't use bot with private message, use it with group or channel.
- `TG_SPLIT_SIZE`: Size of split in bytes. Default is `2GB`. Default is `4GB` if your account is premium.
- `AS_DOCUMENT`: Default type of Telegram file upload. Default is `False` mean as media. `Bool`
- `CUSTOM_FILENAME`: Add custom word to leeched file name.
- `SHORTENER_API`: Fill your Shortener API key.
Expand All @@ -164,6 +169,7 @@ Fill up rest of the fields. Meaning of each field is discussed below:
>exe.io gplinks.in shrinkme.io urlshortx.com shortzon.com
- `CRYPT`: Cookie for gdtot google drive link generator.
- `RECURSIVE_SEARCH`: T/F And Fill drive_folder File Using Driveid.py Script.
- `LOGS_CHATS`: Chat ids of channels/groups where you want to store Mirror logs, NOTE Add bot in Mirror logs channel/group as Admin.
- `BUTTON_THREE_NAME`:
- `BUTTON_THREE_URL`:
Expand Down
22 changes: 18 additions & 4 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,18 @@ def aria2c_init():
conn.close()

LOGGER.info("Generating USER_SESSION_STRING")
app = Client(
try:
PREMIUM_USER = False
SESSION_STRING = getConfig('SESSION_STRING')
if len(SESSION_STRING) == 0:
raise KeyError
app = Client(
":memory:", api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, session_string=SESSION_STRING
)
with app:
PREMIUM_USER = app.get_me().is_premium
except:
app = Client(
":memory:", api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN
)

Expand Down Expand Up @@ -365,12 +376,15 @@ def aria2c_init():

try:
TG_SPLIT_SIZE = getConfig('TG_SPLIT_SIZE')
if len(TG_SPLIT_SIZE) == 0 or int(TG_SPLIT_SIZE) > 2097152000:
if len(TG_SPLIT_SIZE) == 0 or (not PREMIUM_USER and TG_SPLIT_SIZE > 2097152000) or TG_SPLIT_SIZE > 4194304000:
raise KeyError
else:
TG_SPLIT_SIZE = int(TG_SPLIT_SIZE)
except KeyError:
TG_SPLIT_SIZE = 2097152000
except:
if PREMIUM_USER:
TG_SPLIT_SIZE = 4194304000
else:
TG_SPLIT_SIZE = 2097152000
try:
AS_DOCUMENT = getConfig('AS_DOCUMENT')
AS_DOCUMENT = AS_DOCUMENT.lower() == 'true'
Expand Down
6 changes: 3 additions & 3 deletions bot/helper/mirror_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,11 +750,11 @@ def download(self, link):
meta = self.getFileMetadata(file_id)
path = f"{DOWNLOAD_DIR}{self.__listener.uid}/"
if meta.get("mimeType") == self.__G_DRIVE_DIR_MIME_TYPE:
self.download_folder(file_id, path, meta.get("name"))
self.download_folder(file_id, path, self.name)
else:
os.makedirs(path)
self.download_file(
file_id, path, meta.get("name"), meta.get("mimeType")
file_id, path, self.name, meta.get("mimeType")
)
except Exception as err:
if isinstance(err, RetryError):
Expand Down Expand Up @@ -1135,4 +1135,4 @@ def count(self, link):
else:
msg = f"Error.\n{err}"
return msg
return msg
return msg
13 changes: 13 additions & 0 deletions bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ def _mirror(bot, update,isTar=False, isZip=False, extract=False, isLeech=False,
if res != "":
sendMessage(res, bot, update)
return
try:
name = name_args[1]
name = name.strip()
except IndexError:
name = name
LOGGER.info(f"Download Name : {name}")
drive = gdriveTools.GoogleDriveHelper(name, listener)
gid = "".join(
Expand Down Expand Up @@ -506,6 +511,14 @@ def _mirror(bot, update,isTar=False, isZip=False, extract=False, isLeech=False,
Interval.append(
setInterval(DOWNLOAD_STATUS_UPDATE_INTERVAL, update_all_messages)
)
if multi > 1:
time.sleep(3)
update.message.message_id = update.message.reply_to_message.message_id + 1
update.message = sendMessage(message_args[0], bot, update)
multi -= 1
time.sleep(3)
threading.Thread(target=_mirror, args=(bot, update, isTar, isZip, extract, isLeech, pswd, multi)).start()
return

def mirror(update, context):
_mirror(context.bot, update)
Expand Down
1 change: 1 addition & 0 deletions config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ USE_SERVICE_ACCOUNTS = ""
# Optional config
ACCOUNTS_ZIP_URL = "" #Enter Direct Links TO Import Service Accounts Directly From Urls Instead Of Adding Files To Repo.( Archive the accounts folder to a zip file.)
TOKEN_PICKLE_URL = "" #Enter Direct Links TO Import Credentials Directly From Urls Instead Of Adding Files To Repo.
SESSION_STRING = ""
AUTHORIZED_CHATS = "" #Separated by space
SUDO_USERS = "" #Separated by space
LOGS_CHATS = "" #Separated by space
Expand Down
7 changes: 7 additions & 0 deletions generate_string_session.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pyrogram import Client

print('Required pyrogram V2 or greater.')
API_KEY = int(input("Enter API KEY: "))
API_HASH = input("Enter API HASH: ")
with Client(name='USS', api_id=API_KEY, api_hash=API_HASH, in_memory=True) as app:
print(app.export_session_string())

0 comments on commit fba6c0b

Please sign in to comment.