Skip to content

Commit

Permalink
Merge pull request #646 from Stypox/get-service
Browse files Browse the repository at this point in the history
Add utility method getService() to Info object
  • Loading branch information
TobiGr authored Jun 5, 2021
2 parents 0ad51e7 + 2158ca4 commit 8c42a48
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 10 additions & 0 deletions extractor/src/main/java/org/schabi/newpipe/extractor/Info.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -72,6 +73,15 @@ public int getServiceId() {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public static StreamingService getServiceByUrl(String url) throws ExtractionExce

public static int getIdOfService(String serviceName) {
try {
//noinspection ConstantConditions
return getService(serviceName).getServiceId();
} catch (ExtractionException ignored) {
return -1;
Expand All @@ -108,7 +107,6 @@ public static int getIdOfService(String serviceName) {

public static String getNameOfService(int id) {
try {
//noinspection ConstantConditions
return getService(id).getServiceInfo().getName();
} catch (Exception e) {
System.err.println("Service id not known");
Expand Down

0 comments on commit 8c42a48

Please sign in to comment.