Remove retry loop in getNextSegments
This might cause blocks by MFC because we are asking for a resource, which is not available.
This commit is contained in:
parent
a37a018159
commit
0c7650f94f
|
@ -75,7 +75,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
|||
};
|
||||
}
|
||||
|
||||
protected SegmentPlaylist getNextSegments(String segmentsURL) throws Exception {
|
||||
protected SegmentPlaylist getNextSegments(String segmentsURL) throws IOException, ParseException, PlaylistException {
|
||||
URL segmentsUrl = new URL(segmentsURL);
|
||||
Request request = new Request.Builder()
|
||||
.url(segmentsUrl)
|
||||
|
@ -87,61 +87,46 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
|||
.header(REFERER, Optional.ofNullable(model).map(Model::getSite).map(Site::getBaseUrl).orElse(""))
|
||||
.build();
|
||||
|
||||
Exception lastException = null;
|
||||
for (int tries = 1; tries <= 10 && running; tries++) {
|
||||
try (Response response = client.execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
String body = response.body().string();
|
||||
if (!body.contains("#EXTINF")) {
|
||||
// no segments, empty playlist
|
||||
return new SegmentPlaylist(segmentsURL);
|
||||
}
|
||||
try (Response response = client.execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
String body = response.body().string();
|
||||
if (!body.contains("#EXTINF")) {
|
||||
// no segments, empty playlist
|
||||
return new SegmentPlaylist(segmentsURL);
|
||||
}
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
|
||||
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
||||
Playlist playlist = parser.parse();
|
||||
if (playlist.hasMediaPlaylist()) {
|
||||
MediaPlaylist mediaPlaylist = playlist.getMediaPlaylist();
|
||||
SegmentPlaylist lsp = new SegmentPlaylist(segmentsURL);
|
||||
lsp.seq = mediaPlaylist.getMediaSequenceNumber();
|
||||
lsp.targetDuration = mediaPlaylist.getTargetDuration();
|
||||
List<TrackData> tracks = mediaPlaylist.getTracks();
|
||||
for (TrackData trackData : tracks) {
|
||||
String uri = trackData.getUri();
|
||||
if (!uri.startsWith("http")) {
|
||||
String tmpurl = segmentsUrl.toString();
|
||||
tmpurl = tmpurl.substring(0, tmpurl.lastIndexOf('/') + 1);
|
||||
uri = tmpurl + uri;
|
||||
}
|
||||
lsp.totalDuration += trackData.getTrackInfo().duration;
|
||||
lsp.lastSegDuration = trackData.getTrackInfo().duration;
|
||||
lsp.segments.add(uri);
|
||||
if (trackData.hasEncryptionData()) {
|
||||
lsp.encrypted = true;
|
||||
EncryptionData data = trackData.getEncryptionData();
|
||||
lsp.encryptionKeyUrl = data.getUri();
|
||||
lsp.encryptionMethod = data.getMethod().getValue();
|
||||
}
|
||||
InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
|
||||
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
||||
Playlist playlist = parser.parse();
|
||||
if (playlist.hasMediaPlaylist()) {
|
||||
MediaPlaylist mediaPlaylist = playlist.getMediaPlaylist();
|
||||
SegmentPlaylist lsp = new SegmentPlaylist(segmentsURL);
|
||||
lsp.seq = mediaPlaylist.getMediaSequenceNumber();
|
||||
lsp.targetDuration = mediaPlaylist.getTargetDuration();
|
||||
List<TrackData> tracks = mediaPlaylist.getTracks();
|
||||
for (TrackData trackData : tracks) {
|
||||
String uri = trackData.getUri();
|
||||
if (!uri.startsWith("http")) {
|
||||
String tmpurl = segmentsUrl.toString();
|
||||
tmpurl = tmpurl.substring(0, tmpurl.lastIndexOf('/') + 1);
|
||||
uri = tmpurl + uri;
|
||||
}
|
||||
lsp.totalDuration += trackData.getTrackInfo().duration;
|
||||
lsp.lastSegDuration = trackData.getTrackInfo().duration;
|
||||
lsp.segments.add(uri);
|
||||
if (trackData.hasEncryptionData()) {
|
||||
lsp.encrypted = true;
|
||||
EncryptionData data = trackData.getEncryptionData();
|
||||
lsp.encryptionKeyUrl = data.getUri();
|
||||
lsp.encryptionMethod = data.getMethod().getValue();
|
||||
}
|
||||
return lsp;
|
||||
}
|
||||
throw new InvalidPlaylistException("Playlist has no media playlist");
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.debug("Couldn't download HLS playlist (try {}) {} - [{}]", tries, e.getMessage(), segmentsURL);
|
||||
lastException = e;
|
||||
if (!getModel().isOnline(true)) {
|
||||
break;
|
||||
return lsp;
|
||||
}
|
||||
throw new InvalidPlaylistException("Playlist has no media playlist");
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
waitSomeTime(100 * tries);
|
||||
}
|
||||
if (lastException != null) {
|
||||
throw lastException;
|
||||
} else {
|
||||
throw new IOException("Couldn't download HLS playlist");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class LiveJasminHlsDownload extends HlsDownload {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SegmentPlaylist getNextSegments(String segments) throws Exception {
|
||||
protected SegmentPlaylist getNextSegments(String segments) throws IOException, ParseException, PlaylistException {
|
||||
if(this.segmentUrl == null) {
|
||||
this.segmentUrl = segments;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class LiveJasminMergedHlsDownload extends MergedFfmpegHlsDownload {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected SegmentPlaylist getNextSegments(String segments) throws Exception {
|
||||
protected SegmentPlaylist getNextSegments(String segments) throws IOException, ParseException, PlaylistException {
|
||||
if(this.segmentUrl == null) {
|
||||
this.segmentUrl = segments;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue