mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-25 06:26:37 +00:00
Use private directory_and_stem
function
This commit is contained in:
parent
5c2dfca00f
commit
24105db5cb
@ -10,3 +10,11 @@ def _nfo_element(nfo, label, text, /, *, attrs={}, tail='\n', char=' ', indent=2
|
|||||||
element.tail = tail + (char * indent)
|
element.tail = tail + (char * indent)
|
||||||
return element
|
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,)
|
||||||
|
|
||||||
|
@ -25,8 +25,7 @@ from ..youtube import (
|
|||||||
)
|
)
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
seconds_to_timestr, parse_media_format, filter_response,
|
seconds_to_timestr, parse_media_format, filter_response,
|
||||||
write_text_file, mkdir_p, directory_and_stem, glob_quote,
|
write_text_file, mkdir_p, glob_quote, multi_key_sort,
|
||||||
multi_key_sort,
|
|
||||||
)
|
)
|
||||||
from ..matching import (
|
from ..matching import (
|
||||||
get_best_combined_format,
|
get_best_combined_format,
|
||||||
@ -39,7 +38,7 @@ from ..choices import (
|
|||||||
from ._migrations import (
|
from ._migrations import (
|
||||||
media_file_storage, get_media_thumb_path, get_media_file_path,
|
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 (
|
from .media__tasks import (
|
||||||
download_checklist, download_finished, wait_for_premiere,
|
download_checklist, download_finished, wait_for_premiere,
|
||||||
)
|
)
|
||||||
@ -1152,7 +1151,7 @@ class Media(models.Model):
|
|||||||
|
|
||||||
# collect the list of files to move
|
# collect the list of files to move
|
||||||
# this should not include the video we just moved
|
# this should not include the video we just moved
|
||||||
(old_prefix_path, old_stem) = directory_and_stem(old_video_path, only_once=True)
|
(old_prefix_path, old_stem) = directory_and_stem(old_video_path)
|
||||||
other_paths = list(old_prefix_path.glob(glob_quote(old_stem) + '*'))
|
other_paths = list(old_prefix_path.glob(glob_quote(old_stem) + '*'))
|
||||||
log.info(f'Collected {len(other_paths)} other paths for: {self!s}')
|
log.info(f'Collected {len(other_paths)} other paths for: {self!s}')
|
||||||
|
|
||||||
@ -1172,7 +1171,7 @@ class Media(models.Model):
|
|||||||
self.save(update_fields=('media_file', 'skip'))
|
self.save(update_fields=('media_file', 'skip'))
|
||||||
log.info(f'Updated "media_file" in the database for: {self!s}')
|
log.info(f'Updated "media_file" in the database for: {self!s}')
|
||||||
|
|
||||||
(new_prefix_path, new_stem) = directory_and_stem(new_video_path, only_once=True)
|
(new_prefix_path, new_stem) = directory_and_stem(new_video_path)
|
||||||
|
|
||||||
# move and change names to match stem
|
# move and change names to match stem
|
||||||
for other_path in other_paths:
|
for other_path in other_paths:
|
||||||
@ -1193,7 +1192,7 @@ class Media(models.Model):
|
|||||||
other_path.replace(new_file_path)
|
other_path.replace(new_file_path)
|
||||||
|
|
||||||
for fuzzy_path in fuzzy_paths:
|
for fuzzy_path in fuzzy_paths:
|
||||||
(fuzzy_prefix_path, fuzzy_stem) = directory_and_stem(fuzzy_path, only_once=False)
|
(fuzzy_prefix_path, fuzzy_stem) = directory_and_stem(fuzzy_path, True)
|
||||||
old_file_str = fuzzy_path.name
|
old_file_str = fuzzy_path.name
|
||||||
new_file_str = new_stem + old_file_str[len(fuzzy_stem):]
|
new_file_str = new_stem + old_file_str[len(fuzzy_stem):]
|
||||||
new_file_path = Path(new_prefix_path / new_file_str)
|
new_file_path = Path(new_prefix_path / new_file_str)
|
||||||
|
@ -130,15 +130,6 @@ def file_is_editable(filepath):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def directory_and_stem(arg_path, /, *, only_once=True):
|
|
||||||
filepath = Path(arg_path)
|
|
||||||
stem = Path(filepath.stem)
|
|
||||||
while not only_once and stem.suffixes and '' != stem.suffix:
|
|
||||||
stem = Path(stem.stem)
|
|
||||||
stem = str(stem)
|
|
||||||
return (filepath.parent, stem,)
|
|
||||||
|
|
||||||
|
|
||||||
def mkdir_p(arg_path, mode=0o777):
|
def mkdir_p(arg_path, mode=0o777):
|
||||||
'''
|
'''
|
||||||
Reminder: mode only affects the last directory
|
Reminder: mode only affects the last directory
|
||||||
|
Loading…
Reference in New Issue
Block a user