Use StandardCharsets.UTF_8.
This commit is contained in:
parent
0ea16c0b73
commit
366f5c1632
|
@ -5,10 +5,9 @@ import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
|
|
||||||
public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
||||||
public static final String ALL = "all";
|
public static final String ALL = "all";
|
||||||
public static final String CONFERENCES = "conferences";
|
public static final String CONFERENCES = "conferences";
|
||||||
|
@ -33,7 +32,7 @@ public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory
|
||||||
final String sortFilter) throws ParsingException {
|
final String sortFilter) throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return "https://media.ccc.de/public/events/search?q="
|
return "https://media.ccc.de/public/events/search?q="
|
||||||
+ URLEncoder.encode(query, UTF_8);
|
+ URLEncoder.encode(query, StandardCharsets.UTF_8.name());
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
throw new ParsingException("Could not create search string with query: " + query, e);
|
throw new ParsingException("Could not create search string with query: " + query, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.schabi.newpipe.extractor.services.peertube.extractors;
|
package org.schabi.newpipe.extractor.services.peertube.extractors;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
|
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
|
@ -37,6 +36,7 @@ import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -328,7 +328,7 @@ public class PeertubeStreamExtractor extends StreamExtractor {
|
||||||
params.append("start=0&count=8&sort=-createdAt");
|
params.append("start=0&count=8&sort=-createdAt");
|
||||||
for (final String tag : tags) {
|
for (final String tag : tags) {
|
||||||
params.append("&tagsOneOf=");
|
params.append("&tagsOneOf=");
|
||||||
params.append(URLEncoder.encode(tag, UTF_8));
|
params.append(URLEncoder.encode(tag, StandardCharsets.UTF_8.name()));
|
||||||
}
|
}
|
||||||
return url + "?" + params;
|
return url + "?" + params;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,9 @@ import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
|
|
||||||
public final class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
public final class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
||||||
|
|
||||||
public static final String VIDEOS = "videos";
|
public static final String VIDEOS = "videos";
|
||||||
|
@ -43,7 +42,8 @@ public final class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerF
|
||||||
final String sortFilter,
|
final String sortFilter,
|
||||||
final String baseUrl) throws ParsingException {
|
final String baseUrl) throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return baseUrl + SEARCH_ENDPOINT + "?search=" + URLEncoder.encode(searchString, UTF_8);
|
return baseUrl + SEARCH_ENDPOINT + "?search=" + URLEncoder.encode(searchString,
|
||||||
|
StandardCharsets.UTF_8.name());
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
throw new ParsingException("Could not encode query", e);
|
throw new ParsingException("Could not encode query", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.schabi.newpipe.extractor.services.soundcloud;
|
package org.schabi.newpipe.extractor.services.soundcloud;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
|
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
|
||||||
|
|
||||||
|
@ -33,6 +32,7 @@ import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
|
@ -109,7 +109,7 @@ public final class SoundcloudParsingHelper {
|
||||||
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
|
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
|
||||||
throws IOException, ExtractionException {
|
throws IOException, ExtractionException {
|
||||||
final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve"
|
final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve"
|
||||||
+ "?url=" + URLEncoder.encode(url, UTF_8)
|
+ "?url=" + URLEncoder.encode(url, StandardCharsets.UTF_8.name())
|
||||||
+ "&client_id=" + clientId();
|
+ "&client_id=" + clientId();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -131,7 +131,8 @@ public final class SoundcloudParsingHelper {
|
||||||
ReCaptchaException {
|
ReCaptchaException {
|
||||||
|
|
||||||
final String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url="
|
final String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url="
|
||||||
+ URLEncoder.encode(apiUrl, UTF_8), SoundCloud.getLocalization()).responseBody();
|
+ URLEncoder.encode(apiUrl, StandardCharsets.UTF_8.name()),
|
||||||
|
SoundCloud.getLocalization()).responseBody();
|
||||||
|
|
||||||
return Jsoup.parse(response).select("link[rel=\"canonical\"]").first()
|
return Jsoup.parse(response).select("link[rel=\"canonical\"]").first()
|
||||||
.attr("abs:href");
|
.attr("abs:href");
|
||||||
|
@ -162,7 +163,7 @@ public final class SoundcloudParsingHelper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final String widgetUrl = "https://api-widget.soundcloud.com/resolve?url="
|
final String widgetUrl = "https://api-widget.soundcloud.com/resolve?url="
|
||||||
+ URLEncoder.encode(url.toString(), UTF_8)
|
+ URLEncoder.encode(url.toString(), StandardCharsets.UTF_8.name())
|
||||||
+ "&format=json&client_id=" + SoundcloudParsingHelper.clientId();
|
+ "&format=json&client_id=" + SoundcloudParsingHelper.clientId();
|
||||||
final String response = NewPipe.getDownloader().get(widgetUrl,
|
final String response = NewPipe.getDownloader().get(widgetUrl,
|
||||||
SoundCloud.getLocalization()).responseBody();
|
SoundCloud.getLocalization()).responseBody();
|
||||||
|
|
|
@ -4,7 +4,6 @@ import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsing
|
||||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.clientId;
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.clientId;
|
||||||
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
|
import static org.schabi.newpipe.extractor.stream.AudioStream.UNKNOWN_BITRATE;
|
||||||
import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN;
|
import static org.schabi.newpipe.extractor.stream.Stream.ID_UNKNOWN;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
|
@ -36,6 +35,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -320,7 +320,7 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
|
||||||
|
|
||||||
private static String urlEncode(final String value) {
|
private static String urlEncode(final String value) {
|
||||||
try {
|
try {
|
||||||
return URLEncoder.encode(value, UTF_8);
|
return URLEncoder.encode(value, StandardCharsets.UTF_8.name());
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
throw new IllegalStateException(e);
|
throw new IllegalStateException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
import com.grack.nanojson.JsonParserException;
|
import com.grack.nanojson.JsonParserException;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.NewPipe;
|
import org.schabi.newpipe.extractor.NewPipe;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
|
@ -14,12 +17,10 @@ import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
|
|
||||||
public class SoundcloudSuggestionExtractor extends SuggestionExtractor {
|
public class SoundcloudSuggestionExtractor extends SuggestionExtractor {
|
||||||
|
|
||||||
public SoundcloudSuggestionExtractor(final StreamingService service) {
|
public SoundcloudSuggestionExtractor(final StreamingService service) {
|
||||||
|
@ -32,7 +33,7 @@ public class SoundcloudSuggestionExtractor extends SuggestionExtractor {
|
||||||
final List<String> suggestions = new ArrayList<>();
|
final List<String> suggestions = new ArrayList<>();
|
||||||
final Downloader dl = NewPipe.getDownloader();
|
final Downloader dl = NewPipe.getDownloader();
|
||||||
final String url = SOUNDCLOUD_API_V2_URL + "search/queries" + "?q="
|
final String url = SOUNDCLOUD_API_V2_URL + "search/queries" + "?q="
|
||||||
+ URLEncoder.encode(query, UTF_8) + "&client_id="
|
+ URLEncoder.encode(query, StandardCharsets.UTF_8.name()) + "&client_id="
|
||||||
+ SoundcloudParsingHelper.clientId() + "&limit=10";
|
+ SoundcloudParsingHelper.clientId() + "&limit=10";
|
||||||
final String response = dl.get(url, getExtractorLocalization()).responseBody();
|
final String response = dl.get(url, getExtractorLocalization()).responseBody();
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.schabi.newpipe.extractor.services.soundcloud.linkHandler;
|
package org.schabi.newpipe.extractor.services.soundcloud.linkHandler;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
||||||
|
@ -9,11 +11,9 @@ import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
|
|
||||||
public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
||||||
|
|
||||||
public static final String TRACKS = "tracks";
|
public static final String TRACKS = "tracks";
|
||||||
|
@ -48,9 +48,9 @@ public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFacto
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return url + "?q=" + URLEncoder.encode(id, UTF_8) + "&client_id="
|
return url + "?q=" + URLEncoder.encode(id, StandardCharsets.UTF_8.name())
|
||||||
+ SoundcloudParsingHelper.clientId() + "&limit=" + ITEMS_PER_PAGE
|
+ "&client_id=" + SoundcloudParsingHelper.clientId()
|
||||||
+ "&offset=0";
|
+ "&limit=" + ITEMS_PER_PAGE + "&offset=0";
|
||||||
|
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
throw new ParsingException("Could not encode query", e);
|
throw new ParsingException("Could not encode query", e);
|
||||||
|
|
|
@ -23,7 +23,6 @@ package org.schabi.newpipe.extractor.services.youtube;
|
||||||
import static org.schabi.newpipe.extractor.NewPipe.getDownloader;
|
import static org.schabi.newpipe.extractor.NewPipe.getDownloader;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.HTTP;
|
import static org.schabi.newpipe.extractor.utils.Utils.HTTP;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
|
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.getStringResultFromRegexArray;
|
import static org.schabi.newpipe.extractor.utils.Utils.getStringResultFromRegexArray;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
import static java.util.Collections.singletonList;
|
import static java.util.Collections.singletonList;
|
||||||
|
@ -575,7 +574,7 @@ public final class YoutubeParsingHelper {
|
||||||
.end()
|
.end()
|
||||||
.value("fetchLiveState", true)
|
.value("fetchLiveState", true)
|
||||||
.end()
|
.end()
|
||||||
.end().done().getBytes(UTF_8);
|
.end().done().getBytes(StandardCharsets.UTF_8);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
final Map<String, List<String>> headers = new HashMap<>();
|
final Map<String, List<String>> headers = new HashMap<>();
|
||||||
|
@ -820,7 +819,7 @@ public final class YoutubeParsingHelper {
|
||||||
.end()
|
.end()
|
||||||
.end()
|
.end()
|
||||||
.value("input", "")
|
.value("input", "")
|
||||||
.end().done().getBytes(UTF_8);
|
.end().done().getBytes(StandardCharsets.UTF_8);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
final Map<String, List<String>> headers = new HashMap<>();
|
final Map<String, List<String>> headers = new HashMap<>();
|
||||||
|
@ -892,7 +891,8 @@ public final class YoutubeParsingHelper {
|
||||||
for (final String param : params) {
|
for (final String param : params) {
|
||||||
if (param.split("=")[0].equals("q")) {
|
if (param.split("=")[0].equals("q")) {
|
||||||
try {
|
try {
|
||||||
return URLDecoder.decode(param.split("=")[1], UTF_8);
|
return URLDecoder.decode(param.split("=")[1],
|
||||||
|
StandardCharsets.UTF_8.name());
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextFromObject;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
|
@ -35,6 +34,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -98,7 +98,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
getExtractorLocalization(), getExtractorContentCountry())
|
getExtractorLocalization(), getExtractorContentCountry())
|
||||||
.value("url", "https://www.youtube.com/" + channelPath)
|
.value("url", "https://www.youtube.com/" + channelPath)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
final JsonObject jsonResponse = getJsonPostResponse("navigation/resolve_url",
|
||||||
body, getExtractorLocalization());
|
body, getExtractorLocalization());
|
||||||
|
@ -146,7 +146,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
.value("browseId", id)
|
.value("browseId", id)
|
||||||
.value("params", "EgZ2aWRlb3M%3D") // Equal to videos
|
.value("params", "EgZ2aWRlb3M%3D") // Equal to videos
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
final JsonObject jsonResponse = getJsonPostResponse("browse", body,
|
final JsonObject jsonResponse = getJsonPostResponse("browse", body,
|
||||||
getExtractorLocalization());
|
getExtractorLocalization());
|
||||||
|
@ -397,7 +397,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
getExtractorContentCountry())
|
getExtractorContentCountry())
|
||||||
.value("continuation", continuation)
|
.value("continuation", continuation)
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey()
|
return new Page(YOUTUBEI_V1_URL + "browse?key=" + getKey()
|
||||||
+ DISABLE_PRETTY_PRINT_PARAMETER, null, channelIds, null, body);
|
+ DISABLE_PRETTY_PRINT_PARAMETER, null, channelIds, null, body);
|
||||||
|
|
|
@ -10,7 +10,6 @@ import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeS
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_PLAYLISTS;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_SONGS;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_SONGS;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_VIDEOS;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.MUSIC_VIDEOS;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
|
@ -38,6 +37,7 @@ import org.schabi.newpipe.extractor.utils.Parser;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -113,7 +113,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
||||||
.end()
|
.end()
|
||||||
.value("query", getSearchString())
|
.value("query", getSearchString())
|
||||||
.value("params", params)
|
.value("params", params)
|
||||||
.end().done().getBytes(UTF_8);
|
.end().done().getBytes(StandardCharsets.UTF_8);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
final Map<String, List<String>> headers = new HashMap<>();
|
final Map<String, List<String>> headers = new HashMap<>();
|
||||||
|
@ -248,7 +248,7 @@ public class YoutubeMusicSearchExtractor extends SearchExtractor {
|
||||||
.value("enableSafetyMode", false)
|
.value("enableSafetyMode", false)
|
||||||
.end()
|
.end()
|
||||||
.end()
|
.end()
|
||||||
.end().done().getBytes(UTF_8);
|
.end().done().getBytes(StandardCharsets.UTF_8);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
final Map<String, List<String>> headers = new HashMap<>();
|
final Map<String, List<String>> headers = new HashMap<>();
|
||||||
|
|
|
@ -8,7 +8,6 @@ import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getValidJsonResponseBody;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.getSearchParameter;
|
import static org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory.getSearchParameter;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
|
@ -20,6 +19,7 @@ import com.grack.nanojson.JsonWriter;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.InfoItem;
|
import org.schabi.newpipe.extractor.InfoItem;
|
||||||
import org.schabi.newpipe.extractor.MetaInfo;
|
import org.schabi.newpipe.extractor.MetaInfo;
|
||||||
|
import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
|
||||||
import org.schabi.newpipe.extractor.Page;
|
import org.schabi.newpipe.extractor.Page;
|
||||||
import org.schabi.newpipe.extractor.StreamingService;
|
import org.schabi.newpipe.extractor.StreamingService;
|
||||||
import org.schabi.newpipe.extractor.downloader.Downloader;
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
||||||
|
@ -28,12 +28,12 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
|
||||||
import org.schabi.newpipe.extractor.localization.Localization;
|
import org.schabi.newpipe.extractor.localization.Localization;
|
||||||
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
||||||
import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
|
|
||||||
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
||||||
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
import org.schabi.newpipe.extractor.utils.JsonUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
jsonBody.value("params", params);
|
jsonBody.value("params", params);
|
||||||
}
|
}
|
||||||
|
|
||||||
final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(UTF_8);
|
final byte[] body = JsonWriter.string(jsonBody.done()).getBytes(StandardCharsets.UTF_8);
|
||||||
|
|
||||||
initialData = getJsonPostResponse("search", body, localization);
|
initialData = getJsonPostResponse("search", body, localization);
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ public class YoutubeSearchExtractor extends SearchExtractor {
|
||||||
getExtractorContentCountry())
|
getExtractorContentCountry())
|
||||||
.value("continuation", page.getId())
|
.value("continuation", page.getId())
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
final String responseBody = getValidJsonResponseBody(getDownloader().post(
|
final String responseBody = getValidJsonResponseBody(getDownloader().post(
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getCookieHeader;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getCookieHeader;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
|
|
||||||
import com.grack.nanojson.JsonArray;
|
import com.grack.nanojson.JsonArray;
|
||||||
import com.grack.nanojson.JsonParser;
|
import com.grack.nanojson.JsonParser;
|
||||||
|
@ -16,6 +15,7 @@ import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -54,8 +54,9 @@ public class YoutubeSuggestionExtractor extends SuggestionExtractor {
|
||||||
+ "?client=" + "youtube" //"firefox" for JSON, 'toolbar' for xml
|
+ "?client=" + "youtube" //"firefox" for JSON, 'toolbar' for xml
|
||||||
+ "&jsonp=" + "JP"
|
+ "&jsonp=" + "JP"
|
||||||
+ "&ds=" + "yt"
|
+ "&ds=" + "yt"
|
||||||
+ "&gl=" + URLEncoder.encode(getExtractorContentCountry().getCountryCode(), UTF_8)
|
+ "&gl=" + URLEncoder.encode(getExtractorContentCountry().getCountryCode(),
|
||||||
+ "&q=" + URLEncoder.encode(query, UTF_8);
|
StandardCharsets.UTF_8.name())
|
||||||
|
+ "&q=" + URLEncoder.encode(query, StandardCharsets.UTF_8.name());
|
||||||
|
|
||||||
String response = dl.get(url, getCookieHeader(), getExtractorLocalization()).responseBody();
|
String response = dl.get(url, getCookieHeader(), getExtractorLocalization()).responseBody();
|
||||||
// trim JSONP part "JP(...)"
|
// trim JSONP part "JP(...)"
|
||||||
|
|
|
@ -18,7 +18,10 @@
|
||||||
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
|
* along with NewPipe Extractor. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.schabi.newpipe.extractor.services.youtube.extractors;
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextAtKey;
|
||||||
|
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import com.grack.nanojson.JsonObject;
|
import com.grack.nanojson.JsonObject;
|
||||||
import com.grack.nanojson.JsonWriter;
|
import com.grack.nanojson.JsonWriter;
|
||||||
|
@ -35,15 +38,10 @@ import org.schabi.newpipe.extractor.stream.StreamInfoItem;
|
||||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getJsonPostResponse;
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.getTextAtKey;
|
|
||||||
import static org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper.prepareDesktopJsonBuilder;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
|
||||||
|
|
||||||
public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
private JsonObject initialData;
|
private JsonObject initialData;
|
||||||
|
|
||||||
|
@ -61,7 +59,7 @@ public class YoutubeTrendingExtractor extends KioskExtractor<StreamInfoItem> {
|
||||||
getExtractorContentCountry())
|
getExtractorContentCountry())
|
||||||
.value("browseId", "FEtrending")
|
.value("browseId", "FEtrending")
|
||||||
.done())
|
.done())
|
||||||
.getBytes(UTF_8);
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
|
|
||||||
initialData = getJsonPostResponse("browse", body, getExtractorLocalization());
|
initialData = getJsonPostResponse("browse", body, getExtractorLocalization());
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
|
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
|
||||||
|
|
||||||
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||||
|
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
import javax.annotation.Nonnull;
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
|
||||||
|
|
||||||
public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
||||||
|
|
||||||
|
@ -44,24 +45,28 @@ public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFa
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case VIDEOS:
|
case VIDEOS:
|
||||||
return SEARCH_URL + URLEncoder.encode(searchString, UTF_8)
|
return SEARCH_URL + URLEncoder.encode(searchString,
|
||||||
|
StandardCharsets.UTF_8.name())
|
||||||
+ "&sp=EgIQAQ%253D%253D";
|
+ "&sp=EgIQAQ%253D%253D";
|
||||||
case CHANNELS:
|
case CHANNELS:
|
||||||
return SEARCH_URL + URLEncoder.encode(searchString, UTF_8)
|
return SEARCH_URL + URLEncoder.encode(searchString,
|
||||||
|
StandardCharsets.UTF_8.name())
|
||||||
+ "&sp=EgIQAg%253D%253D";
|
+ "&sp=EgIQAg%253D%253D";
|
||||||
case PLAYLISTS:
|
case PLAYLISTS:
|
||||||
return SEARCH_URL + URLEncoder.encode(searchString, UTF_8)
|
return SEARCH_URL + URLEncoder.encode(searchString,
|
||||||
|
StandardCharsets.UTF_8.name())
|
||||||
+ "&sp=EgIQAw%253D%253D";
|
+ "&sp=EgIQAw%253D%253D";
|
||||||
case MUSIC_SONGS:
|
case MUSIC_SONGS:
|
||||||
case MUSIC_VIDEOS:
|
case MUSIC_VIDEOS:
|
||||||
case MUSIC_ALBUMS:
|
case MUSIC_ALBUMS:
|
||||||
case MUSIC_PLAYLISTS:
|
case MUSIC_PLAYLISTS:
|
||||||
case MUSIC_ARTISTS:
|
case MUSIC_ARTISTS:
|
||||||
return MUSIC_SEARCH_URL + URLEncoder.encode(searchString, UTF_8);
|
return MUSIC_SEARCH_URL + URLEncoder.encode(searchString,
|
||||||
|
StandardCharsets.UTF_8.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SEARCH_URL + URLEncoder.encode(searchString, UTF_8);
|
return SEARCH_URL + URLEncoder.encode(searchString, StandardCharsets.UTF_8.name());
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
throw new ParsingException("Could not encode query", e);
|
throw new ParsingException("Could not encode query", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,9 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.EnumSet;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -99,7 +102,7 @@ public final class Parser {
|
||||||
for (final String arg : input.split("&")) {
|
for (final String arg : input.split("&")) {
|
||||||
final String[] splitArg = arg.split("=");
|
final String[] splitArg = arg.split("=");
|
||||||
if (splitArg.length > 1) {
|
if (splitArg.length > 1) {
|
||||||
map.put(splitArg[0], URLDecoder.decode(splitArg[1], UTF_8));
|
map.put(splitArg[0], URLDecoder.decode(splitArg[1], StandardCharsets.UTF_8.name()));
|
||||||
} else {
|
} else {
|
||||||
map.put(splitArg[0], "");
|
map.put(splitArg[0], "");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.io.UnsupportedEncodingException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -17,14 +18,8 @@ import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public final class Utils {
|
public final class Utils {
|
||||||
|
|
||||||
public static final String HTTP = "http://";
|
public static final String HTTP = "http://";
|
||||||
public static final String HTTPS = "https://";
|
public static final String HTTPS = "https://";
|
||||||
/**
|
|
||||||
* @deprecated Use {@link java.nio.charset.StandardCharsets#UTF_8}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public static final String UTF_8 = "UTF-8";
|
|
||||||
private static final Pattern M_PATTERN = Pattern.compile("(https?)?://m\\.");
|
private static final Pattern M_PATTERN = Pattern.compile("(https?)?://m\\.");
|
||||||
private static final Pattern WWW_PATTERN = Pattern.compile("(https?)?://www\\.");
|
private static final Pattern WWW_PATTERN = Pattern.compile("(https?)?://www\\.");
|
||||||
|
|
||||||
|
@ -139,7 +134,7 @@ public final class Utils {
|
||||||
|
|
||||||
String query;
|
String query;
|
||||||
try {
|
try {
|
||||||
query = URLDecoder.decode(params[0], UTF_8);
|
query = URLDecoder.decode(params[0], StandardCharsets.UTF_8.name());
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
// Cannot decode string with UTF-8, using the string without decoding
|
// Cannot decode string with UTF-8, using the string without decoding
|
||||||
query = params[0];
|
query = params[0];
|
||||||
|
@ -147,7 +142,7 @@ public final class Utils {
|
||||||
|
|
||||||
if (query.equals(parameterName)) {
|
if (query.equals(parameterName)) {
|
||||||
try {
|
try {
|
||||||
return URLDecoder.decode(params[1], UTF_8);
|
return URLDecoder.decode(params[1], StandardCharsets.UTF_8.name());
|
||||||
} catch (final UnsupportedEncodingException e) {
|
} catch (final UnsupportedEncodingException e) {
|
||||||
// Cannot decode string with UTF-8, using the string without decoding
|
// Cannot decode string with UTF-8, using the string without decoding
|
||||||
return params[1];
|
return params[1];
|
||||||
|
@ -246,7 +241,8 @@ public final class Utils {
|
||||||
try {
|
try {
|
||||||
final URL decoded = Utils.stringToURL(url);
|
final URL decoded = Utils.stringToURL(url);
|
||||||
if (decoded.getHost().contains("google") && decoded.getPath().equals("/url")) {
|
if (decoded.getHost().contains("google") && decoded.getPath().equals("/url")) {
|
||||||
return URLDecoder.decode(Parser.matchGroup1("&url=([^&]+)(?:&|$)", url), UTF_8);
|
return URLDecoder.decode(Parser.matchGroup1("&url=([^&]+)(?:&|$)", url),
|
||||||
|
StandardCharsets.UTF_8.name());
|
||||||
}
|
}
|
||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
package org.schabi.newpipe.extractor.services.soundcloud.search;
|
package org.schabi.newpipe.extractor.services.soundcloud.search;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
||||||
|
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems;
|
||||||
|
import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.PLAYLISTS;
|
||||||
|
import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.TRACKS;
|
||||||
|
import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.USERS;
|
||||||
|
import static java.util.Collections.singletonList;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
||||||
|
@ -12,18 +20,13 @@ import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
||||||
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
|
import org.schabi.newpipe.extractor.services.DefaultSearchExtractorTest;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static java.util.Collections.singletonList;
|
import javax.annotation.Nullable;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
|
|
||||||
import static org.schabi.newpipe.extractor.services.DefaultTests.assertNoDuplicatedItems;
|
|
||||||
import static org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory.*;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
|
|
||||||
public class SoundcloudSearchExtractorTest {
|
public class SoundcloudSearchExtractorTest {
|
||||||
|
|
||||||
|
@ -138,7 +141,7 @@ public class SoundcloudSearchExtractorTest {
|
||||||
|
|
||||||
private static String urlEncode(String value) {
|
private static String urlEncode(String value) {
|
||||||
try {
|
try {
|
||||||
return URLEncoder.encode(value, UTF_8);
|
return URLEncoder.encode(value, StandardCharsets.UTF_8.name());
|
||||||
} catch (UnsupportedEncodingException e) {
|
} catch (UnsupportedEncodingException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package org.schabi.newpipe.extractor.services.youtube;
|
package org.schabi.newpipe.extractor.services.youtube;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
import static org.schabi.newpipe.FileUtils.resolveTestResource;
|
||||||
|
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
import org.schabi.newpipe.downloader.DownloaderTestImpl;
|
||||||
|
@ -13,13 +19,10 @@ import org.schabi.newpipe.extractor.subscription.SubscriptionItem;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import static org.schabi.newpipe.FileUtils.resolveTestResource;
|
|
||||||
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link YoutubeSubscriptionExtractor}
|
* Test for {@link YoutubeSubscriptionExtractor}
|
||||||
*/
|
*/
|
||||||
|
@ -54,7 +57,7 @@ public class YoutubeSubscriptionExtractorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testEmptySourceException() throws Exception {
|
public void testEmptySourceException() throws Exception {
|
||||||
final List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(
|
final List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(
|
||||||
new ByteArrayInputStream("[]".getBytes(UTF_8)));
|
new ByteArrayInputStream("[]".getBytes(StandardCharsets.UTF_8)));
|
||||||
assertTrue(items.isEmpty());
|
assertTrue(items.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +65,7 @@ public class YoutubeSubscriptionExtractorTest {
|
||||||
public void testSubscriptionWithEmptyTitleInSource() throws Exception {
|
public void testSubscriptionWithEmptyTitleInSource() throws Exception {
|
||||||
final String source = "[{\"snippet\":{\"resourceId\":{\"channelId\":\"UCEOXxzW2vU0P-0THehuIIeg\"}}}]";
|
final String source = "[{\"snippet\":{\"resourceId\":{\"channelId\":\"UCEOXxzW2vU0P-0THehuIIeg\"}}}]";
|
||||||
final List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(
|
final List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(
|
||||||
new ByteArrayInputStream(source.getBytes(UTF_8)));
|
new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
|
||||||
assertEquals(1, items.size());
|
assertEquals(1, items.size());
|
||||||
assertEquals(ServiceList.YouTube.getServiceId(), items.get(0).getServiceId());
|
assertEquals(ServiceList.YouTube.getServiceId(), items.get(0).getServiceId());
|
||||||
|
@ -75,7 +78,7 @@ public class YoutubeSubscriptionExtractorTest {
|
||||||
final String source = "[{\"snippet\":{\"resourceId\":{\"channelId\":\"gibberish\"},\"title\":\"name1\"}}," +
|
final String source = "[{\"snippet\":{\"resourceId\":{\"channelId\":\"gibberish\"},\"title\":\"name1\"}}," +
|
||||||
"{\"snippet\":{\"resourceId\":{\"channelId\":\"UCEOXxzW2vU0P-0THehuIIeg\"},\"title\":\"name2\"}}]";
|
"{\"snippet\":{\"resourceId\":{\"channelId\":\"UCEOXxzW2vU0P-0THehuIIeg\"},\"title\":\"name2\"}}]";
|
||||||
final List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(
|
final List<SubscriptionItem> items = subscriptionExtractor.fromInputStream(
|
||||||
new ByteArrayInputStream(source.getBytes(UTF_8)));
|
new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)));
|
||||||
|
|
||||||
assertEquals(1, items.size());
|
assertEquals(1, items.size());
|
||||||
assertEquals(ServiceList.YouTube.getServiceId(), items.get(0).getServiceId());
|
assertEquals(ServiceList.YouTube.getServiceId(), items.get(0).getServiceId());
|
||||||
|
@ -99,7 +102,7 @@ public class YoutubeSubscriptionExtractorTest {
|
||||||
|
|
||||||
for (String invalidContent : invalidList) {
|
for (String invalidContent : invalidList) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = invalidContent.getBytes(UTF_8);
|
byte[] bytes = invalidContent.getBytes(StandardCharsets.UTF_8);
|
||||||
subscriptionExtractor.fromInputStream(new ByteArrayInputStream(bytes));
|
subscriptionExtractor.fromInputStream(new ByteArrayInputStream(bytes));
|
||||||
fail("Extracting from \"" + invalidContent + "\" didn't throw an exception");
|
fail("Extracting from \"" + invalidContent + "\" didn't throw an exception");
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue