]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/postprocessor/movefilesafterdownload.py
bugfix for a44ca5a470e09b5170fc9c3a46733f050fadbfae, 19a0394044bfad36cd665450271b8eb0...
[yt-dlp.git] / yt_dlp / postprocessor / movefilesafterdownload.py
index 0ab7744ca6ead31fc1a046dc59ce794fc4232cdb..436d132272f36fa20a4fd058b9aea6c4993ba663 100644 (file)
@@ -1,18 +1,21 @@
-from __future__ import unicode_literals
 import os
 import shutil
 
 from .common import PostProcessor
 from ..utils import (
+    PostProcessingError,
     decodeFilename,
     encodeFilename,
     make_dir,
-    PostProcessingError,
 )
 
 
 class MoveFilesAfterDownloadPP(PostProcessor):
 
+    def __init__(self, downloader=None, downloaded=True):
+        PostProcessor.__init__(self, downloader)
+        self._downloaded = downloaded
+
     @classmethod
     def pp_key(cls):
         return 'MoveFiles'
@@ -21,7 +24,8 @@ def run(self, info):
         dl_path, dl_name = os.path.split(encodeFilename(info['filepath']))
         finaldir = info.get('__finaldir', dl_path)
         finalpath = os.path.join(finaldir, dl_name)
-        info['__files_to_move'][info['filepath']] = decodeFilename(finalpath)
+        if self._downloaded:
+            info['__files_to_move'][info['filepath']] = decodeFilename(finalpath)
 
         make_newfilename = lambda old: decodeFilename(os.path.join(finaldir, os.path.basename(encodeFilename(old))))
         for oldfile, newfile in info['__files_to_move'].items():
@@ -42,7 +46,7 @@ def run(self, info):
                         % (oldfile, newfile))
                     continue
             make_dir(newfile, PostProcessingError)
-            self.to_screen('Moving file "%s" to "%s"' % (oldfile, newfile))
+            self.to_screen(f'Moving file "{oldfile}" to "{newfile}"')
             shutil.move(oldfile, newfile)  # os.rename cannot move between volumes
 
         info['filepath'] = finalpath