@@ -74,19 +74,34 @@ public void addException(Exception e) {
7474 /**Fills out the video info fields which are common to all services.
7575 * Probably needs to be overridden by subclasses*/
7676 public static StreamInfo getVideoInfo (StreamExtractor extractor )
77- throws ExtractionException , IOException {
77+ throws ExtractionException , StreamExtractor . ContentNotAvailableException {
7878 StreamInfo streamInfo = new StreamInfo ();
7979
80- streamInfo = extractImportantData (streamInfo , extractor );
81- streamInfo = extractStreams (streamInfo , extractor );
82- streamInfo = extractOptionalData (streamInfo , extractor );
80+ try {
81+ streamInfo = extractImportantData (streamInfo , extractor );
82+ streamInfo = extractStreams (streamInfo , extractor );
83+ streamInfo = extractOptionalData (streamInfo , extractor );
84+ } catch (ExtractionException e ) {
85+ // Currently YouTube does not distinguish between age restricted videos and videos blocked
86+ // by country. This means that during the initialisation of the extractor, the extractor
87+ // will assume that a video is age restricted while in reality it it blocked by country.
88+ //
89+ // We will now detect whether the video is blocked by country or not.
90+ String errorMsg = extractor .getErrorMessage ();
91+
92+ if (errorMsg != null ) {
93+ throw new StreamExtractor .ContentNotAvailableException (errorMsg );
94+ } else {
95+ throw e ;
96+ }
97+ }
8398
8499 return streamInfo ;
85100 }
86101
87102 private static StreamInfo extractImportantData (
88103 StreamInfo streamInfo , StreamExtractor extractor )
89- throws ExtractionException , IOException {
104+ throws ExtractionException {
90105 /* ---- important data, withoug the video can't be displayed goes here: ---- */
91106 // if one of these is not available an exception is meant to be thrown directly into the frontend.
92107
@@ -112,7 +127,7 @@ private static StreamInfo extractImportantData(
112127
113128 private static StreamInfo extractStreams (
114129 StreamInfo streamInfo , StreamExtractor extractor )
115- throws ExtractionException , IOException {
130+ throws ExtractionException {
116131 /* ---- stream extraction goes here ---- */
117132 // At least one type of stream has to be available,
118133 // otherwise an exception will be thrown directly into the frontend.
0 commit comments