2017-03-01 18:47:52 +01:00
|
|
|
package org.schabi.newpipe.extractor;
|
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/*
|
2017-03-01 18:47:52 +01:00
|
|
|
* Created by Christian Schabesberger on 23.08.15.
|
|
|
|
*
|
|
|
|
* Copyright (C) Christian Schabesberger 2015 <chris.schabesberger@mailbox.org>
|
|
|
|
* NewPipe.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/>.
|
|
|
|
*/
|
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.extractor.downloader.Downloader;
|
2017-08-06 22:20:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2019-04-28 22:03:16 +02:00
|
|
|
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
|
|
|
import org.schabi.newpipe.extractor.localization.Localization;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2022-05-09 20:59:25 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import javax.annotation.Nullable;
|
2018-02-10 03:46:05 +01:00
|
|
|
|
2017-06-29 20:12:55 +02:00
|
|
|
/**
|
2017-08-06 22:20:15 +02:00
|
|
|
* Provides access to streaming services supported by NewPipe.
|
2017-06-29 20:12:55 +02:00
|
|
|
*/
|
2022-03-17 16:14:58 +01:00
|
|
|
public final class NewPipe {
|
2019-04-28 22:03:16 +02:00
|
|
|
private static Downloader downloader;
|
|
|
|
private static Localization preferredLocalization;
|
|
|
|
private static ContentCountry preferredContentCountry;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
|
|
|
private NewPipe() {
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static void init(final Downloader d) {
|
2022-03-14 22:07:01 +01:00
|
|
|
init(d, Localization.DEFAULT);
|
2019-04-28 22:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static void init(final Downloader d, final Localization l) {
|
2022-03-14 22:07:01 +01:00
|
|
|
init(d, l, l.getCountryCode().isEmpty()
|
|
|
|
? ContentCountry.DEFAULT : new ContentCountry(l.getCountryCode()));
|
2019-04-28 22:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static void init(final Downloader d, final Localization l, final ContentCountry c) {
|
2019-04-28 22:03:16 +02:00
|
|
|
downloader = d;
|
|
|
|
preferredLocalization = l;
|
|
|
|
preferredContentCountry = c;
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Downloader getDownloader() {
|
|
|
|
return downloader;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utils
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
2017-03-01 18:47:52 +01:00
|
|
|
|
2018-02-10 03:46:05 +01:00
|
|
|
public static List<StreamingService> getServices() {
|
|
|
|
return ServiceList.all();
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
2017-06-29 20:12:55 +02:00
|
|
|
|
2022-03-17 16:00:50 +01:00
|
|
|
public static StreamingService getService(final int serviceId) throws ExtractionException {
|
|
|
|
return ServiceList.all().stream()
|
|
|
|
.filter(service -> service.getServiceId() == serviceId)
|
|
|
|
.findFirst()
|
|
|
|
.orElseThrow(() -> new ExtractionException(
|
|
|
|
"There's no service with the id = \"" + serviceId + "\""));
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
2017-06-29 20:12:55 +02:00
|
|
|
|
2022-03-17 16:00:50 +01:00
|
|
|
public static StreamingService getService(final String serviceName) throws ExtractionException {
|
|
|
|
return ServiceList.all().stream()
|
|
|
|
.filter(service -> service.getServiceInfo().getName().equals(serviceName))
|
|
|
|
.findFirst()
|
|
|
|
.orElseThrow(() -> new ExtractionException(
|
|
|
|
"There's no service with the name = \"" + serviceName + "\""));
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
2017-06-29 20:12:55 +02:00
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static StreamingService getServiceByUrl(final String url) throws ExtractionException {
|
|
|
|
for (final StreamingService service : ServiceList.all()) {
|
2018-02-10 03:46:05 +01:00
|
|
|
if (service.getLinkTypeByUrl(url) != StreamingService.LinkType.NONE) {
|
|
|
|
return service;
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
throw new ExtractionException("No service can handle the url = \"" + url + "\"");
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2019-04-28 22:03:16 +02:00
|
|
|
/*//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Localization
|
|
|
|
//////////////////////////////////////////////////////////////////////////*/
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static void setupLocalization(final Localization thePreferredLocalization) {
|
|
|
|
setupLocalization(thePreferredLocalization, null);
|
2018-09-15 21:47:53 +02:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static void setupLocalization(
|
|
|
|
final Localization thePreferredLocalization,
|
|
|
|
@Nullable final ContentCountry thePreferredContentCountry) {
|
|
|
|
NewPipe.preferredLocalization = thePreferredLocalization;
|
2019-04-28 22:03:16 +02:00
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
if (thePreferredContentCountry != null) {
|
|
|
|
NewPipe.preferredContentCountry = thePreferredContentCountry;
|
2019-04-28 22:03:16 +02:00
|
|
|
} else {
|
2022-03-17 16:14:58 +01:00
|
|
|
NewPipe.preferredContentCountry = thePreferredLocalization.getCountryCode().isEmpty()
|
2019-04-28 22:03:16 +02:00
|
|
|
? ContentCountry.DEFAULT
|
2022-03-17 16:14:58 +01:00
|
|
|
: new ContentCountry(thePreferredLocalization.getCountryCode());
|
2019-04-28 22:03:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
2018-10-05 16:01:10 +02:00
|
|
|
public static Localization getPreferredLocalization() {
|
2019-04-28 22:03:16 +02:00
|
|
|
return preferredLocalization == null ? Localization.DEFAULT : preferredLocalization;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static void setPreferredLocalization(final Localization preferredLocalization) {
|
2019-04-28 22:03:16 +02:00
|
|
|
NewPipe.preferredLocalization = preferredLocalization;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nonnull
|
|
|
|
public static ContentCountry getPreferredContentCountry() {
|
|
|
|
return preferredContentCountry == null ? ContentCountry.DEFAULT : preferredContentCountry;
|
|
|
|
}
|
|
|
|
|
2022-03-17 16:14:58 +01:00
|
|
|
public static void setPreferredContentCountry(final ContentCountry preferredContentCountry) {
|
2019-04-28 22:03:16 +02:00
|
|
|
NewPipe.preferredContentCountry = preferredContentCountry;
|
2018-09-15 21:47:53 +02:00
|
|
|
}
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|