[yt-dlp]Minor fixes

Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
anasty17 2022-08-20 04:17:33 +03:00
parent 6f7fff2e8c
commit 4404d24ca6
6 changed files with 56 additions and 32 deletions

View File

@ -6,7 +6,7 @@ from qbittorrentapi import Client as qbClient
from aria2p import API as ariaAPI, Client as ariaClient
from os import remove as osremove, path as ospath, environ
from requests import get as rget
from json import loads as jsnloads
from json import loads as jsonloads
from subprocess import Popen, run as srun, check_output
from time import sleep, time
from threading import Thread, Lock
@ -438,7 +438,7 @@ try:
SEARCH_PLUGINS = getConfig('SEARCH_PLUGINS')
if len(SEARCH_PLUGINS) == 0:
raise KeyError
SEARCH_PLUGINS = jsnloads(SEARCH_PLUGINS)
SEARCH_PLUGINS = jsonloads(SEARCH_PLUGINS)
except:
SEARCH_PLUGINS = None

View File

@ -1,6 +1,6 @@
from os import remove as osremove, path as ospath, mkdir, walk, listdir, rmdir, makedirs
from sys import exit as sysexit
from json import loads as jsnloads
from json import loads as jsonloads
from shutil import rmtree
from PIL import Image
from magic import Magic
@ -198,7 +198,7 @@ def get_media_info(path):
LOGGER.error(f'{e}. Mostly file not found!')
return 0, None, None
fields = jsnloads(result).get('format')
fields = jsonloads(result).get('format')
if fields is None:
LOGGER.error(f"get_media_info: {result}")
return 0, None, None
@ -235,7 +235,7 @@ def get_media_streams(path):
LOGGER.error(f'{e}. Mostly file not found!')
return is_video, is_audio
fields = jsnloads(result).get('streams')
fields = jsonloads(result).get('streams')
if fields is None:
LOGGER.error(f"get_media_streams: {result}")
return is_video, is_audio

View File

@ -11,7 +11,7 @@ for original authorship. """
from requests import get as rget, head as rhead, post as rpost, Session as rsession
from re import findall as re_findall, sub as re_sub, match as re_match, search as re_search
from urllib.parse import urlparse, unquote
from json import loads as jsnloads
from json import loads as jsonloads
from lk21 import Bypass
from cfscrape import create_scraper
from bs4 import BeautifulSoup
@ -28,7 +28,7 @@ fmed_list = ['fembed.net', 'fembed.com', 'femax20.com', 'fcdn.stream', 'feurl.co
def direct_link_generator(link: str):
""" direct links generator """
if 'youtube.com' in link or 'youtu.be' in link:
raise DirectDownloadLinkException(f"ERROR: Use ytdl cmds for Youtube links")
raise DirectDownloadLinkException("ERROR: Use ytdl cmds for Youtube links")
elif 'yadi.sk' in link or 'disk.yandex.com' in link:
return yandex_disk(link)
elif 'mediafire.com' in link:
@ -327,7 +327,7 @@ def solidfiles(url: str) -> str:
}
pageSource = rget(url, headers = headers).text
mainOptions = str(re_search(r'viewerOptions\'\,\ (.*?)\)\;', pageSource).group(1))
return jsnloads(mainOptions)["downloadUrl"]
return jsonloads(mainOptions)["downloadUrl"]
def krakenfiles(page_link: str) -> str:
""" krakenfiles direct link generator

View File

@ -5,6 +5,7 @@ from yt_dlp import YoutubeDL, DownloadError
from threading import RLock
from time import time
from re import search as re_search
from json import loads as jsonloads
from bot import download_dict_lock, download_dict
from bot.helper.telegram_helper.message_utils import sendStatusMessage
@ -55,12 +56,13 @@ class YoutubeDLHelper:
self.opts = {'progress_hooks': [self.__onDownloadProgress],
'logger': MyLogger(self),
'usenetrc': True,
'prefer_ffmpeg': True,
'cookiefile': 'cookies.txt',
'allow_multiple_video_streams': True,
'allow_multiple_audio_streams': True,
'trim_file_name': 200,
'noprogress': True,
'allow_playlist_files': True,
'overwrites': True,
'ffmpeg_location': '/bin/opera'}
@property
@ -112,6 +114,8 @@ class YoutubeDLHelper:
self.__set_args(args)
if get_info:
self.opts['playlist_items'] = '0'
if link.startswith(('rtmp', 'mms', 'rstp')):
self.opts['external_downloader'] = 'ffmpeg'
with YoutubeDL(self.opts) as ydl:
try:
result = ydl.extract_info(link, download=False)
@ -194,11 +198,18 @@ class YoutubeDLHelper:
def __set_args(self, args):
args = args.split('|')
for arg in args:
xy = arg.split(':')
if xy[1].startswith('^'):
xy[1] = int(xy[1].split('^')[1])
elif xy[1].lower() == 'true':
xy[1] = True
elif xy[1].lower() == 'false':
xy[1] = False
self.opts[xy[0]] = xy[1]
xy = arg.split(':', 1)
karg = xy[0].strip()
varg = xy[1].strip()
if varg.startswith('^'):
varg = int(varg.split('^')[1])
elif varg.lower() == 'true':
varg = True
elif varg.lower() == 'false':
varg = False
elif varg.startswith('(') and varg.endswith(')'):
varg = varg.replace('(', '').replace(')', '')
varg = tuple(map(int, varg.split(',')))
elif varg.startswith('{') and varg.endswith('}'):
varg = jsonloads(varg)
self.opts[karg] = varg

