forked from j62/ctbrec
Handle empty playlists more gracefully
Check, if a playlist is empty, before parsing it with open-m3u8. If it is empty, return an empty SegmentPlaylist instead of throwing a ParseException
This commit is contained in:
parent
b854455f8a
commit
85411fea2e
|
@ -1,5 +1,6 @@
|
|||
package ctbrec.recorder.download;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
@ -33,7 +34,6 @@ import ctbrec.Config;
|
|||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.sites.fc2live.Fc2Live;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
|
@ -53,28 +53,31 @@ public abstract class AbstractHlsDownload implements Download {
|
|||
this.client = client;
|
||||
}
|
||||
|
||||
protected SegmentPlaylist getNextSegments(String segments) throws IOException, ParseException, PlaylistException {
|
||||
URL segmentsUrl = new URL(segments);
|
||||
protected SegmentPlaylist getNextSegments(String segmentsURL) throws IOException, ParseException, PlaylistException {
|
||||
URL segmentsUrl = new URL(segmentsURL);
|
||||
Request request = new Request.Builder()
|
||||
.url(segmentsUrl)
|
||||
.header("Accept", "*/*")
|
||||
.header("Accept-Language", "en-US,en;q=0.5")
|
||||
.header("User-Agent", Config.getInstance().getSettings().httpUserAgent)
|
||||
.header("Origin", Fc2Live.BASE_URL)
|
||||
.header("Referer", Fc2Live.BASE_URL)
|
||||
.header("Origin", model.getSite().getBaseUrl())
|
||||
.header("Referer", model.getSite().getBaseUrl())
|
||||
.header("Connection", "keep-alive")
|
||||
.build();
|
||||
try(Response response = client.execute(request)) {
|
||||
if(response.isSuccessful()) {
|
||||
// String body = response.body().string();
|
||||
// InputStream inputStream = new ByteArrayInputStream(body.getBytes("utf-8"));
|
||||
// LOG.debug("Segments {}", body);
|
||||
InputStream inputStream = response.body().byteStream();
|
||||
String body = response.body().string();
|
||||
if(!body.contains("#EXT-X-STREAM-INF")) {
|
||||
// no segments, empty playlist
|
||||
return new SegmentPlaylist(segmentsURL);
|
||||
}
|
||||
|
||||
InputStream inputStream = new ByteArrayInputStream(body.getBytes("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(segments);
|
||||
SegmentPlaylist lsp = new SegmentPlaylist(segmentsURL);
|
||||
lsp.seq = mediaPlaylist.getMediaSequenceNumber();
|
||||
lsp.targetDuration = mediaPlaylist.getTargetDuration();
|
||||
List<TrackData> tracks = mediaPlaylist.getTracks();
|
||||
|
|
Loading…
Reference in New Issue