aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpukkandan <pukkandan@gmail.com>2021-01-23 20:55:45 +0530
committerpukkandan <pukkandan@gmail.com>2021-01-24 20:24:06 +0530
commitc571435f9c22129c3663b738ca7b577ee05eec97 (patch)
treeac00703970a66c31b7d389e4e7fee5663bfd9b80
parent6b4b65c4f417e9e6d35f358c87987ebd883f45e7 (diff)
downloadhypervideo-pre-c571435f9c22129c3663b738ca7b577ee05eec97.tar.lz
hypervideo-pre-c571435f9c22129c3663b738ca7b577ee05eec97.tar.xz
hypervideo-pre-c571435f9c22129c3663b738ca7b577ee05eec97.zip
[MoveFiles] More robust way to get final filename
:ci skip dl
-rw-r--r--youtube_dlc/YoutubeDL.py4
-rw-r--r--youtube_dlc/postprocessor/movefilesafterdownload.py13
2 files changed, 8 insertions, 9 deletions
diff --git a/youtube_dlc/YoutubeDL.py b/youtube_dlc/YoutubeDL.py
index 42e0234a0..b45b1bbba 100644
--- a/youtube_dlc/YoutubeDL.py
+++ b/youtube_dlc/YoutubeDL.py
@@ -2252,10 +2252,8 @@ class YoutubeDL(object):
success, real_download = dl(temp_filename, info_dict)
info_dict['__real_download'] = real_download
- # info_dict['__temp_filename'] = temp_filename
dl_filename = dl_filename or temp_filename
- info_dict['__dl_filename'] = dl_filename
- info_dict['__final_filename'] = full_filename
+ info_dict['__finaldir'] = os.path.dirname(os.path.abspath(encodeFilename(full_filename)))
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))
diff --git a/youtube_dlc/postprocessor/movefilesafterdownload.py b/youtube_dlc/postprocessor/movefilesafterdownload.py
index 3f7f529a9..4146a9549 100644
--- a/youtube_dlc/postprocessor/movefilesafterdownload.py
+++ b/youtube_dlc/postprocessor/movefilesafterdownload.py
@@ -22,17 +22,18 @@ class MoveFilesAfterDownloadPP(PostProcessor):
return 'MoveFiles'
def run(self, info):
- if info.get('__dl_filename') is None:
- return [], info
- self.files_to_move.setdefault(info['__dl_filename'], '')
- outdir = os.path.dirname(os.path.abspath(encodeFilename(info['__final_filename'])))
+ dl_path, dl_name = os.path.split(encodeFilename(info['filepath']))
+ finaldir = info.get('__finaldir', dl_path)
+ finalpath = os.path.join(finaldir, dl_name)
+ self.files_to_move[info['filepath']] = finalpath
for oldfile, newfile in self.files_to_move.items():
if not os.path.exists(encodeFilename(oldfile)):
self.report_warning('File "%s" cannot be found' % oldfile)
continue
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)):
continue
if os.path.exists(encodeFilename(newfile)):
@@ -48,5 +49,5 @@ class MoveFilesAfterDownloadPP(PostProcessor):
self.to_screen('Moving file "%s" to "%s"' % (oldfile, newfile))
shutil.move(oldfile, newfile) # os.rename cannot move between volumes
- info['filepath'] = info['__final_filename']
+ info['filepath'] = compat_str(finalpath)
return [], info