NewPipeExtractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/SoundcloudUserUrlIdHandler....

54 lines
1.8 KiB
Java
Raw Normal View History

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-07 18:12:51 +02:00
private static final SoundcloudUserUrlIdHandler instance = new SoundcloudUserUrlIdHandler();
2017-08-07 18:12:51 +02:00
public static SoundcloudUserUrlIdHandler getInstance() {
return instance;
}
@Override
2017-08-07 18:12:51 +02:00
public String getUrl(String id) throws ParsingException {
try {
2017-08-07 18:12:51 +02:00
return SoundcloudParsingHelper.resolveUrlWithEmbedPlayer("https://api.soundcloud.com/users/" + id);
} 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 {
try {
2017-08-06 22:20:15 +02:00
return SoundcloudParsingHelper.resolveIdWithEmbedPlayer(url);
} 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 {
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-06 22:20:15 +02:00
return ogElement.attr("content");
} catch (Exception e) {
throw new ParsingException(e.getMessage(), e);
}
}
@Override
2017-08-07 18:12:51 +02:00
public boolean acceptUrl(String url) {
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());
}
}