Skip to content

Commit 02b5990

Browse files
wb9688TobiGr
authored andcommitted
Remove useless code
1 parent dd4dd84 commit 02b5990

4 files changed

Lines changed: 24 additions & 95 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubePlaylistExtractor.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class YoutubePlaylistExtractor extends PlaylistExtractor {
3434
private JsonObject initialData;
3535
private JsonObject uploaderInfo;
3636
private JsonObject playlistInfo;
37-
private JsonObject playlistVideos;
3837

3938
public YoutubePlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
4039
super(service, linkHandler);
@@ -48,7 +47,6 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
4847
initialData = YoutubeParsingHelper.getInitialData(response.responseBody());
4948
uploaderInfo = getUploaderInfo();
5049
playlistInfo = getPlaylistInfo();
51-
playlistVideos = getPlaylistVideos();
5250
}
5351

5452
private JsonObject getUploaderInfo() throws ParsingException {
@@ -83,19 +81,8 @@ private JsonObject getPlaylistInfo() throws ParsingException {
8381
}
8482
}
8583

86-
private JsonObject getPlaylistVideos() throws ParsingException {
87-
try {
88-
return initialData.getObject("contents").getObject("twoColumnBrowseResultsRenderer")
89-
.getArray("tabs").getObject(0).getObject("tabRenderer").getObject("content").getObject("sectionListRenderer")
90-
.getArray("contents").getObject(0).getObject("itemSectionRenderer").getArray("contents")
91-
.getObject(0).getObject("playlistVideoListRenderer");
92-
} catch (Exception e) {
93-
throw new ParsingException("Could not get playlist info", e);
94-
}
95-
}
96-
9784
@Override
98-
public String getNextPageUrl() throws ExtractionException {
85+
public String getNextPageUrl() {
9986
return getNextPageUrlFrom(initialData.getObject("contents").getObject("twoColumnBrowseResultsRenderer")
10087
.getArray("tabs").getObject(0).getObject("tabRenderer").getObject("content")
10188
.getObject("sectionListRenderer").getArray("contents").getObject(0)
@@ -177,7 +164,7 @@ public long getStreamCount() throws ParsingException {
177164

178165
@Nonnull
179166
@Override
180-
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException {
167+
public InfoItemsPage<StreamInfoItem> getInitialPage() {
181168
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
182169

183170
JsonArray videos = initialData.getObject("contents").getObject("twoColumnBrowseResultsRenderer")

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeSearchExtractor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.schabi.newpipe.extractor.search.InfoItemsSearchCollector;
1818
import org.schabi.newpipe.extractor.search.SearchExtractor;
1919
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
20-
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
2120

2221
import java.io.IOException;
2322
import java.util.Collections;
@@ -147,7 +146,7 @@ public InfoItemsPage<InfoItem> getPage(String pageUrl) throws IOException, Extra
147146
return new InfoItemsPage<>(collector, getNextPageUrlFrom(itemSectionRenderer.getArray("continuations")));
148147
}
149148

150-
private void collectStreamsFrom(InfoItemsSearchCollector collector, JsonArray videos) throws NothingFoundException, ParsingException {
149+
private void collectStreamsFrom(InfoItemsSearchCollector collector, JsonArray videos) throws NothingFoundException {
151150
collector.reset();
152151

153152
final TimeAgoParser timeAgoParser = getTimeAgoParser();

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.grack.nanojson.JsonArray;
44
import com.grack.nanojson.JsonObject;
55
import com.grack.nanojson.JsonParser;
6-
import com.grack.nanojson.JsonParserException;
76

87
import org.jsoup.Jsoup;
98
import org.jsoup.nodes.Document;
@@ -15,7 +14,6 @@
1514
import org.schabi.newpipe.extractor.NewPipe;
1615
import org.schabi.newpipe.extractor.StreamingService;
1716
import org.schabi.newpipe.extractor.downloader.Downloader;
18-
import org.schabi.newpipe.extractor.downloader.Request;
1917
import org.schabi.newpipe.extractor.downloader.Response;
2018
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
2119
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
@@ -36,7 +34,6 @@
3634
import org.schabi.newpipe.extractor.stream.StreamType;
3735
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
3836
import org.schabi.newpipe.extractor.stream.VideoStream;
39-
import org.schabi.newpipe.extractor.utils.JsonUtils;
4037
import org.schabi.newpipe.extractor.utils.Parser;
4138
import 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
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeTrendingExtractor.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@
2222

2323
import com.grack.nanojson.JsonArray;
2424
import com.grack.nanojson.JsonObject;
25-
import com.grack.nanojson.JsonParser;
26-
import com.grack.nanojson.JsonParserException;
2725

28-
import org.jsoup.nodes.Document;
2926
import org.schabi.newpipe.extractor.StreamingService;
3027
import org.schabi.newpipe.extractor.downloader.Downloader;
3128
import org.schabi.newpipe.extractor.downloader.Response;
@@ -37,15 +34,12 @@
3734
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
3835
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
3936
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
40-
import org.schabi.newpipe.extractor.utils.Parser;
4137

4238
import java.io.IOException;
4339

4440
import javax.annotation.Nonnull;
4541

4642
public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
47-
48-
private Document doc;
4943
private JsonObject initialData;
5044

5145
public YoutubeTrendingExtractor(StreamingService service,
@@ -60,7 +54,6 @@ public void onFetchPage(@Nonnull Downloader downloader) throws IOException, Extr
6054
"?gl=" + getExtractorContentCountry().getCountryCode();
6155

6256
final Response response = downloader.get(url, getExtractorLocalization());
63-
doc = YoutubeParsingHelper.parseAndCheckPage(url, response);
6457
initialData = YoutubeParsingHelper.getInitialData(response.responseBody());
6558
}
6659

@@ -92,7 +85,7 @@ public String getName() throws ParsingException {
9285

9386
@Nonnull
9487
@Override
95-
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ParsingException {
88+
public InfoItemsPage<StreamInfoItem> getInitialPage() {
9689
StreamInfoItemsCollector collector = new StreamInfoItemsCollector(getServiceId());
9790
JsonArray firstPageElements = initialData.getObject("contents").getObject("twoColumnBrowseResultsRenderer")
9891
.getArray("tabs").getObject(0).getObject("tabRenderer").getObject("content")

0 commit comments

Comments
 (0)