File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111import org .schabi .newpipe .extractor .NewPipe ;
1212import org .schabi .newpipe .extractor .StreamingService ;
1313import org .schabi .newpipe .extractor .downloader .Downloader ;
14+ import org .schabi .newpipe .extractor .exceptions .ContentNotAvailableException ;
1415import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
1516import org .schabi .newpipe .extractor .exceptions .ParsingException ;
1617import org .schabi .newpipe .extractor .exceptions .ReCaptchaException ;
3233import org .schabi .newpipe .extractor .stream .StreamType ;
3334import org .schabi .newpipe .extractor .stream .SubtitlesStream ;
3435import org .schabi .newpipe .extractor .stream .VideoStream ;
36+ import org .schabi .newpipe .extractor .utils .JsonUtils ;
3537import org .schabi .newpipe .extractor .utils .Parser ;
3638import org .schabi .newpipe .extractor .utils .Utils ;
3739
@@ -619,6 +621,13 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
619621
620622 playerResponse = getPlayerResponse ();
621623
624+ final JsonObject playabilityStatus = playerResponse .getObject ("playabilityStatus" , JsonUtils .DEFAULT_EMPTY );
625+ final String status = playabilityStatus .getString ("status" );
626+ if (status != null && status .toLowerCase ().equals ("error" )) {
627+ final String reason = playabilityStatus .getString ("reason" );
628+ throw new ContentNotAvailableException ("Got error: \" " + reason + "\" " );
629+ }
630+
622631 if (decryptionCode .isEmpty ()) {
623632 decryptionCode = loadDecryptionCode (playerUrl );
624633 }
Original file line number Diff line number Diff line change 1111import java .util .List ;
1212
1313public class JsonUtils {
14+ public static final JsonObject DEFAULT_EMPTY = new JsonObject ();
1415
1516 private JsonUtils () {
1617 }
Original file line number Diff line number Diff line change 77import org .schabi .newpipe .extractor .ExtractorAsserts ;
88import org .schabi .newpipe .extractor .MediaFormat ;
99import org .schabi .newpipe .extractor .NewPipe ;
10+ import org .schabi .newpipe .extractor .exceptions .ContentNotAvailableException ;
1011import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
1112import org .schabi .newpipe .extractor .exceptions .ParsingException ;
1213import org .schabi .newpipe .extractor .services .youtube .extractors .YoutubeStreamExtractor ;
5657 */
5758public class YoutubeStreamExtractorDefaultTest {
5859
60+ public static class NotAvailable {
61+ @ BeforeClass
62+ public static void setUp () {
63+ NewPipe .init (DownloaderTestImpl .getInstance ());
64+ }
65+
66+ @ Test (expected = ContentNotAvailableException .class )
67+ public void nonExistentFetch () throws Exception {
68+ final StreamExtractor extractor =
69+ YouTube .getStreamExtractor ("https://www.youtube.com/watch?v=don-t-exist" );
70+ extractor .fetchPage ();
71+ }
72+
73+ @ Test (expected = ParsingException .class )
74+ public void invalidId () throws Exception {
75+ final StreamExtractor extractor =
76+ YouTube .getStreamExtractor ("https://www.youtube.com/watch?v=INVALID_ID_INVALID_ID" );
77+ extractor .fetchPage ();
78+ }
79+ }
80+
5981 /**
6082 * Test for {@link StreamExtractor}
6183 */
You can’t perform that action at this time.
0 commit comments