Skip to content

Commit 9cd11a7

Browse files
committed
Encode paramters and small changes
1 parent b5b9f86 commit 9cd11a7

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException;
88
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
99
import org.schabi.newpipe.extractor.exceptions.ParsingException;
10-
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
1110
import org.schabi.newpipe.extractor.stream.*;
12-
import org.schabi.newpipe.extractor.utils.Parser;
1311

1412
import javax.annotation.Nonnull;
13+
import javax.annotation.Nullable;
1514
import java.io.IOException;
15+
import java.io.UnsupportedEncodingException;
16+
import java.net.URLEncoder;
1617
import java.util.*;
1718

1819
public class SoundcloudStreamExtractor extends StreamExtractor {
@@ -127,8 +128,8 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
127128
List<AudioStream> audioStreams = new ArrayList<>();
128129
Downloader dl = NewPipe.getDownloader();
129130

130-
String apiUrl = "https://api.soundcloud.com/i1/tracks/" + getId() + "/streams"
131-
+ "?client_id=" + SoundcloudParsingHelper.clientId();
131+
String apiUrl = "https://api.soundcloud.com/i1/tracks/" + urlEncode(getId()) + "/streams"
132+
+ "?client_id=" + urlEncode(SoundcloudParsingHelper.clientId());
132133

133134
String response = dl.download(apiUrl);
134135
JsonObject responseObject;
@@ -148,6 +149,14 @@ public List<AudioStream> getAudioStreams() throws IOException, ExtractionExcepti
148149
return audioStreams;
149150
}
150151

152+
private static String urlEncode(String value) {
153+
try {
154+
return URLEncoder.encode(value, "UTF-8");
155+
} catch (UnsupportedEncodingException e) {
156+
throw new IllegalStateException(e);
157+
}
158+
}
159+
151160
@Override
152161
public List<VideoStream> getVideoStreams() throws IOException, ExtractionException {
153162
return null;
@@ -159,11 +168,13 @@ public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionExc
159168
}
160169

161170
@Override
171+
@Nullable
162172
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException {
163173
return null;
164174
}
165175

166176
@Override
177+
@Nullable
167178
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
168179
return null;
169180
}
@@ -182,8 +193,8 @@ public StreamInfoItem getNextVideo() throws IOException, ExtractionException {
182193
public StreamInfoItemCollector getRelatedVideos() throws IOException, ExtractionException {
183194
StreamInfoItemCollector collector = new StreamInfoItemCollector(getServiceId());
184195

185-
String apiUrl = "https://api-v2.soundcloud.com/tracks/" + getId() + "/related"
186-
+ "?client_id=" + SoundcloudParsingHelper.clientId();
196+
String apiUrl = "https://api-v2.soundcloud.com/tracks/" + urlEncode(getId()) + "/related"
197+
+ "?client_id=" + urlEncode(SoundcloudParsingHelper.clientId());
187198

188199
SoundcloudParsingHelper.getStreamsFromApi(collector, apiUrl);
189200
return collector;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,13 @@ public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionExc
403403
}
404404

405405
@Override
406+
@Nullable
406407
public List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException {
407408
return getSubtitles(SubtitlesFormat.TTML);
408409
}
409410

410411
@Override
412+
@Nullable
411413
public List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException {
412414
JsonObject playerConfig = getPlayerConfig(getPageHtml());
413415
String playerResponse = playerConfig.getObject("args").getString("player_response");

src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@
2020
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
2121
*/
2222

23-
import com.grack.nanojson.JsonParserException;
2423
import org.schabi.newpipe.extractor.Extractor;
2524
import org.schabi.newpipe.extractor.StreamingService;
2625
import org.schabi.newpipe.extractor.Subtitles;
2726
import org.schabi.newpipe.extractor.UrlIdHandler;
2827
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
2928
import org.schabi.newpipe.extractor.exceptions.ParsingException;
30-
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
3129
import org.schabi.newpipe.extractor.utils.Parser;
3230

3331
import javax.annotation.Nonnull;
32+
import javax.annotation.Nullable;
3433
import java.io.IOException;
3534
import java.util.List;
3635

@@ -57,6 +56,12 @@ protected UrlIdHandler getUrlIdHandler() throws ParsingException {
5756
public abstract String getThumbnailUrl() throws ParsingException;
5857
@Nonnull
5958
public abstract String getDescription() throws ParsingException;
59+
60+
/**
61+
* Get the age limit
62+
* @return The age which limits the content or {@value NO_AGE_LIMIT} if there is no limit
63+
* @throws ParsingException if an error occurs while parsing
64+
*/
6065
public abstract int getAgeLimit() throws ParsingException;
6166

6267
public abstract long getLength() throws ParsingException;
@@ -126,7 +131,11 @@ protected long getTimestampSeconds(String regexPattern) throws ParsingException
126131
public abstract List<AudioStream> getAudioStreams() throws IOException, ExtractionException;
127132
public abstract List<VideoStream> getVideoStreams() throws IOException, ExtractionException;
128133
public abstract List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException;
134+
135+
@Nullable
129136
public abstract List<Subtitles> getSubtitlesDefault() throws IOException, ExtractionException;
137+
138+
@Nullable
130139
public abstract List<Subtitles> getSubtitles(SubtitlesFormat format) throws IOException, ExtractionException;
131140

132141
public abstract StreamType getStreamType() throws ParsingException;

src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamExtractorRestrictedTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,12 @@ public void testGetVideoStreams() throws IOException, ExtractionException {
116116
@Test
117117
public void testGetSubtitlesListDefault() throws IOException, ExtractionException {
118118
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
119-
assertTrue(extractor.getSubtitlesDefault() == null);
119+
assertNull(extractor.getSubtitlesDefault());
120120
}
121121

122122
@Test
123123
public void testGetSubtitlesList() throws IOException, ExtractionException {
124124
// Video (/view?v=YQHsXMglC9A) set in the setUp() method has no captions => null
125-
assertTrue(extractor.getSubtitles(SubtitlesFormat.VTT) == null);
125+
assertNull(extractor.getSubtitles(SubtitlesFormat.VTT));
126126
}
127127
}

0 commit comments

Comments
 (0)