diff options
author | Pccode66 <49125134+Pccode66@users.noreply.github.com> | 2021-02-24 15:45:56 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-25 00:15:56 +0530 |
commit | 7a5c1cfe93924351387b44919b3c0b2f66c4b883 (patch) | |
tree | 6da63f3d7b16cf7d4b9fdb29b029125cab8bd0d3 /yt_dlp/postprocessor/movefilesafterdownload.py | |
parent | c4218ac3f1146daac20308439cdc374e3561101a (diff) |
Completely change project name to yt-dlp (#85)
* All modules and binary names are changed
* All documentation references changed
* yt-dlp no longer loads youtube-dlc config files
* All URLs changed to point to organization account
Co-authored-by: Pccode66
Co-authored-by: pukkandan
Diffstat (limited to 'yt_dlp/postprocessor/movefilesafterdownload.py')
-rw-r--r-- | yt_dlp/postprocessor/movefilesafterdownload.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/yt_dlp/postprocessor/movefilesafterdownload.py b/yt_dlp/postprocessor/movefilesafterdownload.py new file mode 100644 index 000000000..fa61317ed --- /dev/null +++ b/yt_dlp/postprocessor/movefilesafterdownload.py @@ -0,0 +1,54 @@ +from __future__ import unicode_literals +import os +import shutil + +from .common import PostProcessor +from ..utils import ( + decodeFilename, + encodeFilename, + make_dir, + PostProcessingError, +) + + +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): + dl_path, dl_name = os.path.split(encodeFilename(info['filepath'])) + finaldir = info.get('__finaldir', dl_path) + finalpath = os.path.join(finaldir, dl_name) + self.files_to_move.update(info['__files_to_move']) + self.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 self.files_to_move.items(): + if not newfile: + newfile = make_newfilename(oldfile) + if os.path.abspath(encodeFilename(oldfile)) == os.path.abspath(encodeFilename(newfile)): + continue + if not os.path.exists(encodeFilename(oldfile)): + self.report_warning('File "%s" cannot be found' % oldfile) + continue + if os.path.exists(encodeFilename(newfile)): + if self.get_param('overwrites', True): + self.report_warning('Replacing existing file "%s"' % newfile) + os.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'] = finalpath + return [], info |