Fix inconsistency in youtube channel urls
Urls from the youtube search extractor were "https://www.youtube.com/user/NAME" instead of "https://www.youtube.com/channel/ID". This fixes TeamNewPipe/NewPipe#2167
This commit is contained in:
parent
5f65788a2f
commit
6aa69a2df8
|
@ -47,6 +47,7 @@ import java.util.ArrayList;
|
||||||
|
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
public class YoutubeChannelExtractor extends ChannelExtractor {
|
public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
|
/*package-private*/ static final String CHANNEL_URL_BASE = "https://www.youtube.com/channel/";
|
||||||
private static final String CHANNEL_FEED_BASE = "https://www.youtube.com/feeds/videos.xml?channel_id=";
|
private static final String CHANNEL_FEED_BASE = "https://www.youtube.com/feeds/videos.xml?channel_id=";
|
||||||
private static final String CHANNEL_URL_PARAMETERS = "/videos?view=0&flow=list&sort=dd&live_view=10000";
|
private static final String CHANNEL_URL_PARAMETERS = "/videos?view=0&flow=list&sort=dd&live_view=10000";
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ public class YoutubeChannelExtractor extends ChannelExtractor {
|
||||||
@Override
|
@Override
|
||||||
public String getUrl() throws ParsingException {
|
public String getUrl() throws ParsingException {
|
||||||
try {
|
try {
|
||||||
return "https://www.youtube.com/channel/" + getId();
|
return CHANNEL_URL_BASE + getId();
|
||||||
} catch (ParsingException e) {
|
} catch (ParsingException e) {
|
||||||
return super.getUrl();
|
return super.getUrl();
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ import org.schabi.newpipe.extractor.channel.ChannelInfoItemExtractor;
|
||||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
import org.schabi.newpipe.extractor.utils.Utils;
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Created by Christian Schabesberger on 12.02.17.
|
* Created by Christian Schabesberger on 12.02.17.
|
||||||
*
|
*
|
||||||
|
@ -53,8 +56,20 @@ public class YoutubeChannelInfoItemExtractor implements ChannelInfoItemExtractor
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getUrl() throws ParsingException {
|
public String getUrl() throws ParsingException {
|
||||||
return el.select("a[class*=\"yt-uix-tile-link\"]").first()
|
String buttonTrackingUrl = el.select("button[class*=\"yt-uix-button\"]").first()
|
||||||
.attr("abs:href");
|
.attr("abs:data-href");
|
||||||
|
|
||||||
|
Pattern channelIdPattern = Pattern.compile("(?:.*?)\\%252Fchannel\\%252F(.+?)\\%26(?:.*)");
|
||||||
|
Matcher match = channelIdPattern.matcher(buttonTrackingUrl);
|
||||||
|
|
||||||
|
if (match.matches()) {
|
||||||
|
return YoutubeChannelExtractor.CHANNEL_URL_BASE + match.group(1);
|
||||||
|
} else {
|
||||||
|
// fallback method just in case youtube changes things; it should never run and tests will fail
|
||||||
|
// provides an url with "/user/NAME", that is inconsistent with stream and channel extractor
|
||||||
|
return el.select("a[class*=\"yt-uix-tile-link\"]").first()
|
||||||
|
.attr("abs:href");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue