fix M3U parsing bug, adjust unit tests

This commit is contained in:
mykola2312 2024-04-22 00:03:04 +03:00
parent 9cc7f254e4
commit 62a1013cd7
4 changed files with 20 additions and 5 deletions

View file

@ -25,6 +25,6 @@ public class SourceItem {
@Nullable
public String cookies;
@Nullable
@NonNull
public String rootCategory;
}

View file

@ -50,6 +50,12 @@ public class M3UParser {
}
case URL_LINE -> {
/* there may by other tags like #EXTVLCOPT that may get in the way
so for now we're just skipping them until we hit url.
in future, if needed, we can extract user-agent from EXTVLCOPT */
if (line.startsWith("#")) {
continue;
}
String url = line;
item.url = url;

View file

@ -33,12 +33,12 @@ public class TestConfig {
"type": "m3u",
"url": "https://example.com/list.m3u",
"cookies": null,
"singleCategory": null
"rootCategory": "m3u"
},
{
"type": "m3u-local",
"path": "test.m3u8",
"singleCategory": "test"
"rootCategory": "m3u-local"
}
]
}
@ -81,14 +81,14 @@ public class TestConfig {
SourceItem m3u = config.sources.get(0);
assertEquals(SourceItem.SourceType.M3U, m3u.type);
assertEquals("https://example.com/list.m3u", m3u.url);
assertEquals("m3u", m3u.rootCategory);
assertNull(m3u.path);
assertNull(m3u.cookies);
assertNull(m3u.rootCategory);
SourceItem m3uLocal = config.sources.get(1);
assertEquals(SourceItem.SourceType.M3U_LOCAL, m3uLocal.type);
assertEquals("test.m3u8", m3uLocal.path);
assertEquals("test", m3uLocal.rootCategory);
assertEquals("m3u-local", m3uLocal.rootCategory);
assertNull(m3uLocal.url);
assertNull(m3uLocal.cookies);
}

View file

@ -18,6 +18,9 @@ http://example.org/video1.m3u8
#EXTINF:-1 group-title="test2" ,Test title 2
http://example.org/video2.m3u8
#EXTINF:-1 group-title="test3",Test title 3
#EXTVLCOPT:http-user-agent=User-Agent/1.0
http://example.org/video3.m3u8
""";
@Test
@ -36,6 +39,12 @@ http://example.org/video2.m3u8
assertEquals("test2", item.groupTitle);
assertEquals("http://example.org/video2.m3u8", item.url);
assertNull(item.tvgLogo);
item = items.get(2);
assertEquals("Test title 3", item.title);
assertEquals("test3", item.groupTitle);
assertEquals("http://example.org/video3.m3u8", item.url);
assertNull(item.tvgLogo);
}
@Test