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/>.
|
|
|
|
*/
|
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
2018-09-15 21:47:53 +02:00
|
|
|
import org.schabi.newpipe.extractor.utils.Localization;
|
2017-08-06 22:20:15 +02:00
|
|
|
|
2018-02-10 03:46:05 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
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
|
|
|
*/
|
2017-03-01 18:47:52 +01:00
|
|
|
public class NewPipe {
|
2017-08-06 22:20:15 +02:00
|
|
|
private static Downloader downloader = null;
|
2018-09-15 21:47:53 +02:00
|
|
|
private static Localization localization = null;
|
2017-03-01 18:47:52 +01:00
|
|
|
|
|
|
|
private NewPipe() {
|
|
|
|
}
|
|
|
|
|
2018-09-15 21:47:53 +02:00
|
|
|
public static void init(Downloader d, Localization l) {
|
2017-08-06 22:20:15 +02:00
|
|
|
downloader = d;
|
2018-09-15 21:47:53 +02:00
|
|
|
localization = l;
|
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
|
|
|
|
|
|
|
public static StreamingService getService(int serviceId) throws ExtractionException {
|
2018-02-10 03:46:05 +01:00
|
|
|
for (StreamingService service : ServiceList.all()) {
|
|
|
|
if (service.getServiceId() == serviceId) {
|
|
|
|
return service;
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
throw 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
|
|
|
|
2017-03-01 18:47:52 +01:00
|
|
|
public static StreamingService getService(String serviceName) throws ExtractionException {
|
2018-02-10 03:46:05 +01:00
|
|
|
for (StreamingService service : ServiceList.all()) {
|
|
|
|
if (service.getServiceInfo().getName().equals(serviceName)) {
|
|
|
|
return service;
|
2017-08-06 22:20:15 +02:00
|
|
|
}
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
2017-08-06 22:20:15 +02:00
|
|
|
throw 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
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
public static StreamingService getServiceByUrl(String url) throws ExtractionException {
|
2018-02-10 03:46:05 +01:00
|
|
|
for (StreamingService service : ServiceList.all()) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
public static int getIdOfService(String serviceName) {
|
|
|
|
try {
|
|
|
|
//noinspection ConstantConditions
|
|
|
|
return getService(serviceName).getServiceId();
|
|
|
|
} catch (ExtractionException ignored) {
|
|
|
|
return -1;
|
|
|
|
}
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
|
2017-08-06 22:20:15 +02:00
|
|
|
public static String getNameOfService(int id) {
|
|
|
|
try {
|
|
|
|
//noinspection ConstantConditions
|
2018-02-10 03:46:05 +01:00
|
|
|
return getService(id).getServiceInfo().getName();
|
2017-08-06 22:20:15 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
System.err.println("Service id not known");
|
|
|
|
e.printStackTrace();
|
|
|
|
return "<unknown>";
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|
|
|
|
}
|
2018-09-15 21:47:53 +02:00
|
|
|
|
|
|
|
public static void setLocalization(Localization localization) {
|
|
|
|
NewPipe.localization = localization;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Localization getLocalization() {
|
|
|
|
return localization;
|
|
|
|
}
|
2017-03-01 18:47:52 +01:00
|
|
|
}
|