View File

@ -44,10 +44,17 @@ class TgUploader:
if not file_.lower().endswith(tuple(EXTENSION_FILTER)):
up_path = ospath.join(dirpath, file_)
self.__total_files += 1
if ospath.getsize(up_path) == 0:
LOGGER.error(f"{up_path} size is zero, telegram don't upload zero size files")
self.__corrupted += 1
continue
try:
if ospath.getsize(up_path) == 0:
LOGGER.error(f"{up_path} size is zero, telegram don't upload zero size files")
self.__corrupted += 1
continue
except Exception as e:
if self.__is_cancelled:
return
else:
LOGGER.error(e)
continue
self.__upload_file(up_path, file_, dirpath)
if self.__is_cancelled:
return

View File

@ -71,15 +71,21 @@ def _ytdl(bot, message, isZip=False, isLeech=False):
tag = reply_to.from_user.mention_html(reply_to.from_user.first_name)
if not is_url(link):
help_msg = "<b>Send link along with command line:</b>"
help_msg += "\n<code>/command</code> {link} |newname pswd: mypassword [zip] args: x:y|x1:y1"
help_msg += "\n\n<b>By replying to link:</b>"
help_msg += "\n<code>/command</code> |newname pswd: mypassword [zip] args: x:y|x1:y1"
help_msg += "\n\n<b>Args Example:</b> args: playliststart:^10|matchtitle:S13|writesubtitles:true"
help_msg += "\n\n<b>NOTE:</b> Add `^` before integer, some values must be integer and some string."
help_msg += " Like playlist_items:10 works with string, so no need to add `^` before the number"
help_msg += " but playlistend works only with integer so you must add `^` before the number like example above."
help_msg += "\n\nCheck all arguments from this <a href='https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L178'>FILE</a>."
help_msg = """
<b>Send link along with command line:</b>
<code>/command</code> {link} |newname pswd: mypassword [zip] args: x:y|x1:y1
<b>By replying to link:</b>
<code>/command</code> |newname pswd: mypassword [zip] args: x:y|x1:y1
<b>Args Example:</b> args: playliststart:^10|matchtitle:S13|writesubtitles:true|live_from_start:true|postprocessor_args:{"ffmpeg": ["-threads", "4"]}|wait_for_video:(5, 100)
<b>Args Note:</b> Add `^` before integer, some values must be integer and some string.
Like playlist_items:10 works with string, so no need to add `^` before the number but playlistend works only with integer so you must add `^` before the number like example above.
You can add tuple and dict also. Use double quotes inside dict. Also you can add format manually, whatever what quality button you have pressed.
Check all arguments from this <a href='https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L178'>FILE</a>.
"""
return sendMessage(help_msg, bot, message)
listener = MirrorLeechListener(bot, message, isZip, isLeech=isLeech, pswd=pswd, tag=tag)
@ -94,9 +100,9 @@ def _ytdl(bot, message, isZip=False, isLeech=False):
return sendMessage(tag + " " + msg, bot, message)
if 'entries' in result:
for i in ['144', '240', '360', '480', '720', '1080', '1440', '2160']:
video_format = f"bv*[height<=?{i}][ext=mp4]"
video_format = f"bv*[height<=?{i}][ext=mp4]+ba/b[height<=?{i}]"
buttons.sbutton(f"{i}-mp4", f"qu {msg_id} {video_format} t")
video_format = f"bv*[height<=?{i}][ext=webm]"
video_format = f"bv*[height<=?{i}][ext=webm]+ba/b[height<=?{i}]"
buttons.sbutton(f"{i}-webm", f"qu {msg_id} {video_format} t")
buttons.sbutton("MP3", f"qu {msg_id} mp3 t")
buttons.sbutton("Best Videos", f"qu {msg_id} {best_video} t")