Improve exception handling and logging for the playlist generation
This commit is contained in:
parent
89f2319345
commit
39679f3162
|
@ -41,6 +41,7 @@ import com.iheartradio.m3u8.Encoding;
|
|||
import com.iheartradio.m3u8.Format;
|
||||
import com.iheartradio.m3u8.ParseException;
|
||||
import com.iheartradio.m3u8.ParsingMode;
|
||||
import com.iheartradio.m3u8.PlaylistError;
|
||||
import com.iheartradio.m3u8.PlaylistException;
|
||||
import com.iheartradio.m3u8.PlaylistParser;
|
||||
import com.iheartradio.m3u8.data.MediaPlaylist;
|
||||
|
@ -408,8 +409,17 @@ public class LocalRecorder implements Recorder {
|
|||
if(playlist != null) {
|
||||
playlistGenerator.validate(recDir);
|
||||
}
|
||||
} catch (IOException | ParseException | PlaylistException e) {
|
||||
} catch (IOException | ParseException e) {
|
||||
LOG.error("Couldn't generate playlist file", e);
|
||||
} catch (PlaylistException e) {
|
||||
if(e.getErrors().isEmpty()) {
|
||||
LOG.error("Couldn't generate playlist file", e);
|
||||
} else {
|
||||
LOG.error("Playlist contains errors");
|
||||
for (PlaylistError error : e.getErrors()) {
|
||||
LOG.error("Error: {}", error.toString());
|
||||
}
|
||||
}
|
||||
} catch (InvalidPlaylistException e) {
|
||||
LOG.error("Playlist is invalid and will be deleted", e);
|
||||
File playlist = new File(recDir, "playlist.m3u8");
|
||||
|
|
|
@ -56,10 +56,15 @@ public class PlaylistGenerator {
|
|||
int done = 0;
|
||||
for (File file : files) {
|
||||
try {
|
||||
track.add(new TrackData.Builder()
|
||||
.withUri(file.getName())
|
||||
.withTrackInfo(new TrackInfo((float) MpegUtil.getFileDuration(file), file.getName()))
|
||||
.build());
|
||||
float duration = (float) MpegUtil.getFileDuration(file);
|
||||
if(duration <= 0) {
|
||||
throw new RuntimeException("Track has negative duration: " + file.getName());
|
||||
} else {
|
||||
track.add(new TrackData.Builder()
|
||||
.withUri(file.getName())
|
||||
.withTrackInfo(new TrackInfo(duration, file.getName()))
|
||||
.build());
|
||||
}
|
||||
} catch(Exception e) {
|
||||
LOG.warn("Couldn't determine duration for {}. Skipping this file.", file.getName());
|
||||
file.renameTo(new File(directory, file.getName()+".corrupt"));
|
||||
|
|
Loading…
Reference in New Issue