Use a different HTTP client for each MVLive download
MVLive only allows recording of mor than one stream, if the recorder looks like different HTTP sessions. That's why we use a different HTTP client with its own cookie jar for each recording.
This commit is contained in:
parent
7015c3173f
commit
2455797fb2
|
@ -59,7 +59,7 @@ public class MVLiveClient {
|
||||||
running = true;
|
running = true;
|
||||||
|
|
||||||
if (ws == null && !connecting) {
|
if (ws == null && !connecting) {
|
||||||
fetchAuthenticationCookies();
|
httpClient.fetchAuthenticationCookies();
|
||||||
JSONObject response = getRoomLocation(model);
|
JSONObject response = getRoomLocation(model);
|
||||||
roomNumber = response.optString("floorId");
|
roomNumber = response.optString("floorId");
|
||||||
roomId = response.optString("roomId");
|
roomId = response.optString("roomId");
|
||||||
|
@ -88,18 +88,6 @@ public class MVLiveClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fetchAuthenticationCookies() throws IOException {
|
|
||||||
Request req = new Request.Builder()
|
|
||||||
.url("https://www.manyvids.com/tak-live-redirect.php")
|
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
|
||||||
.build();
|
|
||||||
try (Response response = httpClient.execute(req)) {
|
|
||||||
if (!response.isSuccessful()) {
|
|
||||||
throw new HttpException(response.code(), response.message());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPhpSessionIdCookie() {
|
private String getPhpSessionIdCookie() {
|
||||||
List<Cookie> cookies = httpClient.getCookiesByName("PHPSESSID");
|
List<Cookie> cookies = httpClient.getCookiesByName("PHPSESSID");
|
||||||
return cookies.stream().map(c -> c.name() + "=" + c.value()).findFirst().orElse("");
|
return cookies.stream().map(c -> c.name() + "=" + c.value()).findFirst().orElse("");
|
||||||
|
|
|
@ -1,8 +1,14 @@
|
||||||
package ctbrec.sites.manyvids;
|
package ctbrec.sites.manyvids;
|
||||||
|
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import ctbrec.Config;
|
||||||
import ctbrec.io.HttpClient;
|
import ctbrec.io.HttpClient;
|
||||||
|
import ctbrec.io.HttpException;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class MVLiveHttpClient extends HttpClient {
|
public class MVLiveHttpClient extends HttpClient {
|
||||||
|
|
||||||
|
@ -14,4 +20,26 @@ public class MVLiveHttpClient extends HttpClient {
|
||||||
public boolean login() throws IOException {
|
public boolean login() throws IOException {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MVLiveHttpClient newSession() {
|
||||||
|
MVLiveHttpClient newClient = new MVLiveHttpClient();
|
||||||
|
newClient.client = newClient.client.newBuilder()
|
||||||
|
.cookieJar(createCookieJar())
|
||||||
|
.build();
|
||||||
|
newClient.reconfigure();
|
||||||
|
newClient.cookieJar.clear();
|
||||||
|
return newClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fetchAuthenticationCookies() throws IOException {
|
||||||
|
Request req = new Request.Builder()
|
||||||
|
.url("https://www.manyvids.com/tak-live-redirect.php")
|
||||||
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.build();
|
||||||
|
try (Response response = execute(req)) {
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,15 @@ public class MVLiveMergedHlsDownload extends MergedFfmpegHlsDownload {
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
scheduler.scheduleAtFixedRate(() -> updateCloudFlareCookies(), 2, 2, TimeUnit.MINUTES);
|
scheduler.scheduleAtFixedRate(() -> updateCloudFlareCookies(), 2, 2, TimeUnit.MINUTES);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
((MVLiveModel)getModel()).getRoomLocation();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
updateCloudFlareCookies();
|
||||||
super.start();
|
super.start();
|
||||||
} finally {
|
} finally {
|
||||||
scheduler.shutdown();
|
scheduler.shutdown();
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
|
|
||||||
private static final transient Logger LOG = LoggerFactory.getLogger(MVLiveModel.class);
|
private static final transient Logger LOG = LoggerFactory.getLogger(MVLiveModel.class);
|
||||||
|
|
||||||
|
private MVLiveHttpClient httpClient;
|
||||||
private MVLiveClient client;
|
private MVLiveClient client;
|
||||||
private String roomNumber;
|
private String roomNumber;
|
||||||
|
|
||||||
|
@ -87,7 +88,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
.url(url)
|
.url(url)
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = getSite().getHttpClient().execute(req)) {
|
try (Response response = getHttpClient().execute(req)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String body = response.body().string();
|
String body = response.body().string();
|
||||||
LOG.debug(body);
|
LOG.debug(body);
|
||||||
|
@ -109,7 +110,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
.url(url)
|
.url(url)
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = site.getHttpClient().execute(req)) {
|
try (Response response = getHttpClient().execute(req)) {
|
||||||
if (!response.isSuccessful()) {
|
if (!response.isSuccessful()) {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
|
@ -128,7 +129,21 @@ public class MVLiveModel extends AbstractModel {
|
||||||
return roomNumber;
|
return roomNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject getRoomLocation() throws IOException {
|
private void fetchGeneralCookies() throws IOException {
|
||||||
|
Request req = new Request.Builder()
|
||||||
|
.url(getSite().getBaseUrl())
|
||||||
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.build();
|
||||||
|
try (Response response = getHttpClient().execute(req)) {
|
||||||
|
if (!response.isSuccessful()) {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject getRoomLocation() throws IOException {
|
||||||
|
fetchGeneralCookies();
|
||||||
|
httpClient.fetchAuthenticationCookies();
|
||||||
String url = MVLive.WS_ORIGIN + "/api/roomlocation/" + getName() + "?private=false";
|
String url = MVLive.WS_ORIGIN + "/api/roomlocation/" + getName() + "?private=false";
|
||||||
Request req = new Request.Builder()
|
Request req = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
|
@ -137,7 +152,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.header(REFERER, MVLive.WS_ORIGIN + "/stream/" + getName())
|
.header(REFERER, MVLive.WS_ORIGIN + "/stream/" + getName())
|
||||||
.build();
|
.build();
|
||||||
try (Response response = site.getHttpClient().execute(req)) {
|
try (Response response = getHttpClient().execute(req)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
JSONObject json = new JSONObject(response.body().string());
|
||||||
return json;
|
return json;
|
||||||
|
@ -149,9 +164,7 @@ public class MVLiveModel extends AbstractModel {
|
||||||
|
|
||||||
private synchronized MVLiveClient getClient() {
|
private synchronized MVLiveClient getClient() {
|
||||||
if (client == null) {
|
if (client == null) {
|
||||||
MVLive site = (MVLive) getSite();
|
client = new MVLiveClient(getHttpClient());
|
||||||
MVLiveHttpClient httpClient = (MVLiveHttpClient) site.getHttpClient();
|
|
||||||
client = new MVLiveClient(httpClient);
|
|
||||||
}
|
}
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
@ -183,9 +196,17 @@ public class MVLiveModel extends AbstractModel {
|
||||||
@Override
|
@Override
|
||||||
public Download createDownload() {
|
public Download createDownload() {
|
||||||
if (Config.isServerMode() && !Config.getInstance().getSettings().recordSingleFile) {
|
if (Config.isServerMode() && !Config.getInstance().getSettings().recordSingleFile) {
|
||||||
return new HlsDownload(getSite().getHttpClient());
|
return new HlsDownload(getHttpClient());
|
||||||
} else {
|
} else {
|
||||||
return new MVLiveMergedHlsDownload(getSite().getHttpClient());
|
return new MVLiveMergedHlsDownload(getHttpClient());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized MVLiveHttpClient getHttpClient() {
|
||||||
|
if (httpClient == null) {
|
||||||
|
MVLiveHttpClient siteHttpClient = (MVLiveHttpClient) getSite().getHttpClient();
|
||||||
|
httpClient = siteHttpClient.newSession();
|
||||||
|
}
|
||||||
|
return httpClient;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue