2018-05-26 19:15:45 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.soundcloud;
|
|
|
|
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
|
2018-07-13 18:02:40 +02:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
2018-05-26 19:15:45 +02:00
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import java.net.URLEncoder;
|
2018-07-01 16:21:40 +02:00
|
|
|
import java.util.List;
|
2018-05-26 19:15:45 +02:00
|
|
|
|
2018-07-13 18:02:40 +02:00
|
|
|
public class SoundcloudSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
2018-05-26 19:15:45 +02:00
|
|
|
public static final String CHARSET_UTF_8 = "UTF-8";
|
|
|
|
|
|
|
|
public static final String TRACKS = "tracks";
|
|
|
|
public static final String USERS = "users";
|
2018-07-19 16:16:37 +02:00
|
|
|
public static final String PLAYLISTS = "playlists";
|
2018-07-19 16:06:44 +02:00
|
|
|
public static final String ALL = "all";
|
2018-05-26 19:15:45 +02:00
|
|
|
|
2018-06-01 19:08:49 +02:00
|
|
|
public static final int ITEMS_PER_PAGE = 10;
|
|
|
|
|
2018-05-26 19:15:45 +02:00
|
|
|
@Override
|
2018-07-01 16:21:40 +02:00
|
|
|
public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
|
2018-05-26 19:15:45 +02:00
|
|
|
try {
|
|
|
|
String url = "https://api-v2.soundcloud.com/search";
|
|
|
|
|
2018-07-01 16:21:40 +02:00
|
|
|
if(contentFilter.size() > 0) {
|
|
|
|
switch (contentFilter.get(0)) {
|
2018-05-26 19:15:45 +02:00
|
|
|
case TRACKS:
|
|
|
|
url += "/tracks";
|
|
|
|
break;
|
|
|
|
case USERS:
|
|
|
|
url += "/users";
|
|
|
|
break;
|
2018-07-19 16:16:37 +02:00
|
|
|
case PLAYLISTS:
|
2018-05-26 19:15:45 +02:00
|
|
|
url += "/playlists";
|
|
|
|
break;
|
2018-07-19 16:06:44 +02:00
|
|
|
case ALL:
|
2018-05-26 19:15:45 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return url + "?q=" + URLEncoder.encode(id, CHARSET_UTF_8)
|
|
|
|
+ "&client_id=" + SoundcloudParsingHelper.clientId()
|
2018-06-01 19:08:49 +02:00
|
|
|
+ "&limit=" + ITEMS_PER_PAGE
|
|
|
|
+ "&offset=0";
|
2018-05-26 19:15:45 +02:00
|
|
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
throw new ParsingException("Could not encode query", e);
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new ParsingException("Could not get client id", e);
|
|
|
|
} catch (ReCaptchaException e) {
|
|
|
|
throw new ParsingException("ReCaptcha required", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getAvailableContentFilter() {
|
|
|
|
return new String[] {
|
2018-07-19 16:06:44 +02:00
|
|
|
ALL,
|
2018-07-13 18:02:40 +02:00
|
|
|
TRACKS,
|
|
|
|
USERS,
|
2018-07-19 16:16:37 +02:00
|
|
|
PLAYLISTS};
|
2018-05-26 19:15:45 +02:00
|
|
|
}
|
|
|
|
}
|