Update yt-dlp, add --file argument

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2024-10-27 01:02:33 +07:00
parent 7afd00430e
commit 9ea98cd234
5 changed files with 123 additions and 87 deletions

View File

@@ -13,7 +13,7 @@ from tqdm import tqdm
def ascii_banner(text): def ascii_banner(text):
print('\n\n########################################################\n\n\n') print('\n########################################################\n\n\n')
ascii_banner = pyfiglet.figlet_format(text) ascii_banner = pyfiglet.figlet_format(text)
print(ascii_banner) print(ascii_banner)
################################ ################################
@@ -27,11 +27,11 @@ def ph_config_dl_dir(dir):
global download_dir global download_dir
if (dir != None): if (dir != None):
download_dir = dir download_dir = dir
print("Output directory: " + download_dir + "\model\\") print("Output directory: " + download_dir + "\\model\\")
if (os.path.exists(download_dir) != True): if (os.path.exists(download_dir) != True):
print('Invalid Directory!') print('Invalid Directory!')
sys.exit() sys.exit()
download_dir = download_dir + "\model\\" download_dir = download_dir + "\\model\\"
if (os.path.exists(download_dir) != True): if (os.path.exists(download_dir) != True):
os.mkdir(download_dir) os.mkdir(download_dir)
@@ -86,7 +86,7 @@ def download_video(url, filename):
state = 0 state = 0
print('[+] Save as: ' + filename + '\n') print('[+] Save as: ' + filename + '\n')
try: try:
run_command(['.\yt-dlp', '--downloader', 'aria2c', '--downloader-args', run_command(['.\\yt-dlp', '--downloader', 'aria2c', '--downloader-args',
'aria2c:-x 8 --log-level=info --file-allocation=none --summary-interval=1', '--no-warnings', '--newline', '-o', filename, url]) 'aria2c:-x 8 --log-level=info --file-allocation=none --summary-interval=1', '--no-warnings', '--newline', '-o', filename, url])
print("[$] Video download successfully!") print("[$] Video download successfully!")
except KeyboardInterrupt: except KeyboardInterrupt:
@@ -129,7 +129,7 @@ def ph_download_playlist(url, model_name, limit):
# tmp_playlist download # tmp_playlist download
print('... Getting playlist information...') print('... Getting playlist information...')
try: try:
playlist_download_command = [".\yt-dlp", "-j", playlist_download_command = [".\\yt-dlp", "-j",
"--flat-playlist", "--no-check-certificate", url] "--flat-playlist", "--no-check-certificate", url]
res = subprocess.run(playlist_download_command, res = subprocess.run(playlist_download_command,
capture_output=True, text=True).stdout.split("\n") capture_output=True, text=True).stdout.split("\n")
@@ -152,13 +152,13 @@ def ph_download_playlist(url, model_name, limit):
# video_dict = ast.literal_eval(res[i]) # video_dict = ast.literal_eval(res[i])
video_dict = json.loads(res[i]) video_dict = json.loads(res[i])
url = video_dict['url'] url = video_dict['url']
p = subprocess.Popen(['.\yt-dlp', '--no-warnings', '--dump-json', p = subprocess.Popen(['.\\yt-dlp', '--no-warnings', '--dump-json',
'--skip-download', url], stdout=subprocess.PIPE, stderr=None, shell=True) '--skip-download', url], stdout=subprocess.PIPE, stderr=None, shell=True)
output = p.communicate()[0] output = p.communicate()[0]
info = json.loads(output.decode('utf-8')) info = json.loads(output.decode('utf-8'))
# duration = int(info['duration']) # duration = int(info['duration'])
filename = os.path.join(download_dir, model_name, fix_title( filename = os.path.join(download_dir, model_name,
str(info["title"])) + '.' + str(info['ext'])) fix_title(str(info["title"])) + '.' + str(info['ext']))
print("\n\n==========================================\n[+] File #{}: {}".format( print("\n\n==========================================\n[+] File #{}: {}".format(
count, fix_title(str(info["title"])) + '.' + str(info['ext']))) count, fix_title(str(info["title"])) + '.' + str(info['ext'])))
ph_download_video(url, model_name, filename) ph_download_video(url, model_name, filename)
@@ -172,7 +172,7 @@ def fix_url(url, type):
url = ph_check_valid_pornhub_url(url) url = ph_check_valid_pornhub_url(url)
if '/model/' not in url: if '/model/' not in url:
p = subprocess.Popen(['.\yt-dlp', '--no-warnings', '--dump-json', p = subprocess.Popen(['.\\yt-dlp', '--no-warnings', '--dump-json',
'--skip-download', url], stdout=subprocess.PIPE, stderr=None, shell=True) '--skip-download', url], stdout=subprocess.PIPE, stderr=None, shell=True)
output = p.communicate()[0] output = p.communicate()[0]
info = json.loads(output.decode('utf-8')) info = json.loads(output.decode('utf-8'))
@@ -195,7 +195,7 @@ def ph_get_video(url):
# global duration # global duration
url = ph_check_valid_pornhub_url(url) url = ph_check_valid_pornhub_url(url)
p = subprocess.Popen(['.\yt-dlp', '--no-warnings', '--dump-json', p = subprocess.Popen(['.\\yt-dlp', '--no-warnings', '--dump-json',
'--skip-download', url], stdout=subprocess.PIPE, stderr=None, shell=True) '--skip-download', url], stdout=subprocess.PIPE, stderr=None, shell=True)
output = p.communicate()[0] output = p.communicate()[0]
info = json.loads(output.decode('utf-8')) info = json.loads(output.decode('utf-8'))

