Add search link type in the extractor
This commit is contained in:
parent
9ffdd0948b
commit
fa1113bceb
|
@ -86,7 +86,8 @@ public abstract class StreamingService {
|
||||||
NONE,
|
NONE,
|
||||||
STREAM,
|
STREAM,
|
||||||
CHANNEL,
|
CHANNEL,
|
||||||
PLAYLIST
|
PLAYLIST,
|
||||||
|
SEARCH,
|
||||||
}
|
}
|
||||||
|
|
||||||
private final int serviceId;
|
private final int serviceId;
|
||||||
|
@ -140,6 +141,13 @@ public abstract class StreamingService {
|
||||||
*/
|
*/
|
||||||
public abstract ListLinkHandlerFactory getChannelLHFactory();
|
public abstract ListLinkHandlerFactory getChannelLHFactory();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Must return a new instance of an implementation of ListLinkHandlerFactory for channels.
|
||||||
|
* If support for channels is not given null must be returned.
|
||||||
|
* @return an instance of a ListLinkHandlerFactory for search link or null
|
||||||
|
*/
|
||||||
|
public abstract ListLinkHandlerFactory getSearchLHFactory();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Must return a new instance of an implementation of ListLinkHandlerFactory for playlists.
|
* Must return a new instance of an implementation of ListLinkHandlerFactory for playlists.
|
||||||
* If support for playlists is not given null must be returned.
|
* If support for playlists is not given null must be returned.
|
||||||
|
@ -282,6 +290,27 @@ public abstract class StreamingService {
|
||||||
// Utils
|
// Utils
|
||||||
//////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
public final String getIdByUrl(final String url) throws ParsingException{
|
||||||
|
final String polishedUrl = Utils.followGoogleRedirectIfNeeded(url);
|
||||||
|
|
||||||
|
final LinkHandlerFactory sH = getStreamLHFactory();
|
||||||
|
final LinkHandlerFactory cH = getChannelLHFactory();
|
||||||
|
final LinkHandlerFactory pH = getPlaylistLHFactory();
|
||||||
|
final LinkHandlerFactory searchH = getSearchLHFactory();
|
||||||
|
|
||||||
|
if (sH != null && sH.acceptUrl(polishedUrl)) {
|
||||||
|
return sH.getId(url);
|
||||||
|
} else if (searchH != null && searchH.acceptUrl(polishedUrl)) {
|
||||||
|
return searchH.getId(url);
|
||||||
|
} else if (cH != null && cH.acceptUrl(polishedUrl)) {
|
||||||
|
return cH.getId(url);
|
||||||
|
} else if (pH != null && pH.acceptUrl(polishedUrl)) {
|
||||||
|
return pH.getId(url);
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Figures out where the link is pointing to (a channel, a video, a playlist, etc.)
|
* Figures out where the link is pointing to (a channel, a video, a playlist, etc.)
|
||||||
* @param url the url on which it should be decided of which link type it is
|
* @param url the url on which it should be decided of which link type it is
|
||||||
|
@ -293,9 +322,12 @@ public abstract class StreamingService {
|
||||||
final LinkHandlerFactory sH = getStreamLHFactory();
|
final LinkHandlerFactory sH = getStreamLHFactory();
|
||||||
final LinkHandlerFactory cH = getChannelLHFactory();
|
final LinkHandlerFactory cH = getChannelLHFactory();
|
||||||
final LinkHandlerFactory pH = getPlaylistLHFactory();
|
final LinkHandlerFactory pH = getPlaylistLHFactory();
|
||||||
|
final LinkHandlerFactory searchH = getSearchLHFactory();
|
||||||
|
|
||||||
if (sH != null && sH.acceptUrl(polishedUrl)) {
|
if (sH != null && sH.acceptUrl(polishedUrl)) {
|
||||||
return LinkType.STREAM;
|
return LinkType.STREAM;
|
||||||
|
} else if (searchH != null && searchH.acceptUrl(polishedUrl)) {
|
||||||
|
return LinkType.SEARCH;
|
||||||
} else if (cH != null && cH.acceptUrl(polishedUrl)) {
|
} else if (cH != null && cH.acceptUrl(polishedUrl)) {
|
||||||
return LinkType.CHANNEL;
|
return LinkType.CHANNEL;
|
||||||
} else if (pH != null && pH.acceptUrl(polishedUrl)) {
|
} else if (pH != null && pH.acceptUrl(polishedUrl)) {
|
||||||
|
|
|
@ -66,6 +66,11 @@ public class BandcampService extends StreamingService {
|
||||||
return new BandcampChannelLinkHandlerFactory();
|
return new BandcampChannelLinkHandlerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListLinkHandlerFactory getSearchLHFactory() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
||||||
return new BandcampPlaylistLinkHandlerFactory();
|
return new BandcampPlaylistLinkHandlerFactory();
|
||||||
|
|
|
@ -55,6 +55,11 @@ public class MediaCCCService extends StreamingService {
|
||||||
return new MediaCCCConferenceLinkHandlerFactory();
|
return new MediaCCCConferenceLinkHandlerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListLinkHandlerFactory getSearchLHFactory() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -60,6 +60,11 @@ public class PeertubeService extends StreamingService {
|
||||||
return PeertubeChannelLinkHandlerFactory.getInstance();
|
return PeertubeChannelLinkHandlerFactory.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListLinkHandlerFactory getSearchLHFactory() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
||||||
return PeertubePlaylistLinkHandlerFactory.getInstance();
|
return PeertubePlaylistLinkHandlerFactory.getInstance();
|
||||||
|
|
|
@ -63,6 +63,11 @@ public class SoundcloudService extends StreamingService {
|
||||||
return SoundcloudChannelLinkHandlerFactory.getInstance();
|
return SoundcloudChannelLinkHandlerFactory.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListLinkHandlerFactory getSearchLHFactory() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
||||||
return SoundcloudPlaylistLinkHandlerFactory.getInstance();
|
return SoundcloudPlaylistLinkHandlerFactory.getInstance();
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingE
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
|
||||||
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
|
||||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory;
|
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeTrendingLinkHandlerFactory;
|
||||||
|
@ -88,6 +89,11 @@ public class YoutubeService extends StreamingService {
|
||||||
return YoutubeChannelLinkHandlerFactory.getInstance();
|
return YoutubeChannelLinkHandlerFactory.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListLinkHandlerFactory getSearchLHFactory() {
|
||||||
|
return YoutubeSearchLinkHandlerFactory.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
public ListLinkHandlerFactory getPlaylistLHFactory() {
|
||||||
return YoutubePlaylistLinkHandlerFactory.getInstance();
|
return YoutubePlaylistLinkHandlerFactory.getInstance();
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
||||||
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||||
|
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
||||||
|
import org.schabi.newpipe.extractor.utils.Utils;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class YoutubeSearchLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||||
|
private static final YoutubeSearchLinkHandlerFactory INSTANCE
|
||||||
|
= new YoutubeSearchLinkHandlerFactory();
|
||||||
|
|
||||||
|
private YoutubeSearchLinkHandlerFactory() {}
|
||||||
|
|
||||||
|
public static YoutubeSearchLinkHandlerFactory getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUrl(final String id, final List<String> contentFilters,
|
||||||
|
final String sortFilter) {
|
||||||
|
return "https://www.youtube.com/results?search_query=" + id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId(String url) throws ParsingException {
|
||||||
|
try {
|
||||||
|
final URL urlObj = Utils.stringToURL(url);
|
||||||
|
|
||||||
|
if (!Utils.isHTTP(urlObj) || !(YoutubeParsingHelper.isYoutubeURL(urlObj)
|
||||||
|
|| YoutubeParsingHelper.isInvidioURL(urlObj))) {
|
||||||
|
throw new ParsingException("the url given is not a YouTube-URL");
|
||||||
|
}
|
||||||
|
|
||||||
|
final String listID = Utils.getQueryValue(urlObj, "search_query");
|
||||||
|
|
||||||
|
if (listID == null) {
|
||||||
|
throw new ParsingException("the URL given does not include a playlist");
|
||||||
|
}
|
||||||
|
|
||||||
|
return listID;
|
||||||
|
|
||||||
|
} catch (final Exception exception) {
|
||||||
|
throw new ParsingException("Error could not parse URL: " + exception.getMessage(),
|
||||||
|
exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onAcceptUrl(String url) throws ParsingException {
|
||||||
|
try {
|
||||||
|
getId(url);
|
||||||
|
} catch (final ParsingException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue