Move SoundcloudExtractorHelper methods to SoundcloudParsingHelper

This commit is contained in:
wb9688 2018-02-21 09:23:57 +01:00
parent 7716b14378
commit c08cef9331
4 changed files with 34 additions and 41 deletions

View File

@ -1,35 +0,0 @@
package org.schabi.newpipe.extractor.services.soundcloud;
import com.grack.nanojson.JsonObject;
import javax.annotation.Nonnull;
public class SoundcloudExtractorHelper {
private static final String HTTP = "http://";
private static final String HTTPS = "https://";
private static String replaceHttpWithHttps(final String url) {
if(!url.isEmpty() && url.startsWith(HTTP)) {
return HTTPS + url.substring(HTTP.length());
}
return url;
}
@Nonnull
static String getUploaderUrl(JsonObject object) {
String url = object.getObject("user").getString("permalink_url", "");
return replaceHttpWithHttps(url);
}
@Nonnull
static String getAvatarUrl(JsonObject object) {
String url = object.getObject("user", new JsonObject()).getString("avatar_url", "");
return replaceHttpWithHttps(url);
}
public static String getUploaderName(JsonObject object) {
return object.getObject("user").getString("username", "");
}
}

View File

@ -21,9 +21,14 @@ import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.annotation.Nonnull;
public class SoundcloudParsingHelper {
private static String clientId;
private static final String HTTP = "http://";
private static final String HTTPS = "https://";
private SoundcloudParsingHelper() {
}
@ -158,4 +163,27 @@ public class SoundcloudParsingHelper {
public static String getStreamsFromApi(StreamInfoItemCollector collector, String apiUrl) throws ReCaptchaException, ParsingException, IOException {
return getStreamsFromApi(collector, apiUrl, false);
}
private static String replaceHttpWithHttps(final String url) {
if(!url.isEmpty() && url.startsWith(HTTP)) {
return HTTPS + url.substring(HTTP.length());
}
return url;
}
@Nonnull
static String getUploaderUrl(JsonObject object) {
String url = object.getObject("user").getString("permalink_url", "");
return replaceHttpWithHttps(url);
}
@Nonnull
static String getAvatarUrl(JsonObject object) {
String url = object.getObject("user", new JsonObject()).getString("avatar_url", "");
return replaceHttpWithHttps(url);
}
public static String getUploaderName(JsonObject object) {
return object.getObject("user").getString("username", "");
}
}

View File

@ -68,17 +68,17 @@ public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
@Override
public String getUploaderUrl() {
return SoundcloudExtractorHelper.getUploaderUrl(playlist);
return SoundcloudParsingHelper.getUploaderUrl(playlist);
}
@Override
public String getUploaderName() {
return SoundcloudExtractorHelper.getUploaderName(playlist);
return SoundcloudParsingHelper.getUploaderName(playlist);
}
@Override
public String getUploaderAvatarUrl() {
return SoundcloudExtractorHelper.getAvatarUrl(playlist);
return SoundcloudParsingHelper.getAvatarUrl(playlist);
}
@Override

View File

@ -102,19 +102,19 @@ public class SoundcloudStreamExtractor extends StreamExtractor {
@Nonnull
@Override
public String getUploaderUrl() {
return SoundcloudExtractorHelper.getUploaderUrl(track);
return SoundcloudParsingHelper.getUploaderUrl(track);
}
@Nonnull
@Override
public String getUploaderName() {
return SoundcloudExtractorHelper.getUploaderName(track);
return SoundcloudParsingHelper.getUploaderName(track);
}
@Nonnull
@Override
public String getUploaderAvatarUrl() {
return SoundcloudExtractorHelper.getAvatarUrl(track);
return SoundcloudParsingHelper.getAvatarUrl(track);
}
@Override