Merge pull request #646 from Stypox/get-service
Add utility method getService() to Info object
This commit is contained in:
commit
8c42a48673
|
@ -1,5 +1,6 @@
|
||||||
package org.schabi.newpipe.extractor;
|
package org.schabi.newpipe.extractor;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -72,6 +73,15 @@ public abstract class Info implements Serializable {
|
||||||
return serviceId;
|
return serviceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public StreamingService getService() {
|
||||||
|
try {
|
||||||
|
return NewPipe.getService(serviceId);
|
||||||
|
} catch (final ExtractionException e) {
|
||||||
|
// this should be unreachable, as serviceId certainly refers to a valid service
|
||||||
|
throw new RuntimeException("Info object has invalid service id", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,7 +99,6 @@ public class NewPipe {
|
||||||
|
|
||||||
public static int getIdOfService(String serviceName) {
|
public static int getIdOfService(String serviceName) {
|
||||||
try {
|
try {
|
||||||
//noinspection ConstantConditions
|
|
||||||
return getService(serviceName).getServiceId();
|
return getService(serviceName).getServiceId();
|
||||||
} catch (ExtractionException ignored) {
|
} catch (ExtractionException ignored) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -108,7 +107,6 @@ public class NewPipe {
|
||||||
|
|
||||||
public static String getNameOfService(int id) {
|
public static String getNameOfService(int id) {
|
||||||
try {
|
try {
|
||||||
//noinspection ConstantConditions
|
|
||||||
return getService(id).getServiceInfo().getName();
|
return getService(id).getServiceInfo().getName();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("Service id not known");
|
System.err.println("Service id not known");
|
||||||
|
|
Loading…
Reference in New Issue