@@ -105,6 +105,7 @@ public String getId() throws ParsingException {
105105 @ Nonnull
106106 @ Override
107107 public String getName () throws ParsingException {
108+ assertPageFetched ();
108109 String name = getStringFromMetaData ("title" );
109110 if (name == null ) {
110111 // Fallback to HTML method
@@ -123,6 +124,7 @@ public String getName() throws ParsingException {
123124 @ Nonnull
124125 @ Override
125126 public String getUploadDate () throws ParsingException {
127+ assertPageFetched ();
126128 try {
127129 return doc .select ("meta[itemprop=datePublished]" ).attr (CONTENT );
128130 } catch (Exception e ) {//todo: add fallback method
@@ -133,6 +135,7 @@ public String getUploadDate() throws ParsingException {
133135 @ Nonnull
134136 @ Override
135137 public String getThumbnailUrl () throws ParsingException {
138+ assertPageFetched ();
136139 // Try to get high resolution thumbnail first, if it fails, use low res from the player instead
137140 try {
138141 return doc .select ("link[itemprop=\" thumbnailUrl\" ]" ).first ().attr ("abs:href" );
@@ -156,6 +159,7 @@ public String getThumbnailUrl() throws ParsingException {
156159 @ Nonnull
157160 @ Override
158161 public String getDescription () throws ParsingException {
162+ assertPageFetched ();
159163 try {
160164 return doc .select ("p[id=\" eow-description\" ]" ).first ().html ();
161165 } catch (Exception e ) {//todo: add fallback method <-- there is no ... as long as i know
@@ -165,6 +169,7 @@ public String getDescription() throws ParsingException {
165169
166170 @ Override
167171 public int getAgeLimit () throws ParsingException {
172+ assertPageFetched ();
168173 if (!isAgeRestricted ) {
169174 return NO_AGE_LIMIT ;
170175 }
@@ -178,6 +183,7 @@ public int getAgeLimit() throws ParsingException {
178183
179184 @ Override
180185 public long getLength () throws ParsingException {
186+ assertPageFetched ();
181187 if (playerArgs != null ) {
182188 try {
183189 long returnValue = Long .parseLong (playerArgs .get ("length_seconds" ) + "" );
@@ -216,6 +222,7 @@ public long getTimeStamp() throws ParsingException {
216222
217223 @ Override
218224 public long getViewCount () throws ParsingException {
225+ assertPageFetched ();
219226 try {
220227 return Long .parseLong (doc .select ("meta[itemprop=interactionCount]" ).attr (CONTENT ));
221228 } catch (Exception e ) {//todo: find fallback method
@@ -225,6 +232,7 @@ public long getViewCount() throws ParsingException {
225232
226233 @ Override
227234 public long getLikeCount () throws ParsingException {
235+ assertPageFetched ();
228236 String likesString = "" ;
229237 try {
230238 Element button = doc .select ("button.like-button-renderer-like-button" ).first ();
@@ -244,6 +252,7 @@ public long getLikeCount() throws ParsingException {
244252
245253 @ Override
246254 public long getDislikeCount () throws ParsingException {
255+ assertPageFetched ();
247256 String dislikesString = "" ;
248257 try {
249258 Element button = doc .select ("button.like-button-renderer-dislike-button" ).first ();
@@ -264,6 +273,7 @@ public long getDislikeCount() throws ParsingException {
264273 @ Nonnull
265274 @ Override
266275 public String getUploaderUrl () throws ParsingException {
276+ assertPageFetched ();
267277 try {
268278 return doc .select ("div[class=\" yt-user-info\" ]" ).first ().children ()
269279 .select ("a" ).first ().attr ("abs:href" );
@@ -275,6 +285,7 @@ public String getUploaderUrl() throws ParsingException {
275285
276286 @ Nullable
277287 private String getStringFromMetaData (String field ) {
288+ assertPageFetched ();
278289 String value = null ;
279290 if (playerArgs != null ) {
280291 // This can not fail
@@ -290,6 +301,7 @@ private String getStringFromMetaData(String field) {
290301 @ Nonnull
291302 @ Override
292303 public String getUploaderName () throws ParsingException {
304+ assertPageFetched ();
293305 String name = getStringFromMetaData ("author" );
294306
295307 if (name == null ) {
@@ -309,6 +321,7 @@ public String getUploaderName() throws ParsingException {
309321 @ Nonnull
310322 @ Override
311323 public String getUploaderAvatarUrl () throws ParsingException {
324+ assertPageFetched ();
312325 try {
313326 return doc .select ("a[class*=\" yt-user-photo\" ]" ).first ()
314327 .select ("img" ).first ()
@@ -320,6 +333,7 @@ public String getUploaderAvatarUrl() throws ParsingException {
320333
321334 @ Override
322335 public String getDashMpdUrl () throws ParsingException {
336+ assertPageFetched ();
323337 try {
324338 String dashManifestUrl ;
325339 if (videoInfoPage .containsKey ("dashmpd" )) {
@@ -346,6 +360,7 @@ public String getDashMpdUrl() throws ParsingException {
346360
347361 @ Override
348362 public List <AudioStream > getAudioStreams () throws IOException , ExtractionException {
363+ assertPageFetched ();
349364 List <AudioStream > audioStreams = new ArrayList <>();
350365 try {
351366 for (Map .Entry <String , ItagItem > entry : getItags (ADAPTIVE_FMTS , ItagItem .ItagType .AUDIO ).entrySet ()) {
@@ -365,6 +380,7 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
365380
366381 @ Override
367382 public List <VideoStream > getVideoStreams () throws IOException , ExtractionException {
383+ assertPageFetched ();
368384 List <VideoStream > videoStreams = new ArrayList <>();
369385 try {
370386 for (Map .Entry <String , ItagItem > entry : getItags (URL_ENCODED_FMT_STREAM_MAP , ItagItem .ItagType .VIDEO ).entrySet ()) {
@@ -384,6 +400,7 @@ public List<VideoStream> getVideoStreams() throws IOException, ExtractionExcepti
384400
385401 @ Override
386402 public List <VideoStream > getVideoOnlyStreams () throws IOException , ExtractionException {
403+ assertPageFetched ();
387404 List <VideoStream > videoOnlyStreams = new ArrayList <>();
388405 try {
389406 for (Map .Entry <String , ItagItem > entry : getItags (ADAPTIVE_FMTS , ItagItem .ItagType .VIDEO_ONLY ).entrySet ()) {
@@ -410,6 +427,7 @@ public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionExcep
410427 @ Override
411428 @ Nullable
412429 public List <Subtitles > getSubtitles (SubtitlesFormat format ) throws IOException , ExtractionException {
430+ assertPageFetched ();
413431 if (isAgeRestricted ) {
414432 // If the video is age restricted getPlayerConfig will fail
415433 return null ;
@@ -459,6 +477,7 @@ public StreamType getStreamType() throws ParsingException {
459477
460478 @ Override
461479 public StreamInfoItem getNextVideo () throws IOException , ExtractionException {
480+ assertPageFetched ();
462481 try {
463482 StreamInfoItemCollector collector = new StreamInfoItemCollector (getServiceId ());
464483 collector .commit (extractVideoPreviewInfo (doc .select ("div[class=\" watch-sidebar-section\" ]" )
@@ -472,6 +491,7 @@ public StreamInfoItem getNextVideo() throws IOException, ExtractionException {
472491
473492 @ Override
474493 public StreamInfoItemCollector getRelatedVideos () throws IOException , ExtractionException {
494+ assertPageFetched ();
475495 try {
476496 StreamInfoItemCollector collector = new StreamInfoItemCollector (getServiceId ());
477497 Element ul = doc .select ("ul[id=\" watch-related\" ]" ).first ();
0 commit comments