]>
jfr.im git - yt-dlp.git/blob - youtube_dlc/postprocessor/movefilesafterdownload.py
1 from __future__
import unicode_literals
5 from .common
import PostProcessor
11 from ..compat
import compat_str
14 class MoveFilesAfterDownloadPP(PostProcessor
):
16 def __init__(self
, downloader
, files_to_move
):
17 PostProcessor
.__init
__(self
, downloader
)
18 self
.files_to_move
= files_to_move
25 if info
.get('__dl_filename') is None:
27 self
.files_to_move
.setdefault(info
['__dl_filename'], '')
28 outdir
= os
.path
.dirname(os
.path
.abspath(encodeFilename(info
['__final_filename'])))
30 for oldfile
, newfile
in self
.files_to_move
.items():
31 if not os
.path
.exists(encodeFilename(oldfile
)):
32 self
.report_warning('File "%s" cannot be found' % oldfile
)
35 newfile
= compat_str(os
.path
.join(outdir
, os
.path
.basename(encodeFilename(oldfile
))))
36 if os
.path
.abspath(encodeFilename(oldfile
)) == os
.path
.abspath(encodeFilename(newfile
)):
38 if os
.path
.exists(encodeFilename(newfile
)):
39 if self
.get_param('overwrites', True):
40 self
.report_warning('Replacing existing file "%s"' % newfile
)
41 os
.path
.remove(encodeFilename(newfile
))
44 'Cannot move file "%s" out of temporary directory since "%s" already exists. '
47 make_dir(newfile
, PostProcessingError
)
48 self
.to_screen('Moving file "%s" to "%s"' % (oldfile
, newfile
))
49 shutil
.move(oldfile
, newfile
) # os.rename cannot move between volumes
51 info
['filepath'] = info
['__final_filename']