package ctbrec.sites.showup;

import java.io.File;
import java.io.IOException;

import com.iheartradio.m3u8.ParseException;
import com.iheartradio.m3u8.PlaylistException;

import ctbrec.Recording;
import ctbrec.io.HttpClient;
import ctbrec.recorder.PlaylistGenerator;
import ctbrec.recorder.download.hls.HlsDownload;

public class ShowupDownload extends HlsDownload {

    public ShowupDownload(HttpClient client) {
        super(client);
    }

    @Override
    protected File generatePlaylist(Recording recording) throws IOException, ParseException, PlaylistException {
        File recDir = recording.getAbsoluteFile();
        if (!config.getSettings().generatePlaylist) {
            return null;
        }
        PlaylistGenerator playlistGenerator = PlaylistGenerator.newInstance(config.getSettings().fastPlaylistGenerator);
        playlistGenerator.addProgressListener(recording::setProgress);
        File playlist = playlistGenerator.generate(recDir, "mp4");
        recording.setProgress(-1);
        return playlist;
    }
}
