Fix anipy fallback episode numbering
Use the queued episode spec when finalizing anipy-cli fallback TV downloads so retries keep the requested episode numbers instead of being renumbered from 1, and update tests plus release docs for the fix.
This commit is contained in:
+27
-1
@@ -1076,6 +1076,26 @@ def extract_episode_from_filename(path):
|
||||
return match.group(1) if match else None
|
||||
|
||||
|
||||
def episode_values_from_spec(value):
|
||||
spec = str(value or "").strip()
|
||||
if not spec:
|
||||
return []
|
||||
values = []
|
||||
for part in re.split(r"\s+", spec):
|
||||
if not part:
|
||||
continue
|
||||
if "-" in part:
|
||||
start_text, end_text = [piece.strip() for piece in part.split("-", 1)]
|
||||
if start_text.isdigit() and end_text.isdigit():
|
||||
start = int(start_text, 10)
|
||||
end = int(end_text, 10)
|
||||
if start <= end:
|
||||
values.extend(str(number) for number in range(start, end + 1))
|
||||
continue
|
||||
values.append(part)
|
||||
return values
|
||||
|
||||
|
||||
def unique_destination(path):
|
||||
if not path.exists():
|
||||
return path
|
||||
@@ -1104,11 +1124,17 @@ def finalize_library_files(job):
|
||||
|
||||
moved = []
|
||||
fallback_episode = 1
|
||||
requested_episode_values = episode_values_from_spec(job.get("episodes"))
|
||||
backend = str(job.get("download_backend") or "").strip().lower()
|
||||
for source in files:
|
||||
if media_type == "movie":
|
||||
final_name = f"{library_name}{source.suffix}"
|
||||
else:
|
||||
ep = extract_episode_from_filename(source)
|
||||
ep = None
|
||||
if backend == "anipy-cli" and requested_episode_values:
|
||||
ep = requested_episode_values.pop(0)
|
||||
if ep is None:
|
||||
ep = extract_episode_from_filename(source)
|
||||
if ep is None:
|
||||
ep = str(fallback_episode)
|
||||
fallback_episode += 1
|
||||
|
||||
Reference in New Issue
Block a user