forked from j62/ctbrec
User another request to determine the model ID
This commit is contained in:
parent
799ef77f38
commit
9cf4bacae1
|
@ -6,7 +6,6 @@ import com.squareup.moshi.JsonReader;
|
||||||
import com.squareup.moshi.JsonWriter;
|
import com.squareup.moshi.JsonWriter;
|
||||||
import ctbrec.AbstractModel;
|
import ctbrec.AbstractModel;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
|
||||||
import ctbrec.NotImplementedExcetion;
|
import ctbrec.NotImplementedExcetion;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
import ctbrec.recorder.download.StreamSource;
|
import ctbrec.recorder.download.StreamSource;
|
||||||
|
@ -19,6 +18,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
|
||||||
import static ctbrec.Model.State.*;
|
import static ctbrec.Model.State.*;
|
||||||
import static ctbrec.io.HttpConstants.*;
|
import static ctbrec.io.HttpConstants.*;
|
||||||
import static ctbrec.sites.streamate.StreamateHttpClient.JSON;
|
import static ctbrec.sites.streamate.StreamateHttpClient.JSON;
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
public class StreamateModel extends AbstractModel {
|
public class StreamateModel extends AbstractModel {
|
||||||
|
|
||||||
|
@ -70,11 +71,6 @@ public class StreamateModel extends AbstractModel {
|
||||||
return onlineState;
|
return onlineState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setOnlineState(State onlineState) {
|
|
||||||
this.onlineState = onlineState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||||
String url = "https://sea1c-ls.naiadsystems.com/sea1c-edge-ls/80/live/s:" + getName() + ".json";
|
String url = "https://sea1c-ls.naiadsystems.com/sea1c-edge-ls/80/live/s:" + getName() + ".json";
|
||||||
|
@ -129,10 +125,22 @@ public class StreamateModel extends AbstractModel {
|
||||||
resolution = null;
|
resolution = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadModelId() throws IOException, InterruptedException {
|
void loadModelId() throws IOException {
|
||||||
List<Model> models = getSite().search(getName());
|
String url = "https://www.streamate.com/api/performer/lookup?nicknames" + URLEncoder.encode(getName(), UTF_8);
|
||||||
if (!models.isEmpty()) {
|
Request req = new Request.Builder().url(url)
|
||||||
id = ((StreamateModel)models.get(0)).getId();
|
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
.addHeader(ACCEPT, "*/*")
|
||||||
|
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
|
.addHeader(REFERER, Streamate.BASE_URL + '/' + getName())
|
||||||
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
|
.build();
|
||||||
|
try (Response response = site.getHttpClient().execute(req)) {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
String body = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
|
id = new JSONObject(body).getJSONObject("result").getLong(getName());
|
||||||
|
} else {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,8 +236,6 @@ public class StreamateModel extends AbstractModel {
|
||||||
loadModelId();
|
loadModelId();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("Couldn't load model ID for {}. This can cause problems with saving / loading the model", getName(), e);
|
LOG.error("Couldn't load model ID for {}. This can cause problems with saving / loading the model", getName(), e);
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
writer.name("id").value(id);
|
writer.name("id").value(id);
|
||||||
|
|
Loading…
Reference in New Issue