diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java index f6b6b8bd..55a9c7c1 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSubscriptionExtractor.java @@ -63,16 +63,10 @@ public class YoutubeSubscriptionExtractor extends SubscriptionExtractor { String title = outline.attr("title"); String xmlUrl = outline.attr("abs:xmlUrl"); - if (title.isEmpty() || xmlUrl.isEmpty()) { - throw new InvalidSourceException("document has invalid entries"); - } - try { String id = Parser.matchGroup1(ID_PATTERN, xmlUrl); result.add(new SubscriptionItem(service.getServiceId(), BASE_CHANNEL_URL + id, title)); - } catch (Parser.RegexException e) { - throw new InvalidSourceException("document has invalid entries", e); - } + } catch (Parser.RegexException ignored) { /* ignore invalid subscriptions */ } } return result; diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java index 8d2e6cfa..c5739b85 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeSubscriptionExtractorTest.java @@ -59,15 +59,38 @@ public class YoutubeSubscriptionExtractorTest { assertTrue(items.isEmpty()); } + @Test + public void testSubscriptionWithEmptyTitleInSource() throws Exception { + String channelId = "AA0AaAa0AaaaAAAAAA0aa0AA"; + String source = "" + + "" + + ""; + + List items = subscriptionExtractor.fromInputStream(new ByteArrayInputStream(source.getBytes("UTF-8"))); + assertTrue("List doesn't have exactly 1 item (had " + items.size() + ")", items.size() == 1); + assertTrue("Item does not have an empty title (had \"" + items.get(0).getName() + "\")", items.get(0).getName().isEmpty()); + assertTrue("Item does not have the right channel id \"" + channelId + "\" (the whole url is \"" + items.get(0).getUrl() + "\")", items.get(0).getUrl().endsWith(channelId)); + } + + @Test + public void testSubscriptionWithInvalidUrlInSource() throws Exception { + String source = "" + + "" + + "" + + "" + + "" + + ""; + + List items = subscriptionExtractor.fromInputStream(new ByteArrayInputStream(source.getBytes("UTF-8"))); + assertTrue(items.isEmpty()); + } + @Test public void testInvalidSourceException() { List invalidList = Arrays.asList( "", "", "", - "", - "", "", null, "\uD83D\uDC28\uD83D\uDC28\uD83D\uDC28", @@ -78,11 +101,11 @@ public class YoutubeSubscriptionExtractorTest { if (invalidContent != null) { byte[] bytes = invalidContent.getBytes("UTF-8"); subscriptionExtractor.fromInputStream(new ByteArrayInputStream(bytes)); + fail("Extracting from \"" + invalidContent + "\" didn't throw an exception"); } else { subscriptionExtractor.fromInputStream(null); + fail("Extracting from null String didn't throw an exception"); } - - fail("didn't throw exception"); } catch (Exception e) { // System.out.println(" -> " + e); boolean isExpectedException = e instanceof SubscriptionExtractor.InvalidSourceException;