forked from j62/ctbrec
1
0
Fork 0

Improve error handling for loading the master playlist for Cam4Models

This commit is contained in:
0xboobface 2019-12-26 12:52:14 +01:00
parent 5b2ddfb825
commit c774a29421
1 changed files with 11 additions and 9 deletions

View File

@ -157,15 +157,17 @@ public class Cam4Model extends AbstractModel {
private MasterPlaylist getMasterPlaylist() throws IOException, ParseException, PlaylistException { private MasterPlaylist getMasterPlaylist() throws IOException, ParseException, PlaylistException {
LOG.trace("Loading master playlist {}", getPlaylistUrl()); LOG.trace("Loading master playlist {}", getPlaylistUrl());
Request req = new Request.Builder().url(getPlaylistUrl()).build(); Request req = new Request.Builder().url(getPlaylistUrl()).build();
Response response = site.getHttpClient().execute(req);
try { try (Response response = site.getHttpClient().execute(req)) {
InputStream inputStream = response.body().byteStream(); if (response.isSuccessful()) {
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT); InputStream inputStream = response.body().byteStream();
Playlist playlist = parser.parse(); PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
MasterPlaylist master = playlist.getMasterPlaylist(); Playlist playlist = parser.parse();
return master; MasterPlaylist master = playlist.getMasterPlaylist();
} finally { return master;
response.close(); } else {
throw new HttpException(response.code(), "Couldn't download HLS playlist");
}
} }
} }