Skip to content

Commit 701666f

Browse files
committed
block yt premium videos
fix logig error for block yt premium videos
1 parent dcca11f commit 701666f

2 files changed

Lines changed: 111 additions & 1 deletion

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamInfoItemExtractor.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ public StreamType getStreamType() throws ParsingException {
4545
@Override
4646
public boolean isAd() throws ParsingException {
4747
return !item.select("span[class*=\"icon-not-available\"]").isEmpty()
48-
|| !item.select("span[class*=\"yt-badge-ad\"]").isEmpty();
48+
|| !item.select("span[class*=\"yt-badge-ad\"]").isEmpty()
49+
|| isPremiumVideo();
50+
}
51+
52+
private boolean isPremiumVideo() {
53+
Element premiumSpan = item.select("span[class=\"standalone-collection-badge-renderer-red-text\"]").first();
54+
if(premiumSpan == null) return false;
55+
56+
// if this span has text it most likely says ("Free Video") so we can play this
57+
if(premiumSpan.hasText()) return false;
58+
return true;
4959
}
5060

5161
@Override
@@ -119,6 +129,9 @@ public String getUploadDate() throws ParsingException {
119129
Element meta = item.select("div[class=\"yt-lockup-meta\"]").first();
120130
if (meta == null) return "";
121131

132+
Element li = meta.select("li").first();
133+
if(li == null) return "";
134+
122135
return meta.select("li").first().text();
123136
} catch (Exception e) {
124137
throw new ParsingException("Could not get upload date", e);

extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeChannelExtractorTest.java

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,103 @@ public void testChannelDonation() throws Exception {
114114
}
115115
}
116116

117+
// Youtube RED/Premium ad blocking test
118+
public static class VSauce implements BaseChannelExtractorTest {
119+
private static YoutubeChannelExtractor extractor;
120+
121+
@BeforeClass
122+
public static void setUp() throws Exception {
123+
NewPipe.init(Downloader.getInstance());
124+
extractor = (YoutubeChannelExtractor) YouTube
125+
.getChannelExtractor("https://www.youtube.com/user/Vsauce");
126+
extractor.fetchPage();
127+
}
128+
129+
/*//////////////////////////////////////////////////////////////////////////
130+
// Extractor
131+
//////////////////////////////////////////////////////////////////////////*/
132+
133+
@Test
134+
public void testServiceId() {
135+
assertEquals(YouTube.getServiceId(), extractor.getServiceId());
136+
}
137+
138+
@Test
139+
public void testName() throws Exception {
140+
assertEquals("Vsauce", extractor.getName());
141+
}
142+
143+
@Test
144+
public void testId() throws Exception {
145+
assertEquals("UC6nSFpj9HTCZ5t-N3Rm3-HA", extractor.getId());
146+
}
147+
148+
@Test
149+
public void testUrl() throws ParsingException {
150+
assertEquals("https://www.youtube.com/channel/UC6nSFpj9HTCZ5t-N3Rm3-HA", extractor.getUrl());
151+
}
152+
153+
@Test
154+
public void testOriginalUrl() throws ParsingException {
155+
assertEquals("https://www.youtube.com/user/Vsauce", extractor.getOriginalUrl());
156+
}
157+
158+
/*//////////////////////////////////////////////////////////////////////////
159+
// ListExtractor
160+
//////////////////////////////////////////////////////////////////////////*/
161+
162+
@Test
163+
public void testRelatedItems() throws Exception {
164+
defaultTestRelatedItems(extractor, YouTube.getServiceId());
165+
}
166+
167+
@Test
168+
public void testMoreRelatedItems() throws Exception {
169+
defaultTestMoreItems(extractor, ServiceList.YouTube.getServiceId());
170+
}
171+
172+
/*//////////////////////////////////////////////////////////////////////////
173+
// ChannelExtractor
174+
//////////////////////////////////////////////////////////////////////////*/
175+
176+
@Test
177+
public void testDescription() throws Exception {
178+
assertTrue("What it actually was: " + extractor.getDescription(),
179+
extractor.getDescription().contains("Our World is Amazing. Questions? Ideas? Tweet me:"));
180+
}
181+
182+
@Test
183+
public void testAvatarUrl() throws Exception {
184+
String avatarUrl = extractor.getAvatarUrl();
185+
assertIsSecureUrl(avatarUrl);
186+
assertTrue(avatarUrl, avatarUrl.contains("yt3"));
187+
}
188+
189+
@Test
190+
public void testBannerUrl() throws Exception {
191+
String bannerUrl = extractor.getBannerUrl();
192+
assertIsSecureUrl(bannerUrl);
193+
assertTrue(bannerUrl, bannerUrl.contains("yt3"));
194+
}
195+
196+
@Test
197+
public void testFeedUrl() throws Exception {
198+
assertEquals("https://www.youtube.com/feeds/videos.xml?channel_id=UC6nSFpj9HTCZ5t-N3Rm3-HA", extractor.getFeedUrl());
199+
}
200+
201+
@Test
202+
public void testSubscriberCount() throws Exception {
203+
assertTrue("Wrong subscriber count", extractor.getSubscriberCount() >= 0);
204+
}
205+
206+
@Test
207+
public void testChannelDonation() throws Exception {
208+
// this needs to be ignored since wed have to upgrade channel extractor to the new yt interface
209+
// in order to make this work
210+
assertTrue(extractor.getDonationLinks().length == 0);
211+
}
212+
}
213+
117214
public static class Kurzgesagt implements BaseChannelExtractorTest {
118215
private static YoutubeChannelExtractor extractor;
119216

0 commit comments

Comments
 (0)