Skip to content

Commit

Permalink
Stream segments: Remove exception throwing
Browse files Browse the repository at this point in the history
  • Loading branch information
vkay94 committed Dec 11, 2020
1 parent c10100f commit 34642c2
Showing 1 changed file with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1081,32 +1081,32 @@ public List<StreamSegment> getStreamSegments() {
}
}

if (segmentArray == null) {
throw new Exception("Couldn't find valid segments");
}

final long duration = getLength();
if (segmentArray != null) {
final long duration = getLength();

for (final Object object : segmentArray) {
final JsonObject segmentJson = ((JsonObject) object).getObject("macroMarkersListItemRenderer");
for (final Object object : segmentArray) {
final JsonObject segmentJson = ((JsonObject) object).getObject("macroMarkersListItemRenderer");

final int startTimeSeconds = segmentJson.getObject("onTap").getObject("watchEndpoint")
.getInt("startTimeSeconds", -1);
final int startTimeSeconds = segmentJson.getObject("onTap").getObject("watchEndpoint")
.getInt("startTimeSeconds", -1);

if (startTimeSeconds > duration) {
// Rarely there are streams which show a greater length in the search results
// than it's parsed on the details page, so ignore invalid segments set by uploader.
break;
}
if (startTimeSeconds > duration) {
// Rarely there are streams which show a greater length in the search results
// than it's parsed on the details page, so ignore invalid segments set by uploader.
break;
}

final String title = getTextFromObject(segmentJson.getObject("title"));
final JsonArray previewsArray = segmentJson.getObject("thumbnail").getArray("thumbnails");
final String title = getTextFromObject(segmentJson.getObject("title"));
final JsonArray previewsArray = segmentJson.getObject("thumbnail").getArray("thumbnails");

final StreamSegment segment = new StreamSegment(title, startTimeSeconds);
// Assume that the thumbnail with the highest resolution is at the last position
segment.setPreviewUrl(previewsArray.getObject(previewsArray.size() - 1).getString("url"));
segment.setUrl(getUrl() + "?t=" + startTimeSeconds);
segments.add(segment);
final StreamSegment segment = new StreamSegment(title, startTimeSeconds);
if (!previewsArray.isEmpty()) {
// Assume that the thumbnail with the highest resolution is at the last position
segment.setPreviewUrl(previewsArray.getObject(previewsArray.size() - 1).getString("url"));
}
segment.setUrl(getUrl() + "?t=" + startTimeSeconds);
segments.add(segment);
}
}
} catch (Exception ignored) {
}
Expand Down

0 comments on commit 34642c2

Please sign in to comment.