diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java index 7bdb23ab..3a1980b5 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/Info.java @@ -1,5 +1,6 @@ package org.schabi.newpipe.extractor; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import java.io.Serializable; @@ -72,6 +73,15 @@ public abstract class Info implements Serializable { 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() { return id; } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java b/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java index fbb90a18..cdd53684 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java @@ -99,7 +99,6 @@ public class NewPipe { public static int getIdOfService(String serviceName) { try { - //noinspection ConstantConditions return getService(serviceName).getServiceId(); } catch (ExtractionException ignored) { return -1; @@ -108,7 +107,6 @@ public class NewPipe { public static String getNameOfService(int id) { try { - //noinspection ConstantConditions return getService(id).getServiceInfo().getName(); } catch (Exception e) { System.err.println("Service id not known");