Add support for tg premium users

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
(cherry picked from commit 7e0a2721d4)
This commit is contained in:
anasty17 2022-07-18 18:43:33 +03:00
parent a5ee291a63
commit ce1bc510e3
3 changed files with 30 additions and 12 deletions

View File

@ -126,7 +126,8 @@ Fill up rest of the fields. Meaning of each field is discussed below:
- `UPSTREAM_BRANCH`: Upstream branch for update. Default is `master`. `Str`
### Leech
- `TG_SPLIT_SIZE`: Size of split in bytes. Default is `2GB`. `Str`
- `USER_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. `Str`. **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. `Str`
- `AS_DOCUMENT`: Default type of Telegram file upload. Default is `False` mean as media. `Bool`
- `EQUAL_SPLITS`: Split files larger than **TG_SPLIT_SIZE** into equal parts size (Not working with zip cmd). Default is `False`. `Bool`
- `CUSTOM_FILENAME`: Add custom word to leeched file name. `Str`
@ -142,8 +143,8 @@ Fill up rest of the fields. Meaning of each field is discussed below:
- `RSS_DELAY`: Time in seconds for rss refresh interval. Recommended `900` second at least. Default is `900` in sec. `Str`
- `RSS_COMMAND`: Choose command for the desired action. `Str`
- `RSS_CHAT_ID`: Chat ID where rss links will be sent. If using channel then add channel id. `Str`
- `USER_SESSION_STRING`: To send rss links from your telegram account. Instead of adding bot to channel then linking the channel to group to get rss link since bot will not read command from itself or other bot. To generate session string use this command `python3 generate_string_session.py` after mounting repo folder for sure. `Str`
- **RSS NOTE**: `DATABASE_URL` and `RSS_CHAT_ID` is required, otherwise all rss commands will not work. You must use bot in group. You can add the bot to a channel and link this channel to group so messages sent by bot to channel will be forwarded to group without using `USER_STRING_SESSION`.
- `RSS_USER_SESSION_STRING`: To send rss links from your telegram account. Instead of adding bot to channel then linking the channel to group to get rss link since bot will not read command from itself or other bot. To generate session string use this command `python3 generate_string_session.py` after mounting repo folder for sure. `Str`. **NOTE**: Don't use same session string as `USER_SESSION_STRING`.
- **RSS NOTE**: `DATABASE_URL` and `RSS_CHAT_ID` is required, otherwise all rss commands will not work. You must use bot in group. You can add the bot to a channel and link this channel to group so messages sent by bot to channel will be forwarded to group without using `RSS_USER_STRING_SESSION`.
### Private Files
- `ACCOUNTS_ZIP_URL`: Only if you want to load your Service Account externally from an Index Link or by any direct download link NOT webpage link. Archive the accounts folder to ZIP file. Fill this with the direct download link of zip file. `Str`. If index need authentication so add direct download as shown below:

View File

@ -146,14 +146,23 @@ except:
log_error("One or more env variables missing! Exiting now")
exit(1)
LOGGER.info("Generating BOT_SESSION_STRING")
app = Client(name='pyrogram', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN, parse_mode=enums.ParseMode.HTML, no_updates=True)
LOGGER.info("Generating SESSION_STRING")
try:
IS_PREMIUM_USER = False
USER_SESSION_STRING = getConfig('USER_SESSION_STRING')
if len(USER_SESSION_STRING) == 0:
raise KeyError
rss_session = Client(name='rss_session', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, session_string=USER_SESSION_STRING, parse_mode=enums.ParseMode.HTML, no_updates=True)
app = Client(name='pyrogram', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, session_string=USER_SESSION_STRING, parse_mode=enums.ParseMode.HTML, no_updates=True)
with app:
IS_PREMIUM_USER = app.get_me().is_premium
except:
app = Client(name='pyrogram', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN, parse_mode=enums.ParseMode.HTML, no_updates=True)
try:
RSS_USER_SESSION_STRING = getConfig('RSS_USER_SESSION_STRING')
if len(RSS_USER_SESSION_STRING) == 0:
raise KeyError
rss_session = Client(name='rss_session', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, session_string=RSS_USER_SESSION_STRING, parse_mode=enums.ParseMode.HTML, no_updates=True)
except:
rss_session = None
@ -197,11 +206,14 @@ except:
DB_URI = None
try:
TG_SPLIT_SIZE = getConfig('TG_SPLIT_SIZE')
if len(TG_SPLIT_SIZE) == 0 or int(TG_SPLIT_SIZE) > 2097151000:
if len(TG_SPLIT_SIZE) == 0 or (not IS_PREMIUM_USER and TG_SPLIT_SIZE > 2097152000) or TG_SPLIT_SIZE > 4194304000:
raise KeyError
TG_SPLIT_SIZE = int(TG_SPLIT_SIZE)
except:
TG_SPLIT_SIZE = 2097151000
if IS_PREMIUM_USER:
TG_SPLIT_SIZE = 2097152000
else:
TG_SPLIT_SIZE = 4194304000
try:
STATUS_LIMIT = getConfig('STATUS_LIMIT')
if len(STATUS_LIMIT) == 0:

View File

@ -10,7 +10,12 @@ from math import ceil
from re import split as re_split, I
from .exceptions import NotSupportedExtractionArchive
from bot import aria2, app, LOGGER, DOWNLOAD_DIR, get_client, TG_SPLIT_SIZE, EQUAL_SPLITS
from bot import aria2, app, LOGGER, DOWNLOAD_DIR, get_client, TG_SPLIT_SIZE, EQUAL_SPLITS, IS_PREMIUM_USER
if IS_PREMIUM_USER:
MAX_SPLIT_SIZE = 4194304000
else:
MAX_SPLIT_SIZE = 2097152000
VIDEO_SUFFIXES = ("M4V", "MP4", "MOV", "FLV", "WMV", "3GP", "MPG", "WEBM", "MKV", "AVI")
@ -127,8 +132,8 @@ def split_file(path, size, file_, dirpath, split_size, listener, start_time=0, i
if listener.split_proc.returncode == -9:
return False
out_size = get_path_size(out_path)
if out_size > 2097152000:
dif = out_size - 2097152000
if out_size > MAX_SPLIT_SIZE:
dif = out_size - MAX_SPLIT_SIZE
split_size = split_size - dif + 5000000
osremove(out_path)
return split_file(path, size, file_, dirpath, split_size, listener, start_time, i, True)