mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
Not showing files that will not be moved during collection reorganization preview. Adding button to mark collection as reorganized when no files need to be reorganized.
This commit is contained in:
parent
99a716aa13
commit
298a67159a
3 changed files with 96 additions and 5 deletions
|
|
@ -374,7 +374,10 @@ export function CollectionReorganizeModal({
|
|||
<Grid.Column>
|
||||
<Message info>
|
||||
<Message.Header>No Files Need Reorganization</Message.Header>
|
||||
<p>All files are already organized according to the current format.</p>
|
||||
<p>
|
||||
All files are already organized according to the current format.
|
||||
{needsReorganization && ' Click "Mark as Organized" to dismiss the warning.'}
|
||||
</p>
|
||||
</Message>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
|
|
@ -422,6 +425,7 @@ export function CollectionReorganizeModal({
|
|||
const isInProgress = polling || (status && status.status !== 'complete' && status.status !== 'error');
|
||||
const hasConflicts = preview && preview.has_conflicts;
|
||||
const canReorganize = preview && preview.files_needing_move > 0 && !isInProgress && !jobId && !hasConflicts;
|
||||
const canMarkAsOrganized = preview && preview.files_needing_move === 0 && needsReorganization && !isInProgress && !jobId;
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
@ -470,6 +474,15 @@ export function CollectionReorganizeModal({
|
|||
Reorganize Files
|
||||
</APIButton>
|
||||
)}
|
||||
{canMarkAsOrganized && (
|
||||
<APIButton
|
||||
color='green'
|
||||
onClick={handleReorganize}
|
||||
obeyWROLMode={true}
|
||||
>
|
||||
Mark as Organized
|
||||
</APIButton>
|
||||
)}
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
|
||||
|
|
|
|||
|
|
@ -395,7 +395,8 @@ def get_batch_reorganization_preview(
|
|||
if sample_video and sample_video.file_group and sample_video.file_group.primary_path:
|
||||
current_path = pathlib.Path(sample_video.file_group.primary_path)
|
||||
new_path = _compute_new_path_for_video(sample_video, collection_directory)
|
||||
if new_path and current_path != new_path:
|
||||
# Compare resolved paths to handle symlinks and path normalization
|
||||
if new_path and current_path.resolve() != new_path.resolve():
|
||||
try:
|
||||
old_relative = str(current_path.relative_to(media_dir))
|
||||
except ValueError:
|
||||
|
|
@ -420,7 +421,8 @@ def get_batch_reorganization_preview(
|
|||
if sample_archive and sample_archive.file_group and sample_archive.file_group.primary_path:
|
||||
current_path = pathlib.Path(sample_archive.file_group.primary_path)
|
||||
new_path = _compute_new_path_for_archive(sample_archive, collection_directory)
|
||||
if new_path and current_path != new_path:
|
||||
# Compare resolved paths to handle symlinks and path normalization
|
||||
if new_path and current_path.resolve() != new_path.resolve():
|
||||
try:
|
||||
old_relative = str(current_path.relative_to(media_dir))
|
||||
except ValueError:
|
||||
|
|
@ -473,7 +475,8 @@ def _build_move_mappings_for_channel(
|
|||
current_path = pathlib.Path(video.file_group.primary_path)
|
||||
new_path = _compute_new_path_for_video(video, collection_directory)
|
||||
|
||||
if new_path and current_path != new_path:
|
||||
# Compare resolved paths to handle symlinks and path normalization
|
||||
if new_path and current_path.resolve() != new_path.resolve():
|
||||
move_mappings.append((current_path, new_path))
|
||||
|
||||
return move_mappings
|
||||
|
|
@ -502,7 +505,8 @@ def _build_move_mappings_for_domain(
|
|||
current_path = pathlib.Path(archive.file_group.primary_path)
|
||||
new_path = _compute_new_path_for_archive(archive, collection_directory)
|
||||
|
||||
if new_path and current_path != new_path:
|
||||
# Compare resolved paths to handle symlinks and path normalization
|
||||
if new_path and current_path.resolve() != new_path.resolve():
|
||||
move_mappings.append((current_path, new_path))
|
||||
|
||||
return move_mappings
|
||||
|
|
|
|||
|
|
@ -2534,3 +2534,77 @@ def test_format_video_filename_fallback_behavior(
|
|||
for forbidden in should_not_contain:
|
||||
assert forbidden not in result, f"Should NOT contain '{forbidden}'. Got: {result}"
|
||||
|
||||
|
||||
def test_preview_excludes_files_already_in_correct_location(test_session, test_directory, video_factory):
|
||||
"""Files already in the correct location should not appear in preview or be counted as needing move.
|
||||
|
||||
This tests that when a video's current path matches the computed new path, it is excluded from:
|
||||
- files_needing_move count
|
||||
- sample_moves list
|
||||
"""
|
||||
from modules.videos.lib import get_videos_downloader_config, format_video_filename
|
||||
|
||||
# Set up a simple format using the correct nested config structure
|
||||
config = get_videos_downloader_config()
|
||||
original_format = config._config['yt_dlp_options']['file_name_format']
|
||||
|
||||
# Use simple title-only format for predictability
|
||||
yt_dlp_options = dict(config._config['yt_dlp_options'])
|
||||
yt_dlp_options['file_name_format'] = '%(title)s.%(ext)s'
|
||||
config._config['yt_dlp_options'] = yt_dlp_options
|
||||
|
||||
try:
|
||||
# Create channel collection
|
||||
channel_dir = test_directory / 'videos' / 'CorrectLocationChannel'
|
||||
channel_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
with get_db_session(commit=True) as session:
|
||||
collection = Collection(
|
||||
name='CorrectLocationChannel',
|
||||
kind='channel',
|
||||
directory=channel_dir,
|
||||
file_format='%(old_format)s.%(ext)s' # Different from config, so needs_reorganization=True
|
||||
)
|
||||
session.add(collection)
|
||||
session.flush()
|
||||
channel = Channel(name='CorrectLocationChannel', collection_id=collection.id, directory=channel_dir)
|
||||
session.add(channel)
|
||||
session.commit()
|
||||
channel_id = channel.id
|
||||
collection_id = collection.id
|
||||
|
||||
# Create a video with a simple title (no special characters)
|
||||
# The video_factory will place it at channel_dir/SimpleTitle.mp4
|
||||
video = video_factory(
|
||||
channel_id=channel_id,
|
||||
title='SimpleTitle',
|
||||
with_video_file=True,
|
||||
)
|
||||
|
||||
# Verify the video is at the expected location
|
||||
with get_db_session() as session:
|
||||
video_obj = session.query(Video).get(video.id)
|
||||
current_path = video_obj.file_group.primary_path
|
||||
|
||||
# The format_video_filename should produce the same filename
|
||||
expected_filename = format_video_filename(video_obj, '%(title)s.%(ext)s')
|
||||
expected_path = channel_dir / expected_filename
|
||||
|
||||
# Paths should match (this is the precondition for our test)
|
||||
assert str(current_path) == str(expected_path), \
|
||||
f"Test setup error: paths don't match. Current: {current_path}, Expected: {expected_path}"
|
||||
|
||||
# Now get the preview - the file should NOT need moving
|
||||
with get_db_session() as session:
|
||||
preview = get_reorganization_preview(collection_id, session)
|
||||
|
||||
# Since the file is already in the correct location, it should NOT be in the preview
|
||||
assert preview.files_needing_move == 0, \
|
||||
f"File already in correct location should not need moving. Got {preview.files_needing_move} files needing move"
|
||||
assert len(preview.sample_moves) == 0, \
|
||||
f"File already in correct location should not appear in sample_moves. Got: {preview.sample_moves}"
|
||||
|
||||
finally:
|
||||
yt_dlp_options = dict(config._config['yt_dlp_options'])
|
||||
yt_dlp_options['file_name_format'] = original_format
|
||||
config._config['yt_dlp_options'] = yt_dlp_options
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue