33import com .grack .nanojson .JsonArray ;
44import com .grack .nanojson .JsonObject ;
55import com .grack .nanojson .JsonParser ;
6- import com .grack .nanojson .JsonParserException ;
76
87import org .jsoup .Jsoup ;
98import org .jsoup .nodes .Document ;
1514import org .schabi .newpipe .extractor .NewPipe ;
1615import org .schabi .newpipe .extractor .StreamingService ;
1716import org .schabi .newpipe .extractor .downloader .Downloader ;
18- import org .schabi .newpipe .extractor .downloader .Request ;
1917import org .schabi .newpipe .extractor .downloader .Response ;
2018import org .schabi .newpipe .extractor .exceptions .ContentNotAvailableException ;
2119import org .schabi .newpipe .extractor .exceptions .ExtractionException ;
3634import org .schabi .newpipe .extractor .stream .StreamType ;
3735import org .schabi .newpipe .extractor .stream .SubtitlesStream ;
3836import org .schabi .newpipe .extractor .stream .VideoStream ;
39- import org .schabi .newpipe .extractor .utils .JsonUtils ;
4037import org .schabi .newpipe .extractor .utils .Parser ;
4138import org .schabi .newpipe .extractor .utils .Utils ;
4239
@@ -366,55 +363,6 @@ public long getViewCount() throws ParsingException {
366363 }
367364 }
368365
369- private long getLiveStreamWatchingCount () throws ExtractionException , IOException , JsonParserException {
370- // https://www.youtube.com/youtubei/v1/updated_metadata?alt=json&key=
371- String innerTubeKey = null , clientVersion = null ;
372- if (playerArgs != null && !playerArgs .isEmpty ()) {
373- innerTubeKey = playerArgs .getString ("innertube_api_key" );
374- clientVersion = playerArgs .getString ("innertube_context_client_version" );
375- } else if (!videoInfoPage .isEmpty ()) {
376- innerTubeKey = videoInfoPage .get ("innertube_api_key" );
377- clientVersion = videoInfoPage .get ("innertube_context_client_version" );
378- }
379-
380- if (innerTubeKey == null || innerTubeKey .isEmpty ()) {
381- throw new ExtractionException ("Couldn't get innerTube key" );
382- }
383-
384- if (clientVersion == null || clientVersion .isEmpty ()) {
385- throw new ExtractionException ("Couldn't get innerTube client version" );
386- }
387-
388- final String metadataUrl = "https://www.youtube.com/youtubei/v1/updated_metadata?alt=json&key=" + innerTubeKey ;
389- final byte [] dataBody = ("{\" context\" :{\" client\" :{\" clientName\" :1,\" clientVersion\" :\" " + clientVersion + "\" }}" +
390- ",\" videoId\" :\" " + getId () + "\" }" ).getBytes ("UTF-8" );
391- final Response response = getDownloader ().execute (Request .newBuilder ()
392- .post (metadataUrl , dataBody )
393- .addHeader ("Content-Type" , "application/json" )
394- .build ());
395- final JsonObject jsonObject = JsonParser .object ().from (response .responseBody ());
396-
397- for (Object actionEntry : jsonObject .getArray ("actions" )) {
398- if (!(actionEntry instanceof JsonObject )) continue ;
399- final JsonObject entry = (JsonObject ) actionEntry ;
400-
401- final JsonObject updateViewershipAction = entry .getObject ("updateViewershipAction" , null );
402- if (updateViewershipAction == null ) continue ;
403-
404- final JsonArray viewCountRuns = JsonUtils .getArray (updateViewershipAction , "viewership.videoViewCountRenderer.viewCount.runs" );
405- if (viewCountRuns .isEmpty ()) continue ;
406-
407- final JsonObject textObject = viewCountRuns .getObject (0 );
408- if (!textObject .has ("text" )) {
409- throw new ExtractionException ("Response don't have \" text\" element" );
410- }
411-
412- return Long .parseLong (Utils .removeNonDigitCharacters (textObject .getString ("text" )));
413- }
414-
415- throw new ExtractionException ("Could not find correct results in response" );
416- }
417-
418366 private JsonObject getVideoPrimaryInfoRenderer () throws ParsingException {
419367 JsonArray contents = initialData .getObject ("contents" ).getObject ("twoColumnWatchNextResults" )
420368 .getObject ("results" ).getObject ("results" ).getArray ("contents" );
@@ -525,7 +473,7 @@ public String getUploaderName() throws ParsingException {
525473 public String getUploaderAvatarUrl () throws ParsingException {
526474 assertPageFetched ();
527475
528- String uploaderAvatarUrl = null ;
476+ String uploaderAvatarUrl ;
529477 try {
530478 uploaderAvatarUrl = initialData .getObject ("contents" ).getObject ("twoColumnWatchNextResults" ).getObject ("secondaryResults" )
531479 .getObject ("secondaryResults" ).getArray ("results" ).getObject (0 ).getObject ("compactAutoplayRenderer" )
@@ -657,13 +605,13 @@ public List<VideoStream> getVideoOnlyStreams() throws ExtractionException {
657605
658606 @ Override
659607 @ Nonnull
660- public List <SubtitlesStream > getSubtitlesDefault () throws IOException , ExtractionException {
608+ public List <SubtitlesStream > getSubtitlesDefault () {
661609 return getSubtitles (MediaFormat .TTML );
662610 }
663611
664612 @ Override
665613 @ Nonnull
666- public List <SubtitlesStream > getSubtitles (final MediaFormat format ) throws IOException , ExtractionException {
614+ public List <SubtitlesStream > getSubtitles (final MediaFormat format ) {
667615 assertPageFetched ();
668616 List <SubtitlesStream > subtitles = new ArrayList <>();
669617 for (final SubtitlesInfo subtitlesInfo : subtitlesInfos ) {
@@ -687,7 +635,7 @@ public StreamType getStreamType() throws ParsingException {
687635 }
688636
689637 @ Override
690- public StreamInfoItem getNextStream () throws IOException , ExtractionException {
638+ public StreamInfoItem getNextStream () throws ExtractionException {
691639 assertPageFetched ();
692640 try {
693641 final JsonObject videoInfo = initialData .getObject ("contents" ).getObject ("twoColumnWatchNextResults" )
@@ -815,12 +763,10 @@ private JsonObject getPlayerConfig() throws ParsingException {
815763 return JsonParser .object ().from (ytPlayerConfigRaw );
816764 } catch (Parser .RegexException e ) {
817765 String errorReason = getErrorMessage ();
818- switch (errorReason ) {
819- case "" :
820- throw new ContentNotAvailableException ("Content not available: player config empty" , e );
821- default :
822- throw new ContentNotAvailableException ("Content not available" , e );
766+ if (errorReason .isEmpty ()) {
767+ throw new ContentNotAvailableException ("Content not available: player config empty" , e );
823768 }
769+ throw new ContentNotAvailableException ("Content not available" , e );
824770 } catch (Exception e ) {
825771 throw new ParsingException ("Could not parse yt player config" , e );
826772 }
@@ -976,7 +922,7 @@ private String getDecryptionFuncName(String playerCode) throws DecryptException
976922 }
977923
978924 @ Nonnull
979- private List <SubtitlesInfo > getAvailableSubtitlesInfo () throws SubtitlesException {
925+ private List <SubtitlesInfo > getAvailableSubtitlesInfo () {
980926 // If the video is age restricted getPlayerConfig will fail
981927 if (isAgeRestricted ) return Collections .emptyList ();
982928
@@ -990,7 +936,7 @@ private List<SubtitlesInfo> getAvailableSubtitlesInfo() throws SubtitlesExceptio
990936 final JsonObject renderer = captions .getObject ("playerCaptionsTracklistRenderer" , new JsonObject ());
991937 final JsonArray captionsArray = renderer .getArray ("captionTracks" , new JsonArray ());
992938 // todo: use this to apply auto translation to different language from a source language
993- final JsonArray autoCaptionsArray = renderer .getArray ("translationLanguages" , new JsonArray ());
939+ // final JsonArray autoCaptionsArray = renderer.getArray("translationLanguages", new JsonArray());
994940
995941 // This check is necessary since there may be cases where subtitles metadata do not contain caption track info
996942 // e.g. https://www.youtube.com/watch?v=-Vpwatutnko
@@ -1147,40 +1093,44 @@ public List<Frameset> getFrames() throws ExtractionException {
11471093 }
11481094 }
11491095
1096+ @ Nonnull
11501097 @ Override
1151- public String getHost () throws ParsingException {
1098+ public String getHost () {
11521099 return "" ;
11531100 }
11541101
1102+ @ Nonnull
11551103 @ Override
1156- public String getPrivacy () throws ParsingException {
1104+ public String getPrivacy () {
11571105 return "" ;
11581106 }
11591107
1108+ @ Nonnull
11601109 @ Override
1161- public String getCategory () throws ParsingException {
1110+ public String getCategory () {
11621111 return "" ;
11631112 }
11641113
1114+ @ Nonnull
11651115 @ Override
1166- public String getLicence () throws ParsingException {
1116+ public String getLicence () {
11671117 return "" ;
11681118 }
11691119
11701120 @ Override
1171- public Locale getLanguageInfo () throws ParsingException {
1121+ public Locale getLanguageInfo () {
11721122 return null ;
11731123 }
11741124
11751125 @ Nonnull
11761126 @ Override
1177- public List <String > getTags () throws ParsingException {
1127+ public List <String > getTags () {
11781128 return new ArrayList <>();
11791129 }
11801130
11811131 @ Nonnull
11821132 @ Override
1183- public String getSupportInfo () throws ParsingException {
1133+ public String getSupportInfo () {
11841134 return "" ;
11851135 }
11861136}
0 commit comments