Skip to content

Commit 9dc17cd

Browse files
Stypoxlitetex
authored andcommitted
[Soundcloud] Fix checkstyle issues
1 parent 9ab32cb commit 9dc17cd

13 files changed

+127
-74
lines changed

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@
4444

4545
import javax.annotation.Nonnull;
4646

47-
public class SoundcloudParsingHelper {
47+
public final class SoundcloudParsingHelper {
4848
private static String clientId;
4949
public static final String SOUNDCLOUD_API_V2_URL = "https://api-v2.soundcloud.com/";
5050

5151
private SoundcloudParsingHelper() {
5252
}
5353

5454
public static synchronized String clientId() throws ExtractionException, IOException {
55-
if (!isNullOrEmpty(clientId)) return clientId;
55+
if (!isNullOrEmpty(clientId)) {
56+
return clientId;
57+
}
5658

5759
final Downloader dl = NewPipe.getDownloader();
5860

@@ -109,7 +111,7 @@ public static OffsetDateTime parseDateFrom(final String textualUploadDate)
109111
public static JsonObject resolveFor(@Nonnull final Downloader downloader, final String url)
110112
throws IOException, ExtractionException {
111113
final String apiUrl = SOUNDCLOUD_API_V2_URL + "resolve"
112-
+ "?url=" + URLEncoder.encode(url, UTF_8)
114+
+ "?url=" + URLEncoder.encode(url, UTF_8)
113115
+ "&client_id=" + clientId();
114116

115117
try {
@@ -142,18 +144,20 @@ public static String resolveUrlWithEmbedPlayer(final String apiUrl) throws IOExc
142144
*
143145
* @return the resolved id
144146
*/
145-
public static String resolveIdWithWidgetApi(String urlString) throws IOException,
147+
public static String resolveIdWithWidgetApi(final String urlString) throws IOException,
146148
ParsingException {
147149
// Remove the tailing slash from URLs due to issues with the SoundCloud API
148-
if (urlString.charAt(urlString.length() - 1) == '/') urlString = urlString.substring(0,
149-
urlString.length() - 1);
150+
String fixedUrl = urlString;
151+
if (fixedUrl.charAt(fixedUrl.length() - 1) == '/') {
152+
fixedUrl = fixedUrl.substring(0, fixedUrl.length() - 1);
153+
}
150154
// Make URL lower case and remove m. and www. if it exists.
151155
// Without doing this, the widget API does not recognize the URL.
152-
urlString = Utils.removeMAndWWWFromUrl(urlString.toLowerCase());
156+
fixedUrl = Utils.removeMAndWWWFromUrl(fixedUrl.toLowerCase());
153157

154158
final URL url;
155159
try {
156-
url = Utils.stringToURL(urlString);
160+
url = Utils.stringToURL(fixedUrl);
157161
} catch (final MalformedURLException e) {
158162
throw new IllegalArgumentException("The given URL is not valid");
159163
}
@@ -225,8 +229,9 @@ public static String getUsersFromApi(final ChannelInfoItemsCollector collector,
225229
String nextPageUrl;
226230
try {
227231
nextPageUrl = responseObject.getString("next_href");
228-
if (!nextPageUrl.contains("client_id=")) nextPageUrl += "&client_id="
229-
+ SoundcloudParsingHelper.clientId();
232+
if (!nextPageUrl.contains("client_id=")) {
233+
nextPageUrl += "&client_id=" + SoundcloudParsingHelper.clientId();
234+
}
230235
} catch (final Exception ignored) {
231236
nextPageUrl = "";
232237
}
@@ -291,8 +296,9 @@ public static String getStreamsFromApi(final StreamInfoItemsCollector collector,
291296
String nextPageUrl;
292297
try {
293298
nextPageUrl = responseObject.getString("next_href");
294-
if (!nextPageUrl.contains("client_id=")) nextPageUrl += "&client_id="
295-
+ SoundcloudParsingHelper.clientId();
299+
if (!nextPageUrl.contains("client_id=")) {
300+
nextPageUrl += "&client_id=" + SoundcloudParsingHelper.clientId();
301+
}
296302
} catch (final Exception ignored) {
297303
nextPageUrl = "";
298304
}

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,42 @@
11
package org.schabi.newpipe.extractor.services.soundcloud;
22

3+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
4+
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
5+
import static java.util.Arrays.asList;
6+
37
import org.schabi.newpipe.extractor.StreamingService;
48
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
59
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
610
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
711
import org.schabi.newpipe.extractor.kiosk.KioskList;
8-
import org.schabi.newpipe.extractor.linkhandler.*;
12+
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
13+
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
14+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
15+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
16+
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
17+
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
918
import org.schabi.newpipe.extractor.localization.ContentCountry;
1019
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
1120
import org.schabi.newpipe.extractor.search.SearchExtractor;
12-
import org.schabi.newpipe.extractor.services.soundcloud.extractors.*;
13-
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.*;
21+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChannelExtractor;
22+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudChartsExtractor;
23+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudCommentsExtractor;
24+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudPlaylistExtractor;
25+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudSearchExtractor;
26+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudStreamExtractor;
27+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudSubscriptionExtractor;
28+
import org.schabi.newpipe.extractor.services.soundcloud.extractors.SoundcloudSuggestionExtractor;
29+
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudChannelLinkHandlerFactory;
30+
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudChartsLinkHandlerFactory;
31+
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudCommentsLinkHandlerFactory;
32+
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudPlaylistLinkHandlerFactory;
33+
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudSearchQueryHandlerFactory;
34+
import org.schabi.newpipe.extractor.services.soundcloud.linkHandler.SoundcloudStreamLinkHandlerFactory;
1435
import org.schabi.newpipe.extractor.stream.StreamExtractor;
1536
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
1637

1738
import java.util.List;
1839

19-
import static java.util.Arrays.asList;
20-
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.AUDIO;
21-
import static org.schabi.newpipe.extractor.StreamingService.ServiceInfo.MediaCapability.COMMENTS;
22-
2340
public class SoundcloudService extends StreamingService {
2441

2542
public SoundcloudService(final int id) {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
2222
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
2323

24-
@SuppressWarnings("WeakerAccess")
2524
public class SoundcloudChannelExtractor extends ChannelExtractor {
2625
private String userId;
2726
private JsonObject user;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ public String getUrl() {
2525

2626
@Override
2727
public String getThumbnailUrl() {
28-
String avatarUrl = itemObject.getString("avatar_url", EMPTY_STRING);
2928
// An avatar URL with a better resolution
30-
return avatarUrl.replace("large.jpg", "crop.jpg");
29+
return itemObject.getString("avatar_url", EMPTY_STRING).replace("large.jpg", "crop.jpg");
3130
}
3231

3332
@Override

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public String getThumbnailUrl() throws ParsingException {
4646

4747
// First look for track artwork url
4848
if (trackObject.isString(ARTWORK_URL_KEY)) {
49-
String artworkUrl = trackObject.getString(ARTWORK_URL_KEY, EMPTY_STRING);
49+
final String artworkUrl = trackObject.getString(ARTWORK_URL_KEY, EMPTY_STRING);
5050
if (!artworkUrl.isEmpty()) {
5151
// An artwork URL with a better resolution
5252
return artworkUrl.replace("large.jpg", "crop.jpg");
@@ -56,7 +56,9 @@ public String getThumbnailUrl() throws ParsingException {
5656
// Then look for track creator avatar url
5757
final JsonObject creator = trackObject.getObject(USER_KEY);
5858
final String creatorAvatar = creator.getString(AVATAR_URL_KEY, EMPTY_STRING);
59-
if (!creatorAvatar.isEmpty()) return creatorAvatar;
59+
if (!creatorAvatar.isEmpty()) {
60+
return creatorAvatar;
61+
}
6062
}
6163
} catch (final Exception ignored) {
6264
// Try other method

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
import com.grack.nanojson.JsonObject;
55
import com.grack.nanojson.JsonParser;
66
import com.grack.nanojson.JsonParserException;
7-
import org.schabi.newpipe.extractor.*;
7+
8+
import org.schabi.newpipe.extractor.InfoItem;
9+
import org.schabi.newpipe.extractor.InfoItemExtractor;
10+
import org.schabi.newpipe.extractor.InfoItemsCollector;
11+
import org.schabi.newpipe.extractor.MetaInfo;
12+
import org.schabi.newpipe.extractor.Page;
13+
import org.schabi.newpipe.extractor.StreamingService;
814
import org.schabi.newpipe.extractor.downloader.Downloader;
915
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
1016
import org.schabi.newpipe.extractor.exceptions.ParsingException;
@@ -76,9 +82,9 @@ public InfoItemsPage<InfoItem> getPage(final Page page) throws IOException,
7682
throw new ParsingException("Could not parse json response", e);
7783
}
7884

79-
return new InfoItemsPage<>(
80-
collectItems(searchCollection),
81-
getNextPageFromCurrentUrl(page.getUrl(), currentOffset -> currentOffset + ITEMS_PER_PAGE));
85+
return new InfoItemsPage<>(collectItems(searchCollection),
86+
getNextPageFromCurrentUrl(page.getUrl(),
87+
currentOffset -> currentOffset + ITEMS_PER_PAGE));
8288
}
8389

8490
@Override
@@ -103,7 +109,10 @@ private InfoItemsCollector<InfoItem, InfoItemExtractor> collectItems(
103109
final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(getServiceId());
104110

105111
for (final Object result : searchCollection) {
106-
if (!(result instanceof JsonObject)) continue;
112+
if (!(result instanceof JsonObject)) {
113+
continue;
114+
}
115+
107116
final JsonObject searchResult = (JsonObject) result;
108117
final String kind = searchResult.getString("kind", EMPTY_STRING);
109118
switch (kind) {
@@ -122,7 +131,8 @@ private InfoItemsCollector<InfoItem, InfoItemExtractor> collectItems(
122131
return collector;
123132
}
124133

125-
private Page getNextPageFromCurrentUrl(final String currentUrl, final IntUnaryOperator newPageOffsetCalculator)
134+
private Page getNextPageFromCurrentUrl(final String currentUrl,
135+
final IntUnaryOperator newPageOffsetCalculator)
126136
throws MalformedURLException, UnsupportedEncodingException {
127137
final int currentPageOffset = Integer.parseInt(
128138
Parser.compatParseMap(new URL(currentUrl).getQuery()).get("offset"));

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

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package org.schabi.newpipe.extractor.services.soundcloud.extractors;
22

3+
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
4+
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
5+
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;
6+
import static org.schabi.newpipe.extractor.utils.Utils.UTF_8;
7+
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
8+
39
import com.grack.nanojson.JsonArray;
410
import com.grack.nanojson.JsonObject;
511
import com.grack.nanojson.JsonParser;
612
import com.grack.nanojson.JsonParserException;
13+
714
import org.schabi.newpipe.extractor.MediaFormat;
8-
import org.schabi.newpipe.extractor.MetaInfo;
915
import org.schabi.newpipe.extractor.NewPipe;
1016
import org.schabi.newpipe.extractor.StreamingService;
1117
import org.schabi.newpipe.extractor.downloader.Downloader;
@@ -18,20 +24,22 @@
1824
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
1925
import org.schabi.newpipe.extractor.localization.DateWrapper;
2026
import org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper;
21-
import org.schabi.newpipe.extractor.stream.*;
27+
import org.schabi.newpipe.extractor.stream.AudioStream;
28+
import org.schabi.newpipe.extractor.stream.Description;
29+
import org.schabi.newpipe.extractor.stream.StreamExtractor;
30+
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
31+
import org.schabi.newpipe.extractor.stream.StreamType;
32+
import org.schabi.newpipe.extractor.stream.VideoStream;
2233

23-
import javax.annotation.Nonnull;
24-
import javax.annotation.Nullable;
2534
import java.io.IOException;
2635
import java.io.UnsupportedEncodingException;
2736
import java.net.URLEncoder;
2837
import java.util.ArrayList;
2938
import java.util.Collections;
3039
import java.util.List;
31-
import java.util.Locale;
3240

33-
import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
34-
import static org.schabi.newpipe.extractor.utils.Utils.*;
41+
import javax.annotation.Nonnull;
42+
import javax.annotation.Nullable;
3543

3644
public class SoundcloudStreamExtractor extends StreamExtractor {
3745
private JsonObject track;
@@ -53,8 +61,10 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
5361
if (policy.equals("SNIP")) {
5462
throw new SoundCloudGoPlusContentException();
5563
}
56-
if (policy.equals("BLOCK")) throw new GeographicRestrictionException(
64+
if (policy.equals("BLOCK")) {
65+
throw new GeographicRestrictionException(
5766
"This track is not available in user's country");
67+
}
5868
throw new ContentNotAvailableException("Content not available: policy " + policy);
5969
}
6070
}
@@ -152,7 +162,9 @@ public List<AudioStream> getAudioStreams() throws ExtractionException {
152162
// Streams can be streamable and downloadable - or explicitly not.
153163
// For playing the track, it is only necessary to have a streamable track.
154164
// If this is not the case, this track might not be published yet.
155-
if (!track.getBoolean("streamable") || !isAvailable) return audioStreams;
165+
if (!track.getBoolean("streamable") || !isAvailable) {
166+
return audioStreams;
167+
}
156168

157169
try {
158170
final JsonArray transcodings = track.getObject("media").getArray("transcodings");
@@ -172,8 +184,8 @@ private static boolean checkMp3ProgressivePresence(final JsonArray transcodings)
172184
boolean presence = false;
173185
for (final Object transcoding : transcodings) {
174186
final JsonObject transcodingJsonObject = (JsonObject) transcoding;
175-
if (transcodingJsonObject.getString("preset").contains("mp3") &&
176-
transcodingJsonObject.getObject("format").getString("protocol")
187+
if (transcodingJsonObject.getString("preset").contains("mp3")
188+
&& transcodingJsonObject.getObject("format").getString("protocol")
177189
.equals("progressive")) {
178190
presence = true;
179191
break;
@@ -345,10 +357,9 @@ public List<String> getTags() {
345357
final List<String> tags = new ArrayList<>();
346358
String escapedTag = "";
347359
boolean isEscaped = false;
348-
for (int i = 0; i < tagList.length; i++) {
349-
String tag = tagList[i];
360+
for (final String tag : tagList) {
350361
if (tag.startsWith("\"")) {
351-
escapedTag += tagList[i].replace("\"", "");
362+
escapedTag += tag.replace("\"", "");
352363
isEscaped = true;
353364
} else if (isEscaped) {
354365
if (tag.endsWith("\"")) {
@@ -358,7 +369,7 @@ public List<String> getTags() {
358369
} else {
359370
escapedTag += " " + tag;
360371
}
361-
} else if (!tag.isEmpty()){
372+
} else if (!tag.isEmpty()) {
362373
tags.add(tag);
363374
}
364375
}

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

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ public String getRelatedUrl() {
3434
@Override
3535
public List<SubscriptionItem> fromChannelUrl(final String channelUrl) throws IOException,
3636
ExtractionException {
37-
if (channelUrl == null) throw new InvalidSourceException("Channel url is null");
37+
if (channelUrl == null) {
38+
throw new InvalidSourceException("Channel url is null");
39+
}
3840

3941
final String id;
4042
try {
@@ -53,18 +55,15 @@ public List<SubscriptionItem> fromChannelUrl(final String channelUrl) throws IOE
5355
return toSubscriptionItems(collector.getItems());
5456
}
5557

56-
private String getUrlFrom(String channelUrl) {
57-
channelUrl = replaceHttpWithHttps(channelUrl);
58-
59-
if (!channelUrl.startsWith(HTTPS)) {
60-
if (!channelUrl.contains("soundcloud.com/")) {
61-
channelUrl = "https://soundcloud.com/" + channelUrl;
62-
} else {
63-
channelUrl = HTTPS + channelUrl;
64-
}
58+
private String getUrlFrom(final String channelUrl) {
59+
final String fixedUrl = replaceHttpWithHttps(channelUrl);
60+
if (fixedUrl.startsWith(HTTPS)) {
61+
return channelUrl;
62+
} else if (!fixedUrl.contains("soundcloud.com/")) {
63+
return "https://soundcloud.com/" + fixedUrl;
64+
} else {
65+
return HTTPS + fixedUrl;
6566
}
66-
67-
return channelUrl;
6867
}
6968

7069
/*//////////////////////////////////////////////////////////////////////////

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ public List<String> suggestionList(final String query) throws IOException,
3939
try {
4040
final JsonArray collection = JsonParser.object().from(response).getArray("collection");
4141
for (final Object suggestion : collection) {
42-
if (suggestion instanceof JsonObject) suggestions.add(((JsonObject) suggestion)
43-
.getString("query"));
42+
if (suggestion instanceof JsonObject) {
43+
suggestions.add(((JsonObject) suggestion).getString("query"));
44+
}
4445
}
4546

4647
return suggestions;

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/linkHandler/SoundcloudChannelLinkHandlerFactory.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88

99
import java.util.List;
1010

11-
public class SoundcloudChannelLinkHandlerFactory extends ListLinkHandlerFactory {
12-
private static final SoundcloudChannelLinkHandlerFactory instance =
13-
new SoundcloudChannelLinkHandlerFactory();
14-
private static final String URL_PATTERN ="^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+"
11+
public final class SoundcloudChannelLinkHandlerFactory extends ListLinkHandlerFactory {
12+
private static final SoundcloudChannelLinkHandlerFactory INSTANCE
13+
= new SoundcloudChannelLinkHandlerFactory();
14+
private static final String URL_PATTERN = "^https?://(www\\.|m\\.)?soundcloud.com/[0-9a-z_-]+"
1515
+ "(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$";
1616

17+
private SoundcloudChannelLinkHandlerFactory() {
18+
}
19+
1720
public static SoundcloudChannelLinkHandlerFactory getInstance() {
18-
return instance;
21+
return INSTANCE;
1922
}
2023

2124

0 commit comments

Comments
 (0)