-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'
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():
% (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