Skip to content

Commit 8c42a48

Browse files
authored
Merge pull request #646 from Stypox/get-service
Add utility method getService() to Info object
2 parents 0ad51e7 + 2158ca4 commit 8c42a48

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/Info.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.extractor;
22

3+
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
34
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
45

56
import java.io.Serializable;
@@ -72,6 +73,15 @@ public int getServiceId() {
7273
return serviceId;
7374
}
7475

76+
public StreamingService getService() {
77+
try {
78+
return NewPipe.getService(serviceId);
79+
} catch (final ExtractionException e) {
80+
// this should be unreachable, as serviceId certainly refers to a valid service
81+
throw new RuntimeException("Info object has invalid service id", e);
82+
}
83+
}
84+
7585
public String getId() {
7686
return id;
7787
}

extractor/src/main/java/org/schabi/newpipe/extractor/NewPipe.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public static StreamingService getServiceByUrl(String url) throws ExtractionExce
9999

100100
public static int getIdOfService(String serviceName) {
101101
try {
102-
//noinspection ConstantConditions
103102
return getService(serviceName).getServiceId();
104103
} catch (ExtractionException ignored) {
105104
return -1;
@@ -108,7 +107,6 @@ public static int getIdOfService(String serviceName) {
108107

109108
public static String getNameOfService(int id) {
110109
try {
111-
//noinspection ConstantConditions
112110
return getService(id).getServiceInfo().getName();
113111
} catch (Exception e) {
114112
System.err.println("Service id not known");

0 commit comments

Comments
 (0)