]>
jfr.im git - yt-dlp.git/blob - yt_dlp/postprocessor/movefilesafterdownload.py
1 from __future__
import unicode_literals
5 from .common
import PostProcessor
14 class MoveFilesAfterDownloadPP(PostProcessor
):
16 def __init__(self
, downloader
=None, downloaded
=True):
17 PostProcessor
.__init
__(self
, downloader
)
18 self
._downloaded
= downloaded
25 dl_path
, dl_name
= os
.path
.split(encodeFilename(info
['filepath']))
26 finaldir
= info
.get('__finaldir', dl_path
)
27 finalpath
= os
.path
.join(finaldir
, dl_name
)
29 info
['__files_to_move'][info
['filepath']] = decodeFilename(finalpath
)
31 make_newfilename
= lambda old
: decodeFilename(os
.path
.join(finaldir
, os
.path
.basename(encodeFilename(old
))))
32 for oldfile
, newfile
in info
['__files_to_move'].items():
34 newfile
= make_newfilename(oldfile
)
35 if os
.path
.abspath(encodeFilename(oldfile
)) == os
.path
.abspath(encodeFilename(newfile
)):
37 if not os
.path
.exists(encodeFilename(oldfile
)):
38 self
.report_warning('File "%s" cannot be found' % oldfile
)
40 if os
.path
.exists(encodeFilename(newfile
)):
41 if self
.get_param('overwrites', True):
42 self
.report_warning('Replacing existing file "%s"' % newfile
)
43 os
.remove(encodeFilename(newfile
))
46 'Cannot move file "%s" out of temporary directory since "%s" already exists. '
49 make_dir(newfile
, PostProcessingError
)
50 self
.to_screen('Moving file "%s" to "%s"' % (oldfile
, newfile
))
51 shutil
.move(oldfile
, newfile
) # os.rename cannot move between volumes
53 info
['filepath'] = finalpath