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 {
LOG.trace("Loading master playlist {}", getPlaylistUrl());
Request req = new Request.Builder().url(getPlaylistUrl()).build();
Response response = site.getHttpClient().execute(req);
try {
InputStream inputStream = response.body().byteStream();
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist playlist = parser.parse();
MasterPlaylist master = playlist.getMasterPlaylist();
return master;
} finally {
response.close();
try (Response response = site.getHttpClient().execute(req)) {
if (response.isSuccessful()) {
InputStream inputStream = response.body().byteStream();
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist playlist = parser.parse();
MasterPlaylist master = playlist.getMasterPlaylist();
return master;
} else {
throw new HttpException(response.code(), "Couldn't download HLS playlist");
}
}
}