@@ -1641,7 +1641,7 @@ def fake_download(*, info, info_dict, logs):
16411641 assert result == {"status" : "ok" }
16421642 assert seen == [entry ]
16431643
1644- def test_extract_config_strips_subtitles (self ) -> None :
1644+ def test_extract_no_subs (self ) -> None :
16451645 from app .library .downloads .item_adder import _extract_config
16461646
16471647 config = {
@@ -1669,7 +1669,7 @@ def test_extract_config_strips_subtitles(self) -> None:
16691669 assert stripped ["postprocessors" ] == [{"key" : "FFmpegMetadata" }]
16701670
16711671 @pytest .mark .asyncio
1672- async def test_light_extract_reextracts (self , monkeypatch : pytest .MonkeyPatch ) -> None :
1672+ async def test_light_reextracts (self , monkeypatch : pytest .MonkeyPatch ) -> None :
16731673 from app .library .downloads .video_processor import LIGHT_EXTRACT_KEY
16741674
16751675 seen : list [dict | None ] = []
@@ -1695,7 +1695,7 @@ def fake_download(*, info, info_dict, logs):
16951695 assert seen == [None ]
16961696
16971697 @pytest .mark .asyncio
1698- async def test_add_strips_subtitle_extract (self , monkeypatch : pytest .MonkeyPatch ) -> None :
1698+ async def test_yt_no_subs (self , monkeypatch : pytest .MonkeyPatch ) -> None :
16991699 from app .library .downloads import item_adder
17001700 from app .library .downloads .video_processor import LIGHT_EXTRACT_KEY
17011701
@@ -1721,7 +1721,7 @@ def get_all(self):
17211721 }
17221722
17231723 item = Item (
1724- url = "https://example.test/ video" ,
1724+ url = "https://www.youtube.com/watch?v= video-id " ,
17251725 preset = "default" ,
17261726 folder = "" ,
17271727 cookies = "" ,
@@ -1734,6 +1734,7 @@ def get_all(self):
17341734 monkeypatch .setattr (item , "get_archive_id" , lambda : None )
17351735 monkeypatch .setattr (item , "is_archived" , lambda : False )
17361736 monkeypatch .setattr (item , "get_archive_file" , lambda : None )
1737+ monkeypatch .setattr (item , "get_extractor" , lambda : "Youtube" )
17371738 queue = self ._video_queue ()
17381739 queue .config .ytdlp_debug = False
17391740 queue .config .ignore_archived_items = False
@@ -1752,6 +1753,98 @@ def get_all(self):
17521753 assert seen_config == [{"format" : "bv*+ba/b" , "sleep_interval_requests" : 3.0 }]
17531754 assert seen_entry [0 ][LIGHT_EXTRACT_KEY ] is True
17541755
1756+ @pytest .mark .asyncio
1757+ async def test_yt_url_no_subs (self , monkeypatch : pytest .MonkeyPatch ) -> None :
1758+ from app .library .downloads import item_adder
1759+ from app .library .downloads .video_processor import LIGHT_EXTRACT_KEY
1760+
1761+ seen_config : list [dict ] = []
1762+ seen_entry : list [dict ] = []
1763+
1764+ async def fake_fetch_info (* , config , ** kwargs ): # noqa: ARG001
1765+ seen_config .append (config )
1766+ return ({"id" : "video-id" , "title" : "Video" , "_type" : "video" , "formats" : [{"format_id" : "18" }]}, [])
1767+
1768+ async def fake_add_video (* , queue , entry , item , logs ): # noqa: ARG001
1769+ seen_entry .append (entry )
1770+ return {"status" : "ok" }
1771+
1772+ class Opts :
1773+ def get_all (self ):
1774+ return {"format" : "bv*+ba/b" , "writeautomaticsub" : True , "subtitleslangs" : ["fr.*" ]}
1775+
1776+ item = Item (url = "https://youtu.be/video-id" , preset = "default" )
1777+ monkeypatch .setattr (item , "get_ytdlp_opts" , lambda : Opts ())
1778+ monkeypatch .setattr (item , "get_archive_id" , lambda : None )
1779+ monkeypatch .setattr (item , "is_archived" , lambda : False )
1780+ monkeypatch .setattr (item , "get_archive_file" , lambda : None )
1781+ monkeypatch .setattr (item , "get_extractor" , lambda : None )
1782+ queue = self ._video_queue ()
1783+ queue .config .ytdlp_debug = False
1784+ queue .config .ignore_archived_items = False
1785+
1786+ monkeypatch .setattr (item_adder , "fetch_info" , fake_fetch_info )
1787+ monkeypatch .setattr (item_adder , "add_video" , fake_add_video )
1788+ monkeypatch .setattr (
1789+ item_adder .Conditions ,
1790+ "get_instance" ,
1791+ classmethod (lambda cls : SimpleNamespace (match = AsyncMock (return_value = None ))),
1792+ )
1793+
1794+ result = await item_adder .add (queue = queue , item = item )
1795+
1796+ assert result == {"status" : "ok" }
1797+ assert seen_config == [{"format" : "bv*+ba/b" }]
1798+ assert seen_entry [0 ][LIGHT_EXTRACT_KEY ] is True
1799+
1800+ @pytest .mark .asyncio
1801+ async def test_non_yt_keeps_subs (self , monkeypatch : pytest .MonkeyPatch ) -> None :
1802+ from app .library .downloads import item_adder
1803+ from app .library .downloads .video_processor import LIGHT_EXTRACT_KEY
1804+
1805+ seen_config : list [dict ] = []
1806+ seen_entry : list [dict ] = []
1807+
1808+ async def fake_fetch_info (* , config , ** kwargs ): # noqa: ARG001
1809+ seen_config .append (config )
1810+ return ({"id" : "video-id" , "title" : "Video" , "_type" : "video" , "formats" : [{"format_id" : "18" }]}, [])
1811+
1812+ async def fake_add_video (* , queue , entry , item , logs ): # noqa: ARG001
1813+ seen_entry .append (entry )
1814+ return {"status" : "ok" }
1815+
1816+ class Opts :
1817+ def get_all (self ):
1818+ return {
1819+ "format" : "bv*+ba/b" ,
1820+ "writeautomaticsub" : True ,
1821+ "subtitleslangs" : ["fr.*" ],
1822+ }
1823+
1824+ item = Item (url = "https://example.test/video" , preset = "default" )
1825+ monkeypatch .setattr (item , "get_ytdlp_opts" , lambda : Opts ())
1826+ monkeypatch .setattr (item , "get_archive_id" , lambda : None )
1827+ monkeypatch .setattr (item , "is_archived" , lambda : False )
1828+ monkeypatch .setattr (item , "get_archive_file" , lambda : None )
1829+ monkeypatch .setattr (item , "get_extractor" , lambda : "Generic" )
1830+ queue = self ._video_queue ()
1831+ queue .config .ytdlp_debug = False
1832+ queue .config .ignore_archived_items = False
1833+
1834+ monkeypatch .setattr (item_adder , "fetch_info" , fake_fetch_info )
1835+ monkeypatch .setattr (item_adder , "add_video" , fake_add_video )
1836+ monkeypatch .setattr (
1837+ item_adder .Conditions ,
1838+ "get_instance" ,
1839+ classmethod (lambda cls : SimpleNamespace (match = AsyncMock (return_value = None ))),
1840+ )
1841+
1842+ result = await item_adder .add (queue = queue , item = item )
1843+
1844+ assert result == {"status" : "ok" }
1845+ assert seen_config == [{"format" : "bv*+ba/b" , "writeautomaticsub" : True , "subtitleslangs" : ["fr.*" ]}]
1846+ assert LIGHT_EXTRACT_KEY not in seen_entry [0 ]
1847+
17551848 @pytest .mark .asyncio
17561849 async def test_cleanup_thumbnails (self , tmp_path : Path ) -> None :
17571850 from app .library .downloads .monitors import cleanup_thumbnails
0 commit comments