From 13f192704dcf60baf44aa216c24253d4bfa50089 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 5 Jun 2021 14:14:19 +0200 Subject: [PATCH 1/2] Add utility method getService() to Info object --- .../main/java/org/schabi/newpipe/extractor/Info.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 7bdb23aba..3a1980b56 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; } From 2158ca4060cc99cfa4df86d0c4b546b3abe24941 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sat, 5 Jun 2021 14:15:44 +0200 Subject: [PATCH 2/2] Remove two unneded warning suppressions --- .../src/main/java/org/schabi/newpipe/extractor/NewPipe.java | 2 -- 1 file changed, 2 deletions(-) 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 fbb90a189..cdd536849 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");