diff --git a/common/src/main/java/ctbrec/sites/manyvids/MVLiveHlsDownload.java b/common/src/main/java/ctbrec/sites/manyvids/MVLiveHlsDownload.java new file mode 100644 index 00000000..de0eab83 --- /dev/null +++ b/common/src/main/java/ctbrec/sites/manyvids/MVLiveHlsDownload.java @@ -0,0 +1,52 @@ +package ctbrec.sites.manyvids; + +import java.io.IOException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ctbrec.io.HttpClient; +import ctbrec.recorder.download.hls.HlsDownload; + +public class MVLiveHlsDownload extends HlsDownload { + private static final Logger LOG = LoggerFactory.getLogger(MVLiveMergedHlsDownload.class); + + private ScheduledExecutorService scheduler; + + public MVLiveHlsDownload(HttpClient client) { + super(client); + } + + @Override + public void start() throws IOException { + try { + scheduler = new ScheduledThreadPoolExecutor(1, r -> { + Thread t = new Thread(r); + t.setDaemon(true); + t.setName("MVLive CF cookie updater"); + t.setPriority(Thread.MIN_PRIORITY); + return t; + }); + scheduler.scheduleAtFixedRate(() -> updateCloudFlareCookies(), 120, 120, TimeUnit.SECONDS); + updateCloudFlareCookies(); + super.start(); + } finally { + scheduler.shutdown(); + + } + } + + private void updateCloudFlareCookies() { + try { + ((MVLiveModel)getModel()).updateCloudFlareCookies(); + } catch (IOException e) { + LOG.error("Couldn't update cloudflare cookies for model {}", getModel(), e); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + LOG.error("Couldn't update cloudflare cookies for model {}", getModel(), e); + } + } +} diff --git a/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java b/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java index 4812795b..681ddab0 100644 --- a/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java +++ b/common/src/main/java/ctbrec/sites/manyvids/MVLiveModel.java @@ -34,7 +34,6 @@ import ctbrec.StringUtil; import ctbrec.io.HttpException; import ctbrec.recorder.download.Download; import ctbrec.recorder.download.StreamSource; -import ctbrec.recorder.download.hls.HlsDownload; import okhttp3.Request; import okhttp3.Response; @@ -213,7 +212,7 @@ public class MVLiveModel extends AbstractModel { @Override public Download createDownload() { if (Config.isServerMode() && !Config.getInstance().getSettings().recordSingleFile) { - return new HlsDownload(getHttpClient()); + return new MVLiveHlsDownload(getHttpClient()); } else { return new MVLiveMergedHlsDownload(getHttpClient()); }