This commit is contained in:
parent
779a68e40d
commit
653aded23e
|
@ -38,5 +38,5 @@ Download, compress, and send your YouTube videos.
|
|||
- `--encrypt`, `-e` Encrypt the compressed 7z archive? If set will ask for password
|
||||
- `--password`, `-p` Provide the password to encrypt the compressed 7z archive with
|
||||
- `--no-update`, `-nu` Don't update any Pip packages. You'd want to update because youtube-dl updates so much
|
||||
- `--max-size`, `-m` Max size of video in mb. Default is 2000 (2 gb)
|
||||
- `--max-size`, `-m` Max size of video in mb. Default is 2000 mb (2 gb)
|
||||
- `--check-size`, `-c` Verify the video is smaller than the max size and skip if not
|
||||
|
|
|
@ -30,7 +30,7 @@ parser.add_argument('--encrypt', '-e', action='store_true', help='encrypt the co
|
|||
parser.add_argument('--password', '-p', action='store_true', help='password to encrypt the compressed 7z archive with')
|
||||
parser.add_argument('--no-update', '-nu', action='store_true', help='don\t update Pip packages')
|
||||
parser.add_argument('--cmd', '-c', help='use the bash youtube-dl instead of the embedded python version', action='store_true')
|
||||
parser.add_argument('--max-size', '-m', type=int, choices=range(500, 100000), default=2000, help="max size of video in mb")
|
||||
parser.add_argument('--max-size', '-m', type=int, default=2000, help="max size of video in mb")
|
||||
parser.add_argument('--check-size', '-ch', action='store_true', help="verify the video is smaller than the max size and skip if not")
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -102,7 +102,9 @@ def compress(name):
|
|||
if args.output is not None:
|
||||
if args.encrypt:
|
||||
pwd = input('password: ')
|
||||
cmd = '7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=1024m -ms=on -mhe=on -p"{}.7z" "{}" "downloads/*"'.format(pwd, name)
|
||||
cmd = '7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=1024m -ms=on -mhe=on -p"{}" "{}.7z" "downloads/*"'.format(pwd, name)
|
||||
elif args.password is not None:
|
||||
cmd = '7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=1024m -ms=on -mhe=on -p{} "{}.7z" "downloads/*"'.format(args.password, name)
|
||||
else:
|
||||
cmd = '7z a -t7z -m0=lzma2 -mx=9 -mfb=64 -md=1024m -ms=on -mhe=on "{}.7z" "downloads/*"'.format(name)
|
||||
os.system(cmd)
|
||||
|
@ -115,13 +117,14 @@ def checkSize(url):
|
|||
ytdl = youtube_dl.YoutubeDL()
|
||||
info = ytdl.extract_info(url, download=False)
|
||||
max = 0
|
||||
maxBytes = args.max_size * 1000000
|
||||
for x in info['formats']:
|
||||
try:
|
||||
if x['filesize'] > max:
|
||||
max = x['filesize']
|
||||
except TypeError as e:
|
||||
pass
|
||||
if max > args.max_size:
|
||||
if max > maxBytes:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
@ -131,6 +134,10 @@ def checkSize(url):
|
|||
|
||||
def getUrls(playlist):
|
||||
proc = subprocess.run(['bash', 'get-urls.sh', playlist], capture_output=True, encoding="utf-8")
|
||||
if proc.stdout == '':
|
||||
logger.error('missing get-urls.sh')
|
||||
print('missing get-urls.sh')
|
||||
sys.exit(1)
|
||||
if proc.stdout.find('get-urls.sh: line 1: jq: command not found') == -1:
|
||||
ret = re.findall(r'(https:\/\/.*)', proc.stdout)
|
||||
return ret
|
||||
|
@ -183,7 +190,7 @@ def my_hook(d):
|
|||
sys.stdout.flush()
|
||||
|
||||
|
||||
ytdlFormat = '(bestvideo[{}][vcodec^=av01][height>=1080][fps>30]/bestvideo[{}][vcodec=vp9.2][height>=1080][fps>30]/bestvideo[{}][vcodec=vp9][height>=1080][fps>30]/bestvideo[{}][vcodec^=av01][height>=1080]/bestvideo[{}][vcodec=vp9.2][height>=1080]/bestvideo[{}][vcodec=vp9][height>=1080]/bestvideo[{}][height>=1080]/bestvideo[{}][vcodec^=av01][height>=720][fps>30]/bestvideo[{}][vcodec=vp9.2][height>=720][fps>30]/bestvideo[{}][vcodec=vp9][height>=720][fps>30]/bestvideo[{}][vcodec^=av01][height>=720]/bestvideo[{}][vcodec=vp9.2][height>=720]/bestvideo[{}][vcodec=vp9][height>=720]/bestvideo[{}][height>=720]/bestvideo[{}])+(bestaudio[acodec=opus]/bestaudio)/best'.replace('{}', 'filesize<' + str(args.max_size))
|
||||
ytdlFormat = '(bestvideo[{}][vcodec^=av01][height>=1080][fps>30]/bestvideo[{}][vcodec=vp9.2][height>=1080][fps>30]/bestvideo[{}][vcodec=vp9][height>=1080][fps>30]/bestvideo[{}][vcodec^=av01][height>=1080]/bestvideo[{}][vcodec=vp9.2][height>=1080]/bestvideo[{}][vcodec=vp9][height>=1080]/bestvideo[{}][height>=1080]/bestvideo[{}][vcodec^=av01][height>=720][fps>30]/bestvideo[{}][vcodec=vp9.2][height>=720][fps>30]/bestvideo[{}][vcodec=vp9][height>=720][fps>30]/bestvideo[{}][vcodec^=av01][height>=720]/bestvideo[{}][vcodec=vp9.2][height>=720]/bestvideo[{}][vcodec=vp9][height>=720]/bestvideo[{}][height>=720]/bestvideo[{}])+(bestaudio[acodec=opus]/bestaudio)/best'.replace('{}', 'filesize<' + str(args.max_size) + 'M')
|
||||
ydl_opts = {
|
||||
'merge_output_format': 'mkv',
|
||||
'allsubtitles': True,
|
||||
|
@ -198,7 +205,6 @@ ydl_opts = {
|
|||
'logger': ytdlLogger(),
|
||||
'progress_hooks': [my_hook],
|
||||
}
|
||||
|
||||
ytdlCMD = 'youtube-dl -i --add-metadata --all-subs --embed-subs --embed-thumbnail -f "{}" --merge-output-format mkv -o "downloads/%(title)s - %(id)s.%(ext)s" --write-annotations --write-info-json --write-description --write-all-thumbnails --write-sub --sub-format "best" --geo-bypass'.format(
|
||||
ytdlFormat)
|
||||
|
||||
|
@ -208,33 +214,7 @@ if not isURL:
|
|||
for x in getUrls(line):
|
||||
if checkSize(x):
|
||||
if args.check_size:
|
||||
if args.cmd:
|
||||
print('========================')
|
||||
print('[info] Video size ok')
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
if args.cmd:
|
||||
ytOut = subprocess.run(ytdlCMD + ' "' + x + '"', capture_output=True, encoding="utf-8", shell=True)
|
||||
ret = re.findall(r'(.*\n)', ytOut.stdout)
|
||||
for x in ret:
|
||||
logger.info(x.strip('\n'))
|
||||
print(x.strip('\n'))
|
||||
else:
|
||||
ydl.download([x])
|
||||
if args.playlists:
|
||||
compress('{}-{}'.format(args.output, i))
|
||||
else:
|
||||
compress(args.output)
|
||||
else:
|
||||
print('[info] Video too big')
|
||||
logger.info('skipping ' + x + ' because too big')
|
||||
i = i + 1
|
||||
else:
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
for x in getUrls(args.file):
|
||||
if checkSize(x):
|
||||
if args.check_size:
|
||||
if args.cmd:
|
||||
print('========================')
|
||||
print('========================')
|
||||
print('[info] Video size ok')
|
||||
if args.cmd:
|
||||
ytOut = subprocess.run(ytdlCMD + ' "' + x + '"', capture_output=True, encoding="utf-8", shell=True)
|
||||
|
@ -243,10 +223,37 @@ else:
|
|||
logger.info(x.strip('\n'))
|
||||
print(x.strip('\n'))
|
||||
else:
|
||||
ydl.download([x])
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([x])
|
||||
if args.playlists:
|
||||
compress('{}-{}'.format(args.output, i))
|
||||
else:
|
||||
compress(args.output)
|
||||
i = i + 1
|
||||
else:
|
||||
print('[info] Video too big')
|
||||
logger.info('skipping ' + x + ' because too big')
|
||||
compress(args.output)
|
||||
i = i + 1
|
||||
else:
|
||||
for x in getUrls(args.file):
|
||||
if checkSize(x):
|
||||
if args.check_size:
|
||||
print('========================')
|
||||
print('[info] Video size ok')
|
||||
if args.cmd:
|
||||
ytOut = subprocess.run(ytdlCMD + ' "' + x + '"', capture_output=True, encoding="utf-8", shell=True)
|
||||
ret = re.findall(r'(.*\n)', ytOut.stdout)
|
||||
for x in ret:
|
||||
logger.info(x.strip('\n'))
|
||||
print(x.strip('\n'))
|
||||
else:
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download([x])
|
||||
i = i + 1
|
||||
else:
|
||||
print('[info] Video too big')
|
||||
logger.info('skipping ' + x + ' because too big')
|
||||
i = i + 1
|
||||
compress(args.output)
|
||||
|
||||
print()
|
Reference in New Issue