aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dlc/postprocessor/movefilesafterdownload.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan@users.noreply.github.com>2021-01-23 17:48:12 +0530
committerpukkandan <pukkandan@gmail.com>2021-01-23 17:53:17 +0530
commit0202b52a0c0a15da6073a122aae7ed6693e18f01 (patch)
tree46a819bbb1c97649216ff0a040468a7d0d73ef29 /youtube_dlc/postprocessor/movefilesafterdownload.py
parentb8f6bbe68a6ff1f733a8d71d991b03008dfaf621 (diff)
downloadhypervideo-pre-0202b52a0c0a15da6073a122aae7ed6693e18f01.tar.lz
hypervideo-pre-0202b52a0c0a15da6073a122aae7ed6693e18f01.tar.xz
hypervideo-pre-0202b52a0c0a15da6073a122aae7ed6693e18f01.zip
#29 New option `-P`/`--paths` to give different paths for different types of files
Syntax: `-P "type:path" -P "type:path"` Types: home, temp, description, annotation, subtitle, infojson, thumbnail
Diffstat (limited to 'youtube_dlc/postprocessor/movefilesafterdownload.py')
-rw-r--r--youtube_dlc/postprocessor/movefilesafterdownload.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/youtube_dlc/postprocessor/movefilesafterdownload.py b/youtube_dlc/postprocessor/movefilesafterdownload.py
new file mode 100644
index 000000000..3f7f529a9
--- /dev/null
+++ b/youtube_dlc/postprocessor/movefilesafterdownload.py
@@ -0,0 +1,52 @@
+from __future__ import unicode_literals
+import os
+import shutil
+
+from .common import PostProcessor
+from ..utils import (
+ encodeFilename,
+ make_dir,
+ PostProcessingError,
+)
+from ..compat import compat_str
+
+
+class MoveFilesAfterDownloadPP(PostProcessor):
+
+ def __init__(self, downloader, files_to_move):
+ PostProcessor.__init__(self, downloader)
+ self.files_to_move = files_to_move
+
+ @classmethod
+ def pp_key(cls):
+ 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'])))
+
+ 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))))
+ if os.path.abspath(encodeFilename(oldfile)) == os.path.abspath(encodeFilename(newfile)):
+ continue
+ if os.path.exists(encodeFilename(newfile)):
+ if self.get_param('overwrites', True):
+ self.report_warning('Replacing existing file "%s"' % newfile)
+ os.path.remove(encodeFilename(newfile))
+ else:
+ self.report_warning(
+ 'Cannot move file "%s" out of temporary directory since "%s" already exists. '
+ % (oldfile, newfile))
+ continue
+ make_dir(newfile, PostProcessingError)
+ 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']
+ return [], info