[BACKEND] Move files from working to output directory instead of copying (#104)
* [BACKEND] Move files from working to output directory instead of copying * still copy split video thumbnails
This commit is contained in:
parent
605de74697
commit
f66596d1a7
3 changed files with 20 additions and 8 deletions
|
|
@ -148,7 +148,7 @@ class Subscription:
|
||||||
and self.downloader_class.supports_download_archive
|
and self.downloader_class.supports_download_archive
|
||||||
)
|
)
|
||||||
|
|
||||||
def _copy_entry_files_to_output_directory(
|
def _move_entry_files_to_output_directory(
|
||||||
self, entry: Entry, entry_metadata: Optional[FileMetadata] = None
|
self, entry: Entry, entry_metadata: Optional[FileMetadata] = None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -288,7 +288,7 @@ class Subscription:
|
||||||
if optional_plugin_entry_metadata:
|
if optional_plugin_entry_metadata:
|
||||||
entry_metadata.extend(optional_plugin_entry_metadata)
|
entry_metadata.extend(optional_plugin_entry_metadata)
|
||||||
|
|
||||||
self._copy_entry_files_to_output_directory(
|
self._move_entry_files_to_output_directory(
|
||||||
entry=entry, entry_metadata=entry_metadata
|
entry=entry, entry_metadata=entry_metadata
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from shutil import copyfile
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
@ -186,7 +186,19 @@ class FileHandler:
|
||||||
dst_file_path
|
dst_file_path
|
||||||
Destination file
|
Destination file
|
||||||
"""
|
"""
|
||||||
copyfile(src=src_file_path, dst=dst_file_path)
|
shutil.copyfile(src=src_file_path, dst=dst_file_path)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def move(cls, src_file_path: Union[str, Path], dst_file_path: Union[str, Path]):
|
||||||
|
"""
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
src_file_path
|
||||||
|
Source file
|
||||||
|
dst_file_path
|
||||||
|
Destination file
|
||||||
|
"""
|
||||||
|
shutil.move(src=src_file_path, dst=dst_file_path)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def delete(cls, file_path: Union[str, Path]):
|
def delete(cls, file_path: Union[str, Path]):
|
||||||
|
|
@ -199,7 +211,7 @@ class FileHandler:
|
||||||
if os.path.isfile(file_path):
|
if os.path.isfile(file_path):
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
|
|
||||||
def copy_file_to_output_directory(
|
def move_file_to_output_directory(
|
||||||
self, file_name: str, output_file_name: str, file_metadata: Optional[FileMetadata] = None
|
self, file_name: str, output_file_name: str, file_metadata: Optional[FileMetadata] = None
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
|
|
@ -223,7 +235,7 @@ class FileHandler:
|
||||||
if not self.dry_run:
|
if not self.dry_run:
|
||||||
output_file_path = Path(self.output_directory) / output_file_name
|
output_file_path = Path(self.output_directory) / output_file_name
|
||||||
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
|
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
|
||||||
self.copy(
|
self.move(
|
||||||
src_file_path=Path(self.working_directory) / file_name,
|
src_file_path=Path(self.working_directory) / file_name,
|
||||||
dst_file_path=output_file_path,
|
dst_file_path=output_file_path,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ class EnhancedDownloadArchive:
|
||||||
a. self._load()
|
a. self._load()
|
||||||
Checks the output directory to see if an existing enhanced download archive file
|
Checks the output directory to see if an existing enhanced download archive file
|
||||||
exists. If so, load it into the class. Otherwise, initialize an empty instance of one.
|
exists. If so, load it into the class. Otherwise, initialize an empty instance of one.
|
||||||
b. self._copy_to_working_directory()
|
b. self._move_to_working_directory()
|
||||||
If the download archive was loaded successfully, create a ytdl download archive in the
|
If the download archive was loaded successfully, create a ytdl download archive in the
|
||||||
working directory. This will let ytdl know which files are already downloaded.
|
working directory. This will let ytdl know which files are already downloaded.
|
||||||
2. ( Perform the ytdlp download using a download archive with the same name )
|
2. ( Perform the ytdlp download using a download archive with the same name )
|
||||||
|
|
@ -576,7 +576,7 @@ class EnhancedDownloadArchive:
|
||||||
if entry:
|
if entry:
|
||||||
self.mapping.add_entry(entry=entry, entry_file_path=output_file_name)
|
self.mapping.add_entry(entry=entry, entry_file_path=output_file_name)
|
||||||
|
|
||||||
self._file_handler.copy_file_to_output_directory(
|
self._file_handler.move_file_to_output_directory(
|
||||||
file_name=file_name, file_metadata=file_metadata, output_file_name=output_file_name
|
file_name=file_name, file_metadata=file_metadata, output_file_name=output_file_name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue