Merge pull request #1054 from tcely/patch-6

Renaming was removing too many extensions
This commit is contained in:
meeb 2025-05-23 01:18:50 +10:00 committed by GitHub
commit 19a3e5f34c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 13 deletions

View File

@ -1,3 +1,4 @@
from pathlib import Path
from ..choices import Val, YouTube_SourceType # noqa
@ -10,3 +11,11 @@ def _nfo_element(nfo, label, text, /, *, attrs={}, tail='\n', char=' ', indent=2
element.tail = tail + (char * indent)
return element
def directory_and_stem(arg_path, /, all_suffixes=False):
filepath = Path(arg_path)
stem = Path(filepath.stem)
while all_suffixes and stem.suffixes and '' != stem.suffix:
stem = Path(stem.stem)
stem = str(stem)
return (filepath.parent, stem,)

View File

@ -25,8 +25,7 @@ from ..youtube import (
)
from ..utils import (
seconds_to_timestr, parse_media_format, filter_response,
write_text_file, mkdir_p, directory_and_stem, glob_quote,
multi_key_sort,
write_text_file, mkdir_p, glob_quote, multi_key_sort,
)
from ..matching import (
get_best_combined_format,
@ -39,7 +38,7 @@ from ..choices import (
from ._migrations import (
media_file_storage, get_media_thumb_path, get_media_file_path,
)
from ._private import _srctype_dict, _nfo_element
from ._private import _srctype_dict, _nfo_element, directory_and_stem
from .media__tasks import (
download_checklist, download_finished, wait_for_premiere,
)
@ -1193,7 +1192,7 @@ class Media(models.Model):
other_path.replace(new_file_path)
for fuzzy_path in fuzzy_paths:
(fuzzy_prefix_path, fuzzy_stem) = directory_and_stem(fuzzy_path)
(fuzzy_prefix_path, fuzzy_stem) = directory_and_stem(fuzzy_path, True)
old_file_str = fuzzy_path.name
new_file_str = new_stem + old_file_str[len(fuzzy_stem):]
new_file_path = Path(new_prefix_path / new_file_str)

View File

@ -130,15 +130,6 @@ def file_is_editable(filepath):
return False
def directory_and_stem(arg_path):
filepath = Path(arg_path)
stem = Path(filepath.stem)
while stem.suffixes and '' != stem.suffix:
stem = Path(stem.stem)
stem = str(stem)
return (filepath.parent, stem,)
def mkdir_p(arg_path, mode=0o777):
'''
Reminder: mode only affects the last directory