Skip to content

Commit f4404b5

Browse files
committed
Add tests for more reasons
1 parent fc99858 commit f4404b5

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,13 @@ public static void defaultAlertsCheck(final JsonObject initialData) throws Parsi
764764
|| alertText.contains("infringement")) {
765765
// possible error messages:
766766
// "This account has been terminated for a violation of YouTube's Terms of Service."
767+
// "This account has been terminated due to multiple or severe violations of YouTube's policy prohibiting hate speech."
768+
// "This account has been terminated due to multiple or severe violations of YouTube's policy prohibiting content designed to harass, bully or threaten."
769+
// "This account has been terminated due to multiple or severe violations of YouTube's policy against spam, deceptive practices and misleading content or other Terms of Service violations."
770+
// "This account has been terminated due to multiple or severe violations of YouTube's policy on nudity or sexual content."
767771
// "This account has been terminated for violating YouTube's Community Guidelines."
768772
// "This account has been terminated because we received multiple third-party claims of copyright infringement regarding material that the user posted."
773+
// "This account has been terminated because it is linked to an account that received multiple third-party claims of copyright infringement."
769774
throw new AccountTerminatedException(alertText, AccountTerminatedException.Reason.VIOLATION);
770775
} else {
771776
throw new AccountTerminatedException(alertText);

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package org.schabi.newpipe.extractor.services.youtube;
22

3+
import com.grack.nanojson.JsonArray;
4+
import com.grack.nanojson.JsonObject;
5+
import com.grack.nanojson.JsonParser;
36
import org.junit.BeforeClass;
47
import org.junit.Test;
58
import org.schabi.newpipe.downloader.DownloaderFactory;
69
import org.schabi.newpipe.downloader.DownloaderTestImpl;
10+
import org.schabi.newpipe.extractor.Extractor;
711
import org.schabi.newpipe.extractor.NewPipe;
812
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
913
import org.schabi.newpipe.extractor.exceptions.AccountTerminatedException;
@@ -12,6 +16,7 @@
1216
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1317
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
1418
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelExtractor;
19+
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
1520

1621
import java.io.IOException;
1722
import java.util.Random;
@@ -80,6 +85,48 @@ public void accountTerminatedCommunityFetch() throws Exception {
8085
}
8186
}
8287

88+
@Test(expected = AccountTerminatedException.class)
89+
public void accountTerminatedHateFetch() throws Exception {
90+
final ChannelExtractor extractor =
91+
YouTube.getChannelExtractor("https://www.youtube.com/channel/UCPWXIOPK-9myzek6jHR5yrg");
92+
try {
93+
extractor.fetchPage();
94+
} catch (AccountTerminatedException e) {
95+
assertTrue(e.getMessage().contains(
96+
"This account has been terminated due to multiple or severe violations of YouTube's policy prohibiting hate speech."));
97+
assertEquals(e.getReason(), AccountTerminatedException.Reason.VIOLATION);
98+
throw e;
99+
}
100+
}
101+
102+
@Test(expected = AccountTerminatedException.class)
103+
public void accountTerminatedBullyFetch() throws Exception {
104+
final ChannelExtractor extractor =
105+
YouTube.getChannelExtractor("https://youtube.com/channel/UCB1o7_gbFp2PLsamWxFenBg");
106+
try {
107+
extractor.fetchPage();
108+
} catch (AccountTerminatedException e) {
109+
assertEquals(e.getMessage(),
110+
"This account has been terminated due to multiple or severe violations of YouTube's policy prohibiting content designed to harass, bully or threaten.");
111+
assertEquals(e.getReason(), AccountTerminatedException.Reason.VIOLATION);
112+
throw e;
113+
}
114+
}
115+
116+
@Test(expected = AccountTerminatedException.class)
117+
public void accountTerminatedSpamFetch() throws Exception {
118+
final ChannelExtractor extractor =
119+
YouTube.getChannelExtractor("https://www.youtube.com/channel/UCoaO4U_p7G7AwalqSbGCZOA");
120+
try {
121+
extractor.fetchPage();
122+
} catch (AccountTerminatedException e) {
123+
assertEquals(e.getMessage(),
124+
"This account has been terminated due to multiple or severe violations of YouTube's policy against spam, deceptive practices and misleading content or other Terms of Service violations.");
125+
assertEquals(e.getReason(), AccountTerminatedException.Reason.VIOLATION);
126+
throw e;
127+
}
128+
}
129+
83130
@Test(expected = AccountTerminatedException.class)
84131
public void accountTerminatedCopyrightFetch() throws Exception {
85132
final ChannelExtractor extractor =

0 commit comments

Comments
 (0)