Update playlist all the time

Before the playlist was only retrieved, when it was empty (on the
initial call). Now the playlist is updated every time.
This commit is contained in:
0xb00bface 2020-12-21 18:15:06 +01:00
parent 43d8b9d2de
commit 8fe48f91b7
2 changed files with 19 additions and 20 deletions

View File

@ -2,7 +2,7 @@
========================
* Fixed MVLive recordings once again
* Fix: "Check URLs" button stays inactive after the first run
* ~~Fix: recordings for some Cam4 models still didn't start~~
* Fix: recordings for some Cam4 models still didn't start
* Added "space used" to recordings tab
* Added menu item to add models in paused state to the "Recording" tab
* Added server setting to choose between fast and accurate playlist generation

View File

@ -33,6 +33,7 @@ import com.iheartradio.m3u8.data.StreamInfo;
import ctbrec.AbstractModel;
import ctbrec.Config;
import ctbrec.StringUtil;
import ctbrec.io.HtmlParser;
import ctbrec.io.HttpException;
import ctbrec.recorder.download.StreamSource;
@ -53,12 +54,12 @@ public class Cam4Model extends AbstractModel {
if (ignoreCache || onlineState == UNKNOWN) {
try {
loadModelDetails();
LOG.info("Final playlist URL for {} {}", getName(), getPlaylistUrl());
getPlaylistUrl();
} catch (Exception e) {
onlineState = OFFLINE;
}
}
return onlineState == ONLINE && !privateRoom && playlistUrl != null && !playlistUrl.isEmpty();
return onlineState == ONLINE && !privateRoom && StringUtil.isNotBlank(playlistUrl);
}
private void loadModelDetails() throws IOException {
@ -117,18 +118,16 @@ public class Cam4Model extends AbstractModel {
}
private String getPlaylistUrl() throws IOException {
if (playlistUrl == null || playlistUrl.trim().isEmpty()) {
String page = loadModelPage();
Matcher m = Pattern.compile("hlsUrl\\s*:\\s*'(.*?)'", DOTALL | MULTILINE).matcher(page);
if (m.find()) {
playlistUrl = m.group(1);
} else {
LOG.debug("hlsURl not in page");
getPlaylistUrlFromStreamUrl();
}
if (playlistUrl == null) {
throw new IOException("Couldn't determine playlist url");
}
String page = loadModelPage();
Matcher m = Pattern.compile("hlsUrl\\s*:\\s*'(.*?)'", DOTALL | MULTILINE).matcher(page);
if (m.find()) {
playlistUrl = m.group(1);
} else {
LOG.debug("hlsUrl not in page");
getPlaylistUrlFromStreamUrl();
}
if (playlistUrl == null) {
throw new IOException("Couldn't determine playlist url");
}
return playlistUrl;
}
@ -163,15 +162,15 @@ public class Cam4Model extends AbstractModel {
}
private String loadModelPage() throws IOException {
Request req = new Request.Builder()
Request req = new Request.Builder() // @formatter:off
.url(getUrl())
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.header(ACCEPT, "text/html")
.header(ACCEPT_LANGUAGE, "en")
.header(ACCEPT, "*/*")
.header(ACCEPT_LANGUAGE, "*")
.header(CACHE_CONTROL, NO_CACHE)
.header(PRAGMA, NO_CACHE)
.header(REFERER, site.getBaseUrl())
.build();
.header(REFERER, getUrl())
.build(); // @formatter:on
try (Response response = site.getHttpClient().execute(req)) {
if (response.isSuccessful()) {
return response.body().string();