forked from j62/ctbrec
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);
|
URL segmentsUrl = new URL(segmentsURL);
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(segmentsUrl)
|
.url(segmentsUrl)
|
||||||
|
@ -87,61 +87,46 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
.header(REFERER, Optional.ofNullable(model).map(Model::getSite).map(Site::getBaseUrl).orElse(""))
|
.header(REFERER, Optional.ofNullable(model).map(Model::getSite).map(Site::getBaseUrl).orElse(""))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Exception lastException = null;
|
try (Response response = client.execute(request)) {
|
||||||
for (int tries = 1; tries <= 10 && running; tries++) {
|
if (response.isSuccessful()) {
|
||||||
try (Response response = client.execute(request)) {
|
String body = response.body().string();
|
||||||
if (response.isSuccessful()) {
|
if (!body.contains("#EXTINF")) {
|
||||||
String body = response.body().string();
|
// no segments, empty playlist
|
||||||
if (!body.contains("#EXTINF")) {
|
return new SegmentPlaylist(segmentsURL);
|
||||||
// no segments, empty playlist
|
}
|
||||||
return new SegmentPlaylist(segmentsURL);
|
|
||||||
}
|
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
|
InputStream inputStream = new ByteArrayInputStream(body.getBytes(StandardCharsets.UTF_8));
|
||||||
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
||||||
Playlist playlist = parser.parse();
|
Playlist playlist = parser.parse();
|
||||||
if (playlist.hasMediaPlaylist()) {
|
if (playlist.hasMediaPlaylist()) {
|
||||||
MediaPlaylist mediaPlaylist = playlist.getMediaPlaylist();
|
MediaPlaylist mediaPlaylist = playlist.getMediaPlaylist();
|
||||||
SegmentPlaylist lsp = new SegmentPlaylist(segmentsURL);
|
SegmentPlaylist lsp = new SegmentPlaylist(segmentsURL);
|
||||||
lsp.seq = mediaPlaylist.getMediaSequenceNumber();
|
lsp.seq = mediaPlaylist.getMediaSequenceNumber();
|
||||||
lsp.targetDuration = mediaPlaylist.getTargetDuration();
|
lsp.targetDuration = mediaPlaylist.getTargetDuration();
|
||||||
List<TrackData> tracks = mediaPlaylist.getTracks();
|
List<TrackData> tracks = mediaPlaylist.getTracks();
|
||||||
for (TrackData trackData : tracks) {
|
for (TrackData trackData : tracks) {
|
||||||
String uri = trackData.getUri();
|
String uri = trackData.getUri();
|
||||||
if (!uri.startsWith("http")) {
|
if (!uri.startsWith("http")) {
|
||||||
String tmpurl = segmentsUrl.toString();
|
String tmpurl = segmentsUrl.toString();
|
||||||
tmpurl = tmpurl.substring(0, tmpurl.lastIndexOf('/') + 1);
|
tmpurl = tmpurl.substring(0, tmpurl.lastIndexOf('/') + 1);
|
||||||
uri = tmpurl + uri;
|
uri = tmpurl + uri;
|
||||||
}
|
}
|
||||||
lsp.totalDuration += trackData.getTrackInfo().duration;
|
lsp.totalDuration += trackData.getTrackInfo().duration;
|
||||||
lsp.lastSegDuration = trackData.getTrackInfo().duration;
|
lsp.lastSegDuration = trackData.getTrackInfo().duration;
|
||||||
lsp.segments.add(uri);
|
lsp.segments.add(uri);
|
||||||
if (trackData.hasEncryptionData()) {
|
if (trackData.hasEncryptionData()) {
|
||||||
lsp.encrypted = true;
|
lsp.encrypted = true;
|
||||||
EncryptionData data = trackData.getEncryptionData();
|
EncryptionData data = trackData.getEncryptionData();
|
||||||
lsp.encryptionKeyUrl = data.getUri();
|
lsp.encryptionKeyUrl = data.getUri();
|
||||||
lsp.encryptionMethod = data.getMethod().getValue();
|
lsp.encryptionMethod = data.getMethod().getValue();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return lsp;
|
|
||||||
}
|
}
|
||||||
throw new InvalidPlaylistException("Playlist has no media playlist");
|
return lsp;
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
|
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
|
@Override
|
||||||
protected SegmentPlaylist getNextSegments(String segments) throws Exception {
|
protected SegmentPlaylist getNextSegments(String segments) throws IOException, ParseException, PlaylistException {
|
||||||
if(this.segmentUrl == null) {
|
if(this.segmentUrl == null) {
|
||||||
this.segmentUrl = segments;
|
this.segmentUrl = segments;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class LiveJasminMergedHlsDownload extends MergedFfmpegHlsDownload {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SegmentPlaylist getNextSegments(String segments) throws Exception {
|
protected SegmentPlaylist getNextSegments(String segments) throws IOException, ParseException, PlaylistException {
|
||||||
if(this.segmentUrl == null) {
|
if(this.segmentUrl == null) {
|
||||||
this.segmentUrl = segments;
|
this.segmentUrl = segments;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue