diff --git a/app/tests/test_dl_formats.py b/app/tests/test_dl_formats.py index c424832..6037bbe 100644 --- a/app/tests/test_dl_formats.py +++ b/app/tests/test_dl_formats.py @@ -134,6 +134,23 @@ class DlFormatsTests(unittest.TestCase): self.assertEqual(_normalize_subtitle_language(""), "en") self.assertEqual(_normalize_subtitle_language(" "), "en") + def test_subtitle_lang_list_with_region_variant_input(self): + """zh-Hans should expand to include zh base and zh-CN, zh-TW, etc.""" + from app.dl_formats import _subtitle_lang_list + result = _subtitle_lang_list("zh-Hans", include_orig=True) + self.assertEqual(result[0], "zh-Hans") # original input first + self.assertIn("zh", result) # base language fallback + self.assertIn("zh-CN", result) # regional variant + self.assertIn("zh-orig", result) # orig suffix for auto-captions + + def test_subtitle_lang_list_dedup_region_variant(self): + """pt-BR should not duplicate pt-BR in the variant expansion.""" + from app.dl_formats import _subtitle_lang_list + result = _subtitle_lang_list("pt-BR", include_orig=True) + self.assertEqual(result.count("pt-BR"), 1) # no duplicate + self.assertIn("pt", result) # base language fallback + self.assertIn("pt-PT", result) # other regional variant + if __name__ == "__main__": unittest.main() diff --git a/app/ytdl.py b/app/ytdl.py index 6552c25..fa18494 100644 --- a/app/ytdl.py +++ b/app/ytdl.py @@ -328,6 +328,7 @@ _PERSISTED_DOWNLOAD_FIELDS = ( "filename", "size", "chapter_files", + "subtitle_files", ) @@ -1494,11 +1495,23 @@ class DownloadQueue: continue if self.config.DELETE_FILE_ON_TRASHCAN: dl = self.done.get(id) - try: - dldirectory, _ = self.__calc_download_path(dl.info.download_type, dl.info.folder) - os.remove(os.path.join(dldirectory, dl.info.filename)) - except Exception as e: - log.warning(f'deleting file for download {id} failed with error message {e!r}') + dldirectory, _ = self.__calc_download_path(dl.info.download_type, dl.info.folder) + # Delete the primary downloaded file + files_to_delete = [dl.info.filename] + # Also delete chapter files and subtitle files + for cf in getattr(dl.info, 'chapter_files', []) or []: + if isinstance(cf, dict) and cf.get('filename'): + files_to_delete.append(cf['filename']) + for sf in getattr(dl.info, 'subtitle_files', []) or []: + if isinstance(sf, dict) and sf.get('filename'): + files_to_delete.append(sf['filename']) + for filename in files_to_delete: + if not filename: + continue + try: + os.remove(os.path.join(dldirectory, filename)) + except Exception as e: + log.warning(f'deleting file {filename} for download {id} failed with error message {e!r}') self.done.delete(id) await self.notifier.cleared(id) return {'status': 'ok'}