2017-08-04 16:21:45 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.soundcloud;
|
|
|
|
|
|
|
|
import org.jsoup.Jsoup;
|
|
|
|
import org.jsoup.nodes.Element;
|
|
|
|
import org.schabi.newpipe.extractor.NewPipe;
|
|
|
|
import org.schabi.newpipe.extractor.UrlIdHandler;
|
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
|
|
|
import org.schabi.newpipe.extractor.utils.Parser;
|
|
|
|
|
2017-08-07 18:12:51 +02:00
|
|
|
public class SoundcloudUserUrlIdHandler implements UrlIdHandler {
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2017-08-07 18:12:51 +02:00
|
|
|
private static final SoundcloudUserUrlIdHandler instance = new SoundcloudUserUrlIdHandler();
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2017-08-07 18:12:51 +02:00
|
|
|
public static SoundcloudUserUrlIdHandler getInstance() {
|
2017-08-04 16:21:45 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-07 18:12:51 +02:00
|
|
|
public String getUrl(String id) throws ParsingException {
|
2017-08-04 16:21:45 +02:00
|
|
|
try {
|
2017-08-07 18:12:51 +02:00
|
|
|
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id);
|
2017-08-04 16:21:45 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-06 22:20:15 +02:00
|
|
|
public String getId(String url) throws ParsingException {
|
2017-08-04 16:21:45 +02:00
|
|
|
try {
|
2017-08-06 22:20:15 +02:00
|
|
|
return SoundcloudParsingHelper.resolveIdWithEmbedPlayer(url);
|
2017-08-04 16:21:45 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-06 22:20:15 +02:00
|
|
|
public String cleanUrl(String complexUrl) throws ParsingException {
|
2017-08-04 16:21:45 +02:00
|
|
|
try {
|
2017-08-06 22:20:15 +02:00
|
|
|
Element ogElement = Jsoup.parse(NewPipe.getDownloader().download(complexUrl))
|
|
|
|
.select("meta[property=og:url]").first();
|
2017-08-04 16:21:45 +02:00
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
return ogElement.attr("content");
|
2017-08-04 16:21:45 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
throw new ParsingException(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-08-07 18:12:51 +02:00
|
|
|
public boolean acceptUrl(String url) {
|
2017-08-04 16:21:45 +02:00
|
|
|
String regex = "^https?://(www\\.)?soundcloud.com/[0-9a-z_-]+(/((tracks|albums|sets|reposts|followers|following)/?)?)?([#?].*)?$";
|
2017-08-07 18:12:51 +02:00
|
|
|
return Parser.isMatch(regex, url.toLowerCase());
|
2017-08-04 16:21:45 +02:00
|
|
|
}
|
|
|
|
}
|