Skip to content

Commit 416cf17

Browse files
authored
Merge pull request #532 from B0pol/utf8
Code improvement
2 parents 50e5718 + 7a3d9bd commit 416cf17

35 files changed

Lines changed: 196 additions & 218 deletions

extractor/src/main/java/org/schabi/newpipe/extractor/kiosk/KioskList.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import java.util.Map;
1515
import java.util.Set;
1616

17+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
18+
1719
public class KioskList {
1820

1921
public interface KioskExtractorFactory {
@@ -70,7 +72,7 @@ public KioskExtractor getDefaultKioskExtractor(Page nextPage)
7072

7173
public KioskExtractor getDefaultKioskExtractor(Page nextPage, Localization localization)
7274
throws ExtractionException, IOException {
73-
if (defaultKiosk != null && !defaultKiosk.equals("")) {
75+
if (!isNullOrEmpty(defaultKiosk)) {
7476
return getExtractorById(defaultKiosk, nextPage, localization);
7577
} else {
7678
if (!kioskList.isEmpty()) {

extractor/src/main/java/org/schabi/newpipe/extractor/linkhandler/SearchQueryHandlerFactory.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
9+
810
public abstract class SearchQueryHandlerFactory extends ListLinkHandlerFactory {
911

1012
///////////////////////////////////
1113
// To Override
1214
///////////////////////////////////
1315

1416
@Override
15-
public abstract String getUrl(String querry, List<String> contentFilter, String sortFilter) throws ParsingException;
17+
public abstract String getUrl(String query, List<String> contentFilter, String sortFilter) throws ParsingException;
1618

1719
public String getSearchString(String url) {
1820
return "";
@@ -28,14 +30,14 @@ public String getId(String url) {
2830
}
2931

3032
@Override
31-
public SearchQueryHandler fromQuery(String querry,
33+
public SearchQueryHandler fromQuery(String query,
3234
List<String> contentFilter,
3335
String sortFilter) throws ParsingException {
34-
return new SearchQueryHandler(super.fromQuery(querry, contentFilter, sortFilter));
36+
return new SearchQueryHandler(super.fromQuery(query, contentFilter, sortFilter));
3537
}
3638

37-
public SearchQueryHandler fromQuery(String querry) throws ParsingException {
38-
return fromQuery(querry, new ArrayList<String>(0), "");
39+
public SearchQueryHandler fromQuery(String query) throws ParsingException {
40+
return fromQuery(query, new ArrayList<String>(0), EMPTY_STRING);
3941
}
4042

4143
/**

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/linkHandler/MediaCCCSearchQueryHandlerFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.net.URLEncoder;
88
import java.util.List;
99

10+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
11+
1012
public class MediaCCCSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1113
public static final String ALL = "all";
1214
public static final String CONFERENCES = "conferences";
@@ -31,7 +33,7 @@ public String getUrl(final String query, final List<String> contentFilter,
3133
final String sortFilter) throws ParsingException {
3234
try {
3335
return "https://media.ccc.de/public/events/search?q="
34-
+ URLEncoder.encode(query, "UTF-8");
36+
+ URLEncoder.encode(query, UTF_8);
3537
} catch (UnsupportedEncodingException e) {
3638
throw new ParsingException("Could not create search string with query: " + query, e);
3739
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeCommentsInfoItemExtractor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.schabi.newpipe.extractor.services.peertube.extractors;
22

33
import com.grack.nanojson.JsonObject;
4-
54
import org.jsoup.Jsoup;
65
import org.jsoup.nodes.Document;
76
import org.schabi.newpipe.extractor.ServiceList;
@@ -13,6 +12,8 @@
1312

1413
import java.util.Objects;
1514

15+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
16+
1617
public class PeertubeCommentsInfoItemExtractor implements CommentsInfoItemExtractor {
1718
private final JsonObject item;
1819
private final String url;
@@ -68,7 +69,7 @@ public String getCommentText() throws ParsingException {
6869
final Document doc = Jsoup.parse(htmlText);
6970
return doc.body().text();
7071
} catch (Exception e) {
71-
return htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", "");
72+
return htmlText.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", EMPTY_STRING);
7273
}
7374
}
7475

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,7 @@
1818
import org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper;
1919
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeSearchQueryHandlerFactory;
2020
import org.schabi.newpipe.extractor.services.peertube.linkHandler.PeertubeStreamLinkHandlerFactory;
21-
import org.schabi.newpipe.extractor.stream.AudioStream;
22-
import org.schabi.newpipe.extractor.stream.Description;
23-
import org.schabi.newpipe.extractor.stream.Stream;
24-
import org.schabi.newpipe.extractor.stream.StreamExtractor;
25-
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
26-
import org.schabi.newpipe.extractor.stream.StreamSegment;
27-
import org.schabi.newpipe.extractor.stream.StreamType;
28-
import org.schabi.newpipe.extractor.stream.SubtitlesStream;
29-
import org.schabi.newpipe.extractor.stream.VideoStream;
21+
import org.schabi.newpipe.extractor.stream.*;
3022
import org.schabi.newpipe.extractor.utils.JsonUtils;
3123
import org.schabi.newpipe.extractor.utils.Utils;
3224

@@ -40,6 +32,8 @@
4032
import java.util.List;
4133
import java.util.Locale;
4234

35+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
36+
4337
public class PeertubeStreamExtractor extends StreamExtractor {
4438
private final String baseUrl;
4539
private JsonObject json;
@@ -322,7 +316,7 @@ private String getRelatedStreamsUrl(final List<String> tags) throws UnsupportedE
322316
params.append("start=0&count=8&sort=-createdAt");
323317
for (final String tag : tags) {
324318
params.append("&tagsOneOf=");
325-
params.append(URLEncoder.encode(tag, "UTF-8"));
319+
params.append(URLEncoder.encode(tag, UTF_8));
326320
}
327321
return url + "?" + params.toString();
328322
}

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/linkHandler/PeertubeSearchQueryHandlerFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
import java.net.URLEncoder;
99
import java.util.List;
1010

11+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
12+
1113
public class PeertubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
1214

13-
public static final String CHARSET_UTF_8 = "UTF-8";
1415
public static final String VIDEOS = "videos";
1516
public static final String SEPIA_VIDEOS = "sepia_videos"; // sepia is the global index
1617
public static final String SEPIA_BASE_URL = "https://sepiasearch.org";
@@ -35,7 +36,7 @@ public String getUrl(String searchString, List<String> contentFilters, String so
3536
public String getUrl(String searchString, List<String> contentFilters, String sortFilter, String baseUrl) throws ParsingException {
3637
try {
3738
final String url = baseUrl + SEARCH_ENDPOINT
38-
+ "?search=" + URLEncoder.encode(searchString, CHARSET_UTF_8);
39+
+ "?search=" + URLEncoder.encode(searchString, UTF_8);
3940

4041
return url;
4142
} catch (UnsupportedEncodingException e) {

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@
3737

3838
import static java.util.Collections.singletonList;
3939
import static org.schabi.newpipe.extractor.ServiceList.SoundCloud;
40-
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
41-
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
42-
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
40+
import static org.schabi.newpipe.extractor.utils.Utils.*;
4341

4442
public class SoundcloudParsingHelper {
4543
private static final String HARDCODED_CLIENT_ID = "H2c34Q0E7hftqnuDHGsk88DbNqhYpgMm"; // Updated on 24/06/20
@@ -117,7 +115,7 @@ public static OffsetDateTime parseDateFrom(String textualUploadDate) throws Pars
117115
*/
118116
public static JsonObject resolveFor(Downloader downloader, String url) throws IOException, ExtractionException {
119117
String apiUrl = "https://api-v2.soundcloud.com/resolve"
120-
+ "?url=" + URLEncoder.encode(url, "UTF-8")
118+
+ "?url=" + URLEncoder.encode(url, UTF_8)
121119
+ "&client_id=" + clientId();
122120

123121
try {
@@ -136,7 +134,7 @@ public static JsonObject resolveFor(Downloader downloader, String url) throws IO
136134
public static String resolveUrlWithEmbedPlayer(String apiUrl) throws IOException, ReCaptchaException, ParsingException {
137135

138136
String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url="
139-
+ URLEncoder.encode(apiUrl, "UTF-8"), SoundCloud.getLocalization()).responseBody();
137+
+ URLEncoder.encode(apiUrl, UTF_8), SoundCloud.getLocalization()).responseBody();
140138

141139
return Jsoup.parse(response).select("link[rel=\"canonical\"]").first().attr("abs:href");
142140
}
@@ -158,7 +156,7 @@ public static String resolveIdWithEmbedPlayer(String urlString) throws IOExcepti
158156
}
159157

160158
String response = NewPipe.getDownloader().get("https://w.soundcloud.com/player/?url="
161-
+ URLEncoder.encode(url.toString(), "UTF-8"), SoundCloud.getLocalization()).responseBody();
159+
+ URLEncoder.encode(url.toString(), UTF_8), SoundCloud.getLocalization()).responseBody();
162160
// handle playlists / sets different and get playlist id via uir field in JSON
163161
if (url.getPath().contains("/sets/") && !url.getPath().endsWith("/sets"))
164162
return Parser.matchGroup1("\"uri\":\\s*\"https:\\/\\/api\\.soundcloud\\.com\\/playlists\\/((\\d)*?)\"", response);

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelExtractor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.grack.nanojson.JsonObject;
44
import com.grack.nanojson.JsonParser;
55
import com.grack.nanojson.JsonParserException;
6-
76
import org.schabi.newpipe.extractor.Page;
87
import org.schabi.newpipe.extractor.StreamingService;
98
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
@@ -15,11 +14,10 @@
1514
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
1615
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
1716

18-
import java.io.IOException;
19-
2017
import javax.annotation.Nonnull;
18+
import java.io.IOException;
2119

22-
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
20+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
2321
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2422

2523
@SuppressWarnings("WeakerAccess")

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudChannelInfoItemExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.grack.nanojson.JsonObject;
44
import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
55

6-
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
6+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
77
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
88

99
public class SoundcloudChannelInfoItemExtractor implements ChannelInfoItemExtractor {

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudPlaylistInfoItemExtractor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import org.schabi.newpipe.extractor.exceptions.ParsingException;
55
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;
66

7-
import static org.schabi.newpipe.extractor.utils.JsonUtils.EMPTY_STRING;
7+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
88
import static org.schabi.newpipe.extractor.utils.Utils.replaceHttpWithHttps;
99

1010
public class SoundcloudPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {

0 commit comments

Comments
 (0)