View File

@@ -1,8 +1,10 @@
#!/usr/bin/env python #!/usr/bin/env python
from sys import exit as sysexit from sys import exit as sysexit
from json import decoder, load, dump
from os.path import isfile from os.path import isfile
from lib_pornhub import ph_config_dl_dir, ph_get_video from lib_pornhub import (
ascii_banner, ph_config_dl_dir, ph_get_playlist, ph_get_video
)
from argparse import ArgumentParser
import ssl import ssl
@@ -16,45 +18,57 @@ else:
ssl._create_default_https_context = _create_unverified_https_context ssl._create_default_https_context = _create_unverified_https_context
filename = "video_list.json" def save_file(filename, list_to_file):
video_list = []
fl_video_list = []
def save_file():
global filename, fl_video_list
with open(filename, encoding="utf-8", mode="w") as f: with open(filename, encoding="utf-8", mode="w") as f:
dump(fl_video_list, f, indent=4) for url in list_to_file:
f.write(url + "\n")
def main(): def main():
global filename, video_list, fl_video_list parser = ArgumentParser()
if not isfile(filename): parser.add_argument('--url', type=str, help='URL of Pornhub video')
print("file not found") parser.add_argument('--playlist', nargs='?', const='best', choices=['most-viewed', 'best', 'top-rated', 'longest'], help='Optional ordering of videos')
sysexit() parser.add_argument('--limit', type=int, help='Maximum number of videos', default=0)
try: parser.add_argument('--dir', type=str, help='Output directory')
with open(filename, encoding="utf-8") as f: parser.add_argument('--file', type=str, help='File with links to download')
temp = load(f) args = parser.parse_args()
video_list = temp.copy()
fl_video_list = temp.copy()
except decoder.JSONDecodeError:
print("syntax error, check file")
sysexit()
ph_config_dl_dir(None)
video_len = len(video_list)
count = 0
for url in video_list:
print('[+] URL: ' + url)
ph_get_video(url)
fl_video_list.remove(url)
count += 1
print("\nDownloaded: {}/{}\n".format(count, video_len))
save_file()
################################
ascii_banner("PornHub-dl")
print("\t\tMade by tnt2402\n")
print("\t\tModified by JDM17")
print("\n\n\n########################################################\n")
################################
if __name__ == "__main__": ph_config_dl_dir(args.dir)
try: if (args.url == None and args.playlist != None):
main() print("URL cannot be empty!")
except KeyboardInterrupt: sys.exit()
save_file() elif (args.playlist != None):
sysexit() ph_get_playlist(args.url, args.playlist, args.limit)
elif (args.url != None):
ph_get_video(args.url)
elif (args.file != None):
if not isfile(args.file):
print("file not found")
sysexit()
with open(args.file, encoding="utf-8") as f:
temp = list(filter(None, f.read().strip().split("\n")))
list_from_file = temp.copy()
new_file = temp.copy()
video_len = len(list_from_file)
count = 0
try:
for url in list_from_file:
print('[+] URL: ' + url)
ph_get_video(url)
new_file.remove(url)
count += 1
print("\nProcessed: {}/{}\n".format(count, video_len))
except KeyboardInterrupt:
pass
save_file(args.file, new_file)
if __name__ == '__main__':
main()

View File

@@ -1,39 +0,0 @@
#!/usr/bin/env python
from lib_pornhub import *
import argparse
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--url', type=str, help='URL of Pornhub video')
parser.add_argument('--playlist', nargs='?', const='best', choices=['most-viewed', 'best', 'top-rated', 'longest'], help='Optional ordering of videos')
parser.add_argument('--limit', type=int, help='Maximum number of videos', default=0)
parser.add_argument('--dir', type=str, help='Output directory')
args = parser.parse_args()
################################
ascii_banner("PornHub-dl")
print(" Made by tnt2402\n\n\n########################################################")
################################
ph_config_dl_dir(args.dir)
if (args.url == None and args.playlist != None):
print("URL cannot be empty !")
sys.exit()
elif (args.playlist != None):
ph_get_playlist(args.url, args.playlist, args.limit)
elif (args.url != None):
ph_get_video(args.url)
if __name__ == '__main__':
main()

61
pornhub_dl_only_file.py Normal file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env python
from sys import exit as sysexit
from json import decoder, load, dump
from os.path import isfile
from lib_pornhub import ph_config_dl_dir, ph_get_video
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
# Legacy Python that doesn't verify HTTPS certificates by default
pass
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
filename = "video_list.json"
video_list = []
fl_video_list = []
def save_file():
global filename, fl_video_list
with open(filename, encoding="utf-8", mode="w") as f:
dump(fl_video_list, f, indent=4)
def main():
global filename, video_list, fl_video_list
if not isfile(filename):
print("file not found")
sysexit()
try:
with open(filename, encoding="utf-8") as f:
temp = load(f)
video_list = temp.copy()
fl_video_list = temp.copy()
except decoder.JSONDecodeError:
print("syntax error, check file")
sysexit()
ph_config_dl_dir(None)
video_len = len(video_list)
count = 0
for url in video_list:
print('[+] URL: ' + url)
ph_get_video(url)
fl_video_list.remove(url)
count += 1
print("\nDownloaded: {}/{}\n".format(count, video_len))
save_file()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
save_file()
sysexit()
save_file()

Binary file not shown.