2017-03-01 18:47:52 +01:00
|
|
|
package org.schabi.newpipe.extractor;
|
|
|
|
|
2017-08-11 20:21:49 +02:00
|
|
|
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
|
2018-08-20 00:52:19 +02:00
|
|
|
import org.schabi.newpipe.extractor.comments.CommentsExtractor;
|
2017-03-01 18:47:52 +01:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2018-05-06 14:08:50 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2019-12-16 08:35:44 +01:00
|
|
|
import org.schabi.newpipe.extractor.feed.FeedExtractor;
|
2017-08-12 17:29:28 +02:00
|
|
|
import org.schabi.newpipe.extractor.kiosk.KioskList;
|
2022-03-17 16:14:58 +01:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandlerFactory;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandler;
|
|
|
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
|
|
|
import org.schabi.newpipe.extractor.localization.Localization;
|
|
|
|
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
|
|
|
|
import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager;
|
2017-06-29 20:12:55 +02:00
|
|
|
import org.schabi.newpipe.extractor.playlist.PlaylistExtractor;
|
2018-05-13 21:28:51 +02:00
|
|
|
import org.schabi.newpipe.extractor.search.SearchExtractor;
|
2017-06-29 20:12:55 +02:00
|
|
|
import org.schabi.newpipe.extractor.stream.StreamExtractor;
|
2018-02-22 15:52:38 +01:00
|
|
|
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.extractor.suggestion.SuggestionExtractor;
|
2020-06-27 15:47:49 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Utils;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2019-12-16 08:35:44 +01:00
|
|
|
import javax.annotation.Nullable;
|
2020-02-08 23:58:46 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2019-12-16 08:35:44 +01:00
|
|
|
|
2018-11-10 10:50:13 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) Christian Schabesberger 2018 <chris.schabesberger@mailbox.org>
|
|
|
|
* StreamingService.java is part of NewPipe.
|
|
|
|
*
|
|
|
|
* NewPipe is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* NewPipe is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-03-01 18:47:52 +01:00
|
|
|
public abstract class StreamingService {
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This class holds meta information about the service implementation.
|
|
|
|
*/
|
2018-02-10 03:46:05 +01:00
|
|
|
public static class ServiceInfo {
|
2019-11-23 22:05:41 +01:00
|
|
|
private final String name;
|
2018-10-11 21:10:22 +02:00
|
|
|
|
2018-02-10 03:46:05 +01:00
|
|
|
private final List<MediaCapability> mediaCapabilities;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2018-11-10 10:50:13 +01:00
|
|
|
/**
|
|
|
|
* Creates a new instance of a ServiceInfo
|
|
|
|
* @param name the name of the service
|
|
|
|
* @param mediaCapabilities the type of media this service can handle
|
|
|
|
*/
|
2022-03-17 16:14:58 +01:00
|
|
|
public ServiceInfo(final String name, final List<MediaCapability> mediaCapabilities) {
|
2017-08-06 22:20:15 +02:00
|
|
|
this.name = name;
|
2018-02-10 03:46:05 +01:00
|
|
|
this.mediaCapabilities = Collections.unmodifiableList(mediaCapabilities);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
2019-12-16 08:35:44 +01:00
|
|
|
|
2018-02-10 03:46:05 +01:00
|
|
|
public List<MediaCapability> getMediaCapabilities() {
|
|
|
|
return mediaCapabilities;
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum MediaCapability {
|
2019-02-15 20:27:00 +01:00
|
|
|
AUDIO, VIDEO, LIVE, COMMENTS
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2018-11-10 10:50:13 +01:00
|
|
|
/**
|
2022-03-17 16:14:58 +01:00
|
|
|
* LinkType will be used to determine which type of URL you are handling, and therefore which
|
|
|
|
* part of NewPipe should handle a certain URL.
|
2018-11-10 10:50:13 +01:00
|
|
|
*/
|
2017-03-01 18:47:52 +01:00
|
|
|
public enum LinkType {
|
|
|
|
NONE,
|
|
|
|
STREAM,
|
2017-08-11 03:23:09 +02:00
|
|
|
CHANNEL,
|
2017-03-01 18:47:52 +01:00
|
|
|
PLAYLIST
|
|
|
|
}
|
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
private final int serviceId;
|
|
|
|
private final ServiceInfo serviceInfo;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2018-11-10 10:50:13 +01:00
|
|
|
/**
|
|
|
|
* Creates a new Streaming service.
|
|
|
|
* If you Implement one do not set id within your implementation of this extractor, instead
|
2022-03-17 16:14:58 +01:00
|
|
|
* set the id when you put the extractor into {@link ServiceList}
|
2018-11-10 10:50:13 +01:00
|
|
|
* All other parameters can be set directly from the overriding constructor.
|
|
|
|
* @param id the number of the service to identify him within the NewPipe frontend
|
|
|
|
* @param name the name of the service
|
|
|
|
* @param capabilities the type of media this service can handle
|
|
|
|
*/
|
2022-03-17 16:14:58 +01:00
|
|
|
public StreamingService(final int id,
|
|
|
|
final String name,
|
|
|
|
final List<ServiceInfo.MediaCapability> capabilities) {
|
2017-08-06 22:20:15 +02:00
|
|
|
this.serviceId = id;
|
2018-02-10 03:46:05 +01:00
|
|
|
this.serviceInfo = new ServiceInfo(name, capabilities);
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public final int getServiceId() {
|
|
|
|
return serviceId;
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
public ServiceInfo getServiceInfo() {
|
|
|
|
return serviceInfo;
|
|
|
|
}
|
2017-07-10 00:43:04 +02:00
|
|
|
|
2018-02-10 03:46:05 +01:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return serviceId + ":" + serviceInfo.getName();
|
|
|
|
}
|
2019-12-16 08:35:44 +01:00
|
|
|
|
2019-11-19 22:38:17 +01:00
|
|
|
public abstract String getBaseUrl();
|
2018-02-10 03:46:05 +01:00
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
2018-05-06 14:08:50 +02:00
|
|
|
// Url Id handler
|
2019-04-28 22:03:16 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must return a new instance of an implementation of LinkHandlerFactory for streams.
|
|
|
|
* @return an instance of a LinkHandlerFactory for streams
|
|
|
|
*/
|
2018-08-05 14:14:36 +02:00
|
|
|
public abstract LinkHandlerFactory getStreamLHFactory();
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 channels or null
|
|
|
|
*/
|
2018-08-05 14:14:36 +02:00
|
|
|
public abstract ListLinkHandlerFactory getChannelLHFactory();
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must return a new instance of an implementation of ListLinkHandlerFactory for playlists.
|
|
|
|
* If support for playlists is not given null must be returned.
|
|
|
|
* @return an instance of a ListLinkHandlerFactory for playlists or null
|
|
|
|
*/
|
2018-08-05 14:14:36 +02:00
|
|
|
public abstract ListLinkHandlerFactory getPlaylistLHFactory();
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must return an instance of an implementation of SearchQueryHandlerFactory.
|
|
|
|
* @return an instance of a SearchQueryHandlerFactory
|
|
|
|
*/
|
2018-08-05 14:14:36 +02:00
|
|
|
public abstract SearchQueryHandlerFactory getSearchQHFactory();
|
2018-08-20 00:52:19 +02:00
|
|
|
public abstract ListLinkHandlerFactory getCommentsLHFactory();
|
2018-02-26 16:19:58 +01:00
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extractors
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must create a new instance of a SearchExtractor implementation.
|
|
|
|
* @param queryHandler specifies the keyword lock for, and the filters which should be applied.
|
|
|
|
* @return a new SearchExtractor instance
|
|
|
|
*/
|
2019-04-28 22:03:16 +02:00
|
|
|
public abstract SearchExtractor getSearchExtractor(SearchQueryHandler queryHandler);
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must create a new instance of a SuggestionExtractor implementation.
|
|
|
|
* @return a new SuggestionExtractor instance
|
|
|
|
*/
|
2019-04-28 22:03:16 +02:00
|
|
|
public abstract SuggestionExtractor getSuggestionExtractor();
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Outdated or obsolete. null can be returned.
|
|
|
|
* @return just null
|
|
|
|
*/
|
2018-02-22 15:52:38 +01:00
|
|
|
public abstract SubscriptionExtractor getSubscriptionExtractor();
|
2018-09-15 21:47:53 +02:00
|
|
|
|
2019-12-16 08:35:44 +01:00
|
|
|
/**
|
2022-03-17 16:14:58 +01:00
|
|
|
* This method decides which strategy will be chosen to fetch the feed. In YouTube, for example,
|
|
|
|
* a separate feed exists which is lightweight and made specifically to be used like this.
|
2019-12-16 08:35:44 +01:00
|
|
|
* <p>
|
|
|
|
* In services which there's no other way to retrieve them, null should be returned.
|
|
|
|
*
|
|
|
|
* @return a {@link FeedExtractor} instance or null.
|
|
|
|
*/
|
|
|
|
@Nullable
|
2022-03-17 16:14:58 +01:00
|
|
|
public FeedExtractor getFeedExtractor(final String url) throws ExtractionException {
|
2019-12-16 08:35:44 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2018-11-10 10:50:13 +01:00
|
|
|
/**
|
|
|
|
* Must create a new instance of a KioskList implementation.
|
|
|
|
* @return a new KioskList instance
|
|
|
|
*/
|
2018-10-05 16:01:10 +02:00
|
|
|
public abstract KioskList getKioskList() throws ExtractionException;
|
2018-09-15 21:47:53 +02:00
|
|
|
|
2018-11-10 10:50:13 +01:00
|
|
|
/**
|
|
|
|
* Must create a new instance of a ChannelExtractor implementation.
|
|
|
|
* @param linkHandler is pointing to the channel which should be handled by this new instance.
|
|
|
|
* @return a new ChannelExtractor
|
|
|
|
*/
|
2022-03-17 16:14:58 +01:00
|
|
|
public abstract ChannelExtractor getChannelExtractor(ListLinkHandler linkHandler)
|
|
|
|
throws ExtractionException;
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must crete a new instance of a PlaylistExtractor implementation.
|
|
|
|
* @param linkHandler is pointing to the playlist which should be handled by this new instance.
|
|
|
|
* @return a new PlaylistExtractor
|
|
|
|
*/
|
2022-03-17 16:14:58 +01:00
|
|
|
public abstract PlaylistExtractor getPlaylistExtractor(ListLinkHandler linkHandler)
|
|
|
|
throws ExtractionException;
|
2018-11-10 10:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Must create a new instance of a StreamExtractor implementation.
|
|
|
|
* @param linkHandler is pointing to the stream which should be handled by this new instance.
|
|
|
|
* @return a new StreamExtractor
|
|
|
|
*/
|
2022-03-17 16:14:58 +01:00
|
|
|
public abstract StreamExtractor getStreamExtractor(LinkHandler linkHandler)
|
|
|
|
throws ExtractionException;
|
2018-09-15 21:47:53 +02:00
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public abstract CommentsExtractor getCommentsExtractor(ListLinkHandler linkHandler)
|
|
|
|
throws ExtractionException;
|
2018-09-15 21:47:53 +02:00
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Extractors without link handler
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
2018-05-06 14:08:50 +02:00
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public SearchExtractor getSearchExtractor(final String query,
|
|
|
|
final List<String> contentFilter,
|
|
|
|
final String sortFilter) throws ExtractionException {
|
2018-09-15 21:47:53 +02:00
|
|
|
return getSearchExtractor(getSearchQHFactory()
|
2019-04-28 22:03:16 +02:00
|
|
|
.fromQuery(query, contentFilter, sortFilter));
|
2018-05-26 19:15:45 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public ChannelExtractor getChannelExtractor(final String id,
|
|
|
|
final List<String> contentFilter,
|
|
|
|
final String sortFilter)
|
|
|
|
throws ExtractionException {
|
2019-04-28 22:03:16 +02:00
|
|
|
return getChannelExtractor(getChannelLHFactory()
|
|
|
|
.fromQuery(id, contentFilter, sortFilter));
|
2018-05-06 14:08:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public PlaylistExtractor getPlaylistExtractor(final String id,
|
|
|
|
final List<String> contentFilter,
|
|
|
|
final String sortFilter)
|
|
|
|
throws ExtractionException {
|
2018-09-15 21:47:53 +02:00
|
|
|
return getPlaylistExtractor(getPlaylistLHFactory()
|
2019-04-28 22:03:16 +02:00
|
|
|
.fromQuery(id, contentFilter, sortFilter));
|
2018-05-06 14:08:50 +02:00
|
|
|
}
|
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Short extractors overloads
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
2018-09-15 21:47:53 +02:00
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public SearchExtractor getSearchExtractor(final String query) throws ExtractionException {
|
2019-04-28 22:03:16 +02:00
|
|
|
return getSearchExtractor(getSearchQHFactory().fromQuery(query));
|
2018-05-26 19:15:45 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public ChannelExtractor getChannelExtractor(final String url) throws ExtractionException {
|
2019-04-28 22:03:16 +02:00
|
|
|
return getChannelExtractor(getChannelLHFactory().fromUrl(url));
|
2018-05-06 14:08:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public PlaylistExtractor getPlaylistExtractor(final String url) throws ExtractionException {
|
2019-04-28 22:03:16 +02:00
|
|
|
return getPlaylistExtractor(getPlaylistLHFactory().fromUrl(url));
|
2018-05-06 14:08:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public StreamExtractor getStreamExtractor(final String url) throws ExtractionException {
|
2019-04-28 22:03:16 +02:00
|
|
|
return getStreamExtractor(getStreamLHFactory().fromUrl(url));
|
2018-05-06 14:08:50 +02:00
|
|
|
}
|
2019-10-02 07:02:01 +02:00
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public CommentsExtractor getCommentsExtractor(final String url) throws ExtractionException {
|
|
|
|
final ListLinkHandlerFactory listLinkHandlerFactory = getCommentsLHFactory();
|
|
|
|
if (listLinkHandlerFactory == null) {
|
2018-09-19 02:02:14 +02:00
|
|
|
return null;
|
|
|
|
}
|
2022-03-17 16:14:58 +01:00
|
|
|
return getCommentsExtractor(listLinkHandlerFactory.fromUrl(url));
|
2018-08-20 00:52:19 +02:00
|
|
|
}
|
2019-12-16 08:35:44 +01:00
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
2018-05-06 14:08:50 +02:00
|
|
|
|
2017-03-01 18:47:52 +01:00
|
|
|
/**
|
2018-11-10 10:50:13 +01:00
|
|
|
* 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
|
|
|
|
* @return the link type of url
|
2017-03-01 18:47:52 +01:00
|
|
|
*/
|
2020-06-28 22:44:16 +02:00
|
|
|
public final LinkType getLinkTypeByUrl(final String url) throws ParsingException {
|
|
|
|
final String polishedUrl = Utils.followGoogleRedirectIfNeeded(url);
|
2020-06-27 15:47:49 +02:00
|
|
|
|
|
|
|
final LinkHandlerFactory sH = getStreamLHFactory();
|
|
|
|
final LinkHandlerFactory cH = getChannelLHFactory();
|
|
|
|
final LinkHandlerFactory pH = getPlaylistLHFactory();
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2020-06-28 22:44:16 +02:00
|
|
|
if (sH != null && sH.acceptUrl(polishedUrl)) {
|
2017-03-01 18:47:52 +01:00
|
|
|
return LinkType.STREAM;
|
2020-06-28 22:44:16 +02:00
|
|
|
} else if (cH != null && cH.acceptUrl(polishedUrl)) {
|
2017-08-11 03:23:09 +02:00
|
|
|
return LinkType.CHANNEL;
|
2020-06-28 22:44:16 +02:00
|
|
|
} else if (pH != null && pH.acceptUrl(polishedUrl)) {
|
2017-03-12 16:15:51 +01:00
|
|
|
return LinkType.PLAYLIST;
|
2017-03-01 18:47:52 +01:00
|
|
|
} else {
|
|
|
|
return LinkType.NONE;
|
|
|
|
}
|
|
|
|
}
|
2019-04-28 22:03:16 +02:00
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Localization
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of localizations that this service supports.
|
|
|
|
*/
|
|
|
|
public List<Localization> getSupportedLocalizations() {
|
|
|
|
return Collections.singletonList(Localization.DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a list of countries that this service supports.<br>
|
|
|
|
*/
|
|
|
|
public List<ContentCountry> getSupportedCountries() {
|
|
|
|
return Collections.singletonList(ContentCountry.DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the localization that should be used in this service. It will get which localization
|
|
|
|
* the user prefer (using {@link NewPipe#getPreferredLocalization()}), then it will:
|
|
|
|
* <ul>
|
|
|
|
* <li>Check if the exactly localization is supported by this service.</li>
|
2022-03-17 16:14:58 +01:00
|
|
|
* <li>If not, check if a less specific localization is available, using only the language
|
|
|
|
* code.</li>
|
2019-04-28 22:03:16 +02:00
|
|
|
* <li>Fallback to the {@link Localization#DEFAULT default} localization.</li>
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public Localization getLocalization() {
|
|
|
|
final Localization preferredLocalization = NewPipe.getPreferredLocalization();
|
|
|
|
|
|
|
|
// Check the localization's language and country
|
|
|
|
if (getSupportedLocalizations().contains(preferredLocalization)) {
|
|
|
|
return preferredLocalization;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback to the first supported language that matches the preferred language
|
2022-03-17 16:14:58 +01:00
|
|
|
for (final Localization supportedLanguage : getSupportedLocalizations()) {
|
|
|
|
if (supportedLanguage.getLanguageCode()
|
|
|
|
.equals(preferredLocalization.getLanguageCode())) {
|
2019-04-28 22:03:16 +02:00
|
|
|
return supportedLanguage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Localization.DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-17 16:14:58 +01:00
|
|
|
* Returns the country that should be used to fetch content in this service. It will get which
|
|
|
|
* country the user prefer (using {@link NewPipe#getPreferredContentCountry()}), then it will:
|
2019-04-28 22:03:16 +02:00
|
|
|
* <ul>
|
|
|
|
* <li>Check if the country is supported by this service.</li>
|
|
|
|
* <li>If not, fallback to the {@link ContentCountry#DEFAULT default} country.</li>
|
|
|
|
* </ul>
|
|
|
|
*/
|
|
|
|
public ContentCountry getContentCountry() {
|
|
|
|
final ContentCountry preferredContentCountry = NewPipe.getPreferredContentCountry();
|
|
|
|
|
|
|
|
if (getSupportedCountries().contains(preferredContentCountry)) {
|
|
|
|
return preferredContentCountry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ContentCountry.DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-03-17 16:14:58 +01:00
|
|
|
* Get an instance of the time ago parser using the patterns related to the passed localization.
|
|
|
|
* <br><br>
|
|
|
|
* Just like {@link #getLocalization()}, it will also try to fallback to a less specific
|
|
|
|
* localization if the exact one is not available/supported.
|
2019-04-28 22:03:16 +02:00
|
|
|
*
|
2022-03-17 16:14:58 +01:00
|
|
|
* @throws IllegalArgumentException if the localization is not supported (parsing patterns are
|
|
|
|
* not present).
|
2019-04-28 22:03:16 +02:00
|
|
|
*/
|
2022-03-17 16:14:58 +01:00
|
|
|
public TimeAgoParser getTimeAgoParser(final Localization localization) {
|
2019-04-28 22:03:16 +02:00
|
|
|
final TimeAgoParser targetParser = TimeAgoPatternsManager.getTimeAgoParserFor(localization);
|
|
|
|
|
|
|
|
if (targetParser != null) {
|
|
|
|
return targetParser;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!localization.getCountryCode().isEmpty()) {
|
2022-03-17 16:14:58 +01:00
|
|
|
final Localization lessSpecificLocalization
|
|
|
|
= new Localization(localization.getLanguageCode());
|
|
|
|
final TimeAgoParser lessSpecificParser
|
|
|
|
= TimeAgoPatternsManager.getTimeAgoParserFor(lessSpecificLocalization);
|
2019-04-28 22:03:16 +02:00
|
|
|
|
|
|
|
if (lessSpecificParser != null) {
|
|
|
|
return lessSpecificParser;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"Localization is not supported (\"" + localization + "\")");
|
2019-04-28 22:03:16 +02:00
|
|
|
}
|
|
|
|
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|