Skip to content

Commit 222d659

Browse files
wb9688Stypox
authored andcommitted
[SoundCloud] Don't make separate request for getAudioStreams() in StreamExtractor
Signed-off-by: Stypox <stypox@pm.me>
1 parent 265cfb6 commit 222d659

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudStreamExtractor.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@
1414
import org.schabi.newpipe.extractor.exceptions.ParsingException;
1515
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
1616
import org.schabi.newpipe.extractor.localization.DateWrapper;
17-
import org.schabi.newpipe.extractor.stream.*;
17+
import org.schabi.newpipe.extractor.stream.AudioStream;
18+
import org.schabi.newpipe.extractor.stream.Description;
19+
import org.schabi.newpipe.extractor.stream.StreamExtractor;
20+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
21+
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
22+
import org.schabi.newpipe.extractor.stream.StreamType;
23+
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
24+
import org.schabi.newpipe.extractor.stream.VideoStream;
1825

1926
import java.io.IOException;
2027
import java.io.UnsupportedEncodingException;
@@ -148,24 +155,13 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
148155
List<AudioStream> audioStreams = new ArrayList<>();
149156
Downloader dl = NewPipe.getDownloader();
150157

151-
String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId())
152-
+ "?client_id=" + urlEncode(SoundcloudParsingHelper.clientId());
153-
154-
String response = dl.get(apiUrl, getExtractorLocalization()).responseBody();
155-
JsonObject responseObject;
156-
try {
157-
responseObject = JsonParser.object().from(response);
158-
} catch (JsonParserException e) {
159-
throw new ParsingException("Could not parse json response", e);
160-
}
161-
162158
// Streams can be streamable and downloadable - or explicitly not.
163159
// For playing the track, it is only necessary to have a streamable track.
164160
// If this is not the case, this track might not be published yet.
165-
if (!responseObject.getBoolean("streamable")) return audioStreams;
161+
if (!track.getBoolean("streamable")) return audioStreams;
166162

167163
try {
168-
JsonArray transcodings = responseObject.getObject("media").getArray("transcodings");
164+
JsonArray transcodings = track.getObject("media").getArray("transcodings");
169165

170166
// get information about what stream formats are available
171167
for (Object transcoding : transcodings) {

0 commit comments

Comments
 (0)