Update
Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,3 +1,3 @@
|
||||
|
||||
*.pyc
|
||||
*.pyc
|
||||
__pycache__
|
||||
venv
|
||||
model
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -29,7 +29,7 @@ def ph_config_dl_dir(dir):
|
||||
download_dir = dir
|
||||
print("Output directory: " + download_dir + "\model\\")
|
||||
if (os.path.exists(download_dir) != True):
|
||||
print('Invalid Directory !')
|
||||
print('Invalid Directory!')
|
||||
sys.exit()
|
||||
download_dir = download_dir + "\model\\"
|
||||
if (os.path.exists(download_dir) != True):
|
||||
@@ -49,10 +49,8 @@ def run_command(command):
|
||||
output = process.stdout.readline().decode("utf-8")
|
||||
if "[download] 100" in output:
|
||||
result_txt = 'Result: ' + output.split("[download]")[1].strip()
|
||||
|
||||
if output == '' and process.poll() is not None:
|
||||
break
|
||||
|
||||
if 'Total fragments' in output:
|
||||
total_frag = int(output.split(':')[1].strip())
|
||||
if 'FILE:' in output:
|
||||
@@ -64,14 +62,15 @@ def run_command(command):
|
||||
pbar.update(100 - state)
|
||||
pbar.close()
|
||||
rc = process.poll()
|
||||
if result_txt != '': print(result_txt)
|
||||
if result_txt != '':
|
||||
print(result_txt)
|
||||
return rc
|
||||
except Exception as e:
|
||||
print(e)
|
||||
sys.exit(0)
|
||||
|
||||
# Main functions
|
||||
|
||||
# Main functions
|
||||
|
||||
def ph_check_valid_pornhub_url(url):
|
||||
if ('pornhub.com' not in url):
|
||||
@@ -87,10 +86,8 @@ def download_video(url, filename):
|
||||
state = 0
|
||||
print('[+] Save as: ' + filename + '\n')
|
||||
try:
|
||||
|
||||
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])
|
||||
|
||||
print("[$] Video download successfully!")
|
||||
except KeyboardInterrupt:
|
||||
os.kill(p.pid, signal.CTRL_C_EVENT)
|
||||
@@ -113,7 +110,6 @@ def check_output_dir(model_name):
|
||||
|
||||
|
||||
def ph_download_video(url, model_name, filename):
|
||||
|
||||
try:
|
||||
check_output_dir(model_name)
|
||||
# filename = os.path.join(download_dir, model_name, fix_title(str(video["title"])) + '.' + str(video['ext']))
|
||||
@@ -145,8 +141,8 @@ def ph_download_playlist(url, model_name, limit):
|
||||
if res == ['']:
|
||||
print("Cannot download playlist information!")
|
||||
sys.exit(1)
|
||||
|
||||
print("Playlist has {} videos".format(len(res)))
|
||||
|
||||
for i in range(len(res) - 1):
|
||||
if (count == limit and limit != 0):
|
||||
break
|
||||
@@ -205,8 +201,8 @@ def ph_get_video(url):
|
||||
info = json.loads(output.decode('utf-8'))
|
||||
model_name = info['uploader']
|
||||
# duration = int(info['duration'])
|
||||
filename = os.path.join(download_dir, model_name, fix_title(
|
||||
str(info["title"])) + '.' + str(info['ext']))
|
||||
filename = os.path.join(download_dir, model_name,
|
||||
fix_title(str(info["title"])) + '.' + str(info['ext']))
|
||||
print("[+] Model: " + model_name)
|
||||
print("[+] Filename: " + fix_title(str(info["title"])) +
|
||||
'.' + str(info['ext']))
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
from lib_pornhub import *
|
||||
import argparse
|
||||
|
||||
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:
|
||||
@@ -13,27 +15,46 @@ 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():
|
||||
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()
|
||||
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
|
||||
fl_video_list = temp
|
||||
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(" 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()
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
save_file()
|
||||
sysexit()
|
||||
|
||||
39
pornhub_dl_old.py
Normal file
39
pornhub_dl_old.py
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/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()
|
||||
Reference in New Issue
Block a user