Skip to content

Commit

Permalink
Add default yt-dlp quality
Browse files Browse the repository at this point in the history
- Add custom yt-dlp quality for each user
- /setthumb cmd removed. Now it's controled directly from /usetting cmd
- Bug fix

Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Nov 7, 2022
1 parent 89e6763 commit f05f36c
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 226 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ In each single file there is a major change from base code, it's almost totaly d
- Switch from youtube-dl to yt-dlp and fix all conflicts
- Yt-dlp quality buttons
- Ability to use specific yt-dlp option for each task
- Custom default video quality for each user
- Fix download progress
### Database
- Mongo Database support
Expand Down Expand Up @@ -167,6 +168,7 @@ Fill up rest of the fields. Meaning of each field is discussed below. **NOTE**:
- `EXTENSION_FILTER`: File extensions that won't upload/clone. Separate them by space. `Str`
- `INCOMPLETE_TASK_NOTIFIER`: Get incomplete task messages after restart. Require database and superGroup. Default is `False`. `Bool`
- `UPTOBOX_TOKEN`: Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account). `str`
- `YT_DLP_QUALITY`: Default yt-dlp quality. Check all possible formats [HERE](https://github.com/yt-dlp/yt-dlp#format-selection-examples).

### Update
- `UPSTREAM_REPO`: Your github repository link, if your repo is private add `https://username:{githubtoken}@github.com/{username}/{reponame}` format. Get token from [Github settings](https://github.com/settings/tokens). So you can update your bot from filled repository on each restart. `Str`.
Expand Down
93 changes: 47 additions & 46 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@
else:
AUTO_DELETE_MESSAGE_DURATION = int(AUTO_DELETE_MESSAGE_DURATION)

YT_DLP_QUALITY = environ.get('YT_DLP_QUALITY', '')
if len(YT_DLP_QUALITY) == 0:
YT_DLP_QUALITY = ''

SEARCH_LIMIT = environ.get('SEARCH_LIMIT', '')
SEARCH_LIMIT = 0 if len(SEARCH_LIMIT) == 0 else int(SEARCH_LIMIT)

Expand Down Expand Up @@ -280,55 +284,52 @@
if len(UPSTREAM_BRANCH) == 0:
UPSTREAM_BRANCH = 'master'

if not config_dict:
config_dict = {'AS_DOCUMENT': AS_DOCUMENT,
'AUTHORIZED_CHATS': AUTHORIZED_CHATS,
'AUTO_DELETE_MESSAGE_DURATION': AUTO_DELETE_MESSAGE_DURATION,
'BASE_URL': BASE_URL,
'CMD_PERFIX': CMD_PERFIX,
'DUMP_CHAT': DUMP_CHAT,
'EQUAL_SPLITS': EQUAL_SPLITS,
'EXTENSION_FILTER': EXTENSION_FILTER,
'GDRIVE_ID': GDRIVE_ID,
'IGNORE_PENDING_REQUESTS': IGNORE_PENDING_REQUESTS,
'INCOMPLETE_TASK_NOTIFIER': INCOMPLETE_TASK_NOTIFIER,
'INDEX_URL': INDEX_URL,
'IS_TEAM_DRIVE': IS_TEAM_DRIVE,
'LEECH_FILENAME_PERFIX': LEECH_FILENAME_PERFIX,
'LEECH_SPLIT_SIZE': LEECH_SPLIT_SIZE,
'MEGA_API_KEY': MEGA_API_KEY,
'MEGA_EMAIL_ID': MEGA_EMAIL_ID,
'MEGA_PASSWORD': MEGA_PASSWORD,
'RSS_USER_SESSION_STRING': RSS_USER_SESSION_STRING,
'RSS_CHAT_ID': RSS_CHAT_ID,
'RSS_COMMAND': RSS_COMMAND,
'RSS_DELAY': RSS_DELAY,
'SEARCH_API_LINK': SEARCH_API_LINK,
'SEARCH_LIMIT': SEARCH_LIMIT,
'SEARCH_PLUGINS': SEARCH_PLUGINS,
'SERVER_PORT': SERVER_PORT,
'STATUS_LIMIT': STATUS_LIMIT,
'STATUS_UPDATE_INTERVAL': STATUS_UPDATE_INTERVAL,
'STOP_DUPLICATE': STOP_DUPLICATE,
'SUDO_USERS': SUDO_USERS,
'TELEGRAM_API': TELEGRAM_API,
'TELEGRAM_HASH': TELEGRAM_HASH,
'TORRENT_TIMEOUT': TORRENT_TIMEOUT,
'UPSTREAM_REPO': UPSTREAM_REPO,
'UPSTREAM_BRANCH': UPSTREAM_BRANCH,
'UPTOBOX_TOKEN': UPTOBOX_TOKEN,
'USER_SESSION_STRING': USER_SESSION_STRING,
'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS,
'VIEW_LINK': VIEW_LINK,
'WEB_PINCODE': WEB_PINCODE}
config_dict = {'AS_DOCUMENT': AS_DOCUMENT,
'AUTHORIZED_CHATS': AUTHORIZED_CHATS,
'AUTO_DELETE_MESSAGE_DURATION': AUTO_DELETE_MESSAGE_DURATION,
'BASE_URL': BASE_URL,
'CMD_PERFIX': CMD_PERFIX,
'DUMP_CHAT': DUMP_CHAT,
'EQUAL_SPLITS': EQUAL_SPLITS,
'EXTENSION_FILTER': EXTENSION_FILTER,
'GDRIVE_ID': GDRIVE_ID,
'IGNORE_PENDING_REQUESTS': IGNORE_PENDING_REQUESTS,
'INCOMPLETE_TASK_NOTIFIER': INCOMPLETE_TASK_NOTIFIER,
'INDEX_URL': INDEX_URL,
'IS_TEAM_DRIVE': IS_TEAM_DRIVE,
'LEECH_FILENAME_PERFIX': LEECH_FILENAME_PERFIX,
'LEECH_SPLIT_SIZE': LEECH_SPLIT_SIZE,
'MEGA_API_KEY': MEGA_API_KEY,
'MEGA_EMAIL_ID': MEGA_EMAIL_ID,
'MEGA_PASSWORD': MEGA_PASSWORD,
'RSS_USER_SESSION_STRING': RSS_USER_SESSION_STRING,
'RSS_CHAT_ID': RSS_CHAT_ID,
'RSS_COMMAND': RSS_COMMAND,
'RSS_DELAY': RSS_DELAY,
'SEARCH_API_LINK': SEARCH_API_LINK,
'SEARCH_LIMIT': SEARCH_LIMIT,
'SEARCH_PLUGINS': SEARCH_PLUGINS,
'SERVER_PORT': SERVER_PORT,
'STATUS_LIMIT': STATUS_LIMIT,
'STATUS_UPDATE_INTERVAL': STATUS_UPDATE_INTERVAL,
'STOP_DUPLICATE': STOP_DUPLICATE,
'SUDO_USERS': SUDO_USERS,
'TELEGRAM_API': TELEGRAM_API,
'TELEGRAM_HASH': TELEGRAM_HASH,
'TORRENT_TIMEOUT': TORRENT_TIMEOUT,
'UPSTREAM_REPO': UPSTREAM_REPO,
'UPSTREAM_BRANCH': UPSTREAM_BRANCH,
'UPTOBOX_TOKEN': UPTOBOX_TOKEN,
'USER_SESSION_STRING': USER_SESSION_STRING,
'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS,
'VIEW_LINK': VIEW_LINK,
'WEB_PINCODE': WEB_PINCODE,
'YT_DLP_QUALITY': YT_DLP_QUALITY}

if GDRIVE_ID:
DRIVES_NAMES.append("Main")
DRIVES_IDS.append(GDRIVE_ID)
if INDEX_URL:
INDEX_URLS.append(INDEX_URL)
else:
INDEX_URLS.append(None)
INDEX_URLS.append(INDEX_URL)

if ospath.exists('list_drives.txt'):
with open('list_drives.txt', 'r+') as f:
Expand All @@ -340,7 +341,7 @@
if len(temp) > 2:
INDEX_URLS.append(temp[2])
else:
INDEX_URLS.append(None)
INDEX_URLS.append('')

if BASE_URL:
Popen(f"gunicorn web.wserver:app --bind 0.0.0.0:{SERVER_PORT}", shell=True)
Expand Down
1 change: 0 additions & 1 deletion bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def log(update, context):
/{BotCommands.CountCommand} [drive_url]: Count file/folder of Google Drive.
/{BotCommands.DeleteCommand} [drive_url]: Delete file/folder from Google Drive (Only Owner & Sudo).
/{BotCommands.UserSetCommand} [query]: Users settings.
/{BotCommands.SetThumbCommand}: Reply photo to set it as Thumbnail.
/{BotCommands.BtSelectCommand}: Select files from torrents by gid or reply.
/{BotCommands.RssListCommand[0]} or /{BotCommands.RssListCommand[1]}: List all subscribed rss feed info (Only Owner & Sudo).
/{BotCommands.RssGetCommand[0]} or /{BotCommands.RssGetCommand[1]}: Force fetch last N links (Only Owner & Sudo).
Expand Down
5 changes: 2 additions & 3 deletions bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ def __connect(self):
def db_load(self):
if self.__err:
return
# Save bot settings if not exists
if self.__db.settings.config.find_one({'_id': bot_id}) is None:
self.__db.settings.config.update_one({'_id': bot_id}, {'$set': config_dict}, upsert=True)
# Save bot settings
self.__db.settings.config.update_one({'_id': bot_id}, {'$set': config_dict}, upsert=True)
# Save Aria2c options
if self.__db.settings.aria2c.find_one({'_id': bot_id}) is None:
self.__db.settings.aria2c.update_one({'_id': bot_id}, {'$set': aria2_options}, upsert=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __onDownloadError(self, error):
self.__listener.onDownloadError(error)

def extractMetaData(self, link, name, args, get_info=False):
if args is not None:
if args:
self.__set_args(args)
if get_info:
self.opts['playlist_items'] = '0'
Expand Down Expand Up @@ -225,6 +225,8 @@ def __set_args(self, args):
for arg in args:
xy = arg.split(':', 1)
karg = xy[0].strip()
if karg == 'format':
continue
varg = xy[1].strip()
if varg.startswith('^'):
varg = int(varg.split('^')[1])
Expand Down
1 change: 0 additions & 1 deletion bot/helper/telegram_helper/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def __init__(self):
self.ClearLocalsCommand = f'clearlocals{CMD_PERFIX}'
self.BotSetCommand = f'bsetting{CMD_PERFIX}'
self.UserSetCommand = f'usetting{CMD_PERFIX}'
self.SetThumbCommand = f'setthumb{CMD_PERFIX}'
self.BtSelectCommand = f'btsel{CMD_PERFIX}'
self.RssListCommand = (f'rsslist{CMD_PERFIX}', f'rl{CMD_PERFIX}')
self.RssGetCommand = (f'rssget{CMD_PERFIX}', f'rg{CMD_PERFIX}')
Expand Down
20 changes: 8 additions & 12 deletions bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,9 @@ def edit_variable(update, context, omsg, key):
value = int(value)
if len(download_dict) != 0:
with status_reply_dict_lock:
try:
if Interval:
Interval[0].cancel()
Interval.clear()
except:
pass
finally:
if Interval:
Interval[0].cancel()
Interval.clear()
Interval.append(setInterval(value, update_all_messages))
elif key == 'TORRENT_TIMEOUT':
value = int(value)
Expand Down Expand Up @@ -503,9 +499,9 @@ def edit_bot_settings(update, context):
srun(["pkill", "-9", "-f", "gunicorn"])
Popen("gunicorn web.wserver:app --bind 0.0.0.0:80", shell=True)
config_dict[data[2]] = value
update_buttons(message, 'var')
if DB_URI:
DbManger().update_config({data[2]: value})
update_buttons(message, 'var')
elif data[1] == 'resetaria':
aria2_defaults = aria2.client.get_global_option()
if aria2_defaults[data[2]] == aria2_options[data[2]]:
Expand All @@ -525,8 +521,8 @@ def edit_bot_settings(update, context):
handler_dict[message.chat.id] = True
update_buttons(message, 'private')
partial_fnc = partial(upload_file, omsg=message)
file_handler = MessageHandler(filters=Filters.document & Filters.chat(message.chat.id) &
(CustomFilters.owner_filter | CustomFilters.sudo_user), callback=partial_fnc, run_async=True)
file_handler = MessageHandler(filters=Filters.document & Filters.chat(message.chat.id) & Filters.user(user_id),
callback=partial_fnc, run_async=True)
dispatcher.add_handler(file_handler)
while handler_dict[message.chat.id]:
if time() - start_time > 60:
Expand All @@ -546,8 +542,8 @@ def edit_bot_settings(update, context):
handler_dict[message.chat.id] = True
update_buttons(message, data[2], data[1])
partial_fnc = partial(edit_variable, omsg=message, key=data[2])
value_handler = MessageHandler(filters=Filters.text & Filters.chat(message.chat.id) &
(CustomFilters.owner_filter | CustomFilters.sudo_user), callback=partial_fnc, run_async=True)
value_handler = MessageHandler(filters=Filters.text & Filters.chat(message.chat.id) & Filters.user(user_id),
callback=partial_fnc, run_async=True)
dispatcher.add_handler(value_handler)
while handler_dict[message.chat.id]:
if time() - start_time > 60:
Expand Down
34 changes: 15 additions & 19 deletions bot/modules/mirror_leech.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
def _mirror_leech(bot, message, isZip=False, extract=False, isQbit=False, isLeech=False):
mesg = message.text.split('\n')
message_args = mesg[0].split(maxsplit=1)
name_args = mesg[0].split('|', maxsplit=1)
index = 1
ratio = None
seed_time = None
select = False
seed = False
multi = 0
link = ''

if len(message_args) > 1:
args = mesg[0].split(maxsplit=3)
Expand Down Expand Up @@ -58,34 +58,28 @@ def _mirror_leech(bot, message, isZip=False, extract=False, isQbit=False, isLeec
link = message_args[index].strip()
if link.startswith(("|", "pswd:")):
link = ''
else:
link = ''
else:
link = ''
else:
link = ''

if len(name_args) > 1:
name = name_args[1]
name = name.split(' pswd:')[0]
name = name.strip()
name = mesg[0].split('|', maxsplit=1)
if len(name) > 1:
if 'pswd:' in name[0]:
name = ''
else:
name = name[1].split('pswd:')[0].strip()
else:
name = ''

link = re_split(r"pswd:|\|", link)[0]
link = link.strip()

pswd_arg = mesg[0].split(' pswd: ')
if len(pswd_arg) > 1:
pswd = pswd_arg[1]
else:
pswd = None
pswd = mesg[0].split(' pswd: ')
pswd = pswd[1] if len(pswd) > 1 else None

if message.from_user.username:
tag = f"@{message.from_user.username}"
else:
tag = message.from_user.mention_html(message.from_user.first_name)

if link != '':
link = re_split(r"pswd:|\|", link)[0]
link = link.strip()

reply_to = message.reply_to_message
if reply_to is not None:
file_ = reply_to.document or reply_to.video or reply_to.audio or reply_to.photo or None
Expand Down Expand Up @@ -131,10 +125,12 @@ def _mirror_leech(bot, message, isZip=False, extract=False, isQbit=False, isLeec
<b>Bittorrent selection:</b>
<code>/cmd</code> <b>s</b> link or by replying to file/link
This perfix should be always before |newname or pswd:
<b>Bittorrent seed</b>:
<code>/cmd</code> <b>d</b> link or by replying to file/link
To specify ratio and seed time add d:ratio:time. Ex: d:0.7:10 (ratio and time) or d:0.7 (only ratio) or d::10 (only time) where time in minutes.
Those perfixes should be always before |newname or pswd:
<b>Multi links only by replying to first link/file:</b>
<code>/cmd</code> 10(number of links/files)
Expand Down
10 changes: 3 additions & 7 deletions bot/modules/mirror_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ def mirror_status(update, context):
sendStatusMessage(update.message, context.bot)
deleteMessage(context.bot, update.message)
with status_reply_dict_lock:
try:
if Interval:
Interval[0].cancel()
Interval.clear()
except:
pass
finally:
if Interval:
Interval[0].cancel()
Interval.clear()
Interval.append(setInterval(config_dict['STATUS_UPDATE_INTERVAL'], update_all_messages))

@new_thread
Expand Down
Loading

0 comments on commit f05f36c

Please sign in to comment.