mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-20 01:42:50 +01:00
[MoveFiles] More robust way to get final filename
:ci skip dl
This commit is contained in:
parent
6b4b65c4f4
commit
c571435f9c
@ -2252,10 +2252,8 @@ def correct_ext(filename):
|
|||||||
success, real_download = dl(temp_filename, info_dict)
|
success, real_download = dl(temp_filename, info_dict)
|
||||||
info_dict['__real_download'] = real_download
|
info_dict['__real_download'] = real_download
|
||||||
|
|
||||||
# info_dict['__temp_filename'] = temp_filename
|
|
||||||
dl_filename = dl_filename or temp_filename
|
dl_filename = dl_filename or temp_filename
|
||||||
info_dict['__dl_filename'] = dl_filename
|
info_dict['__finaldir'] = os.path.dirname(os.path.abspath(encodeFilename(full_filename)))
|
||||||
info_dict['__final_filename'] = full_filename
|
|
||||||
|
|
||||||
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
|
||||||
self.report_error('unable to download video data: %s' % error_to_compat_str(err))
|
self.report_error('unable to download video data: %s' % error_to_compat_str(err))
|
||||||
|
@ -22,17 +22,18 @@ def pp_key(cls):
|
|||||||
return 'MoveFiles'
|
return 'MoveFiles'
|
||||||
|
|
||||||
def run(self, info):
|
def run(self, info):
|
||||||
if info.get('__dl_filename') is None:
|
dl_path, dl_name = os.path.split(encodeFilename(info['filepath']))
|
||||||
return [], info
|
finaldir = info.get('__finaldir', dl_path)
|
||||||
self.files_to_move.setdefault(info['__dl_filename'], '')
|
finalpath = os.path.join(finaldir, dl_name)
|
||||||
outdir = os.path.dirname(os.path.abspath(encodeFilename(info['__final_filename'])))
|
self.files_to_move[info['filepath']] = finalpath
|
||||||
|
|
||||||
for oldfile, newfile in self.files_to_move.items():
|
for oldfile, newfile in self.files_to_move.items():
|
||||||
if not os.path.exists(encodeFilename(oldfile)):
|
if not os.path.exists(encodeFilename(oldfile)):
|
||||||
self.report_warning('File "%s" cannot be found' % oldfile)
|
self.report_warning('File "%s" cannot be found' % oldfile)
|
||||||
continue
|
continue
|
||||||
if not newfile:
|
if not newfile:
|
||||||
newfile = compat_str(os.path.join(outdir, os.path.basename(encodeFilename(oldfile))))
|
newfile = os.path.join(finaldir, os.path.basename(encodeFilename(oldfile)))
|
||||||
|
oldfile, newfile = compat_str(oldfile), compat_str(newfile)
|
||||||
if os.path.abspath(encodeFilename(oldfile)) == os.path.abspath(encodeFilename(newfile)):
|
if os.path.abspath(encodeFilename(oldfile)) == os.path.abspath(encodeFilename(newfile)):
|
||||||
continue
|
continue
|
||||||
if os.path.exists(encodeFilename(newfile)):
|
if os.path.exists(encodeFilename(newfile)):
|
||||||
@ -48,5 +49,5 @@ def run(self, info):
|
|||||||
self.to_screen('Moving file "%s" to "%s"' % (oldfile, newfile))
|
self.to_screen('Moving file "%s" to "%s"' % (oldfile, newfile))
|
||||||
shutil.move(oldfile, newfile) # os.rename cannot move between volumes
|
shutil.move(oldfile, newfile) # os.rename cannot move between volumes
|
||||||
|
|
||||||
info['filepath'] = info['__final_filename']
|
info['filepath'] = compat_str(finalpath)
|
||||||
return [], info
|
return [], info
|
||||||
|
Loading…
Reference in New Issue
Block a user