diff --git a/app/ytdl.py b/app/ytdl.py index 61adfcd..84ac070 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -144,7 +144,21 @@ class Download: def put_status_postprocessor(d): if d['postprocessor'] == 'MoveFiles' and d['status'] == 'finished': - filename = d['info_dict']['filepath'] + filepath = d['info_dict']['filepath'] + if '__finaldir' in d['info_dict']: + finaldir = d['info_dict']['__finaldir'] + # Compute relative path from temp dir to preserve + # subdirectory structure from the output template. + try: + rel_path = os.path.relpath(filepath, self.temp_dir) + except ValueError: + rel_path = os.path.basename(filepath) + if rel_path.startswith('..'): + # filepath is not under temp_dir, fall back to basename + rel_path = os.path.basename(filepath) + filename = os.path.join(finaldir, rel_path) + else: + filename = filepath self.status_queue.put({'status': 'finished', 'filename': filename}) # Capture all chapter files when SplitChapters finishes