forked from j62/ctbrec
1
0
Fork 0

Extend HlsDownload for MV Live to update the cloudflare cookies regularly

This commit is contained in:
0xb00bface 2020-08-24 15:16:45 +02:00
parent c7e39fdd98
commit d7d3e2944b
2 changed files with 53 additions and 2 deletions

View File

@ -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);
}
}
}

View File

@ -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());
}