Remove the uid field from ShowupModel
This commit is contained in:
parent
63b2985e37
commit
9eea66d94f
|
@ -50,9 +50,9 @@ public class ShowupFollowedUpdateService extends PaginatedScheduledService {
|
|||
String body = response.body().string();
|
||||
JSONObject json = new JSONObject(body);
|
||||
if (json.optString("status").equalsIgnoreCase("success")) {
|
||||
Map<Long, String> onlineModels = parseOnlineModels(json);
|
||||
Map<String, String> onlineModels = parseOnlineModels(json);
|
||||
return parseFavorites(json).stream()
|
||||
.filter(m -> onlineModels.containsKey(m.getUid()) == showOnline)
|
||||
.filter(m -> onlineModels.containsKey(m.getName()) == showOnline)
|
||||
.collect(Collectors.toList());
|
||||
} else {
|
||||
throw new RuntimeException("Request was not successful: " + body);
|
||||
|
@ -70,7 +70,6 @@ public class ShowupFollowedUpdateService extends PaginatedScheduledService {
|
|||
JSONObject m = list.getJSONObject(i);
|
||||
ShowupModel model = new ShowupModel();
|
||||
model.setSite(site);
|
||||
model.setUid(m.optLong("fav_uid"));
|
||||
model.setName(m.optString("username"));
|
||||
model.setUrl(site.getBaseUrl() + '/' + model.getName());
|
||||
|
||||
|
@ -78,13 +77,14 @@ public class ShowupFollowedUpdateService extends PaginatedScheduledService {
|
|||
return favorites;
|
||||
}
|
||||
|
||||
private Map<Long, String> parseOnlineModels(JSONObject json) {
|
||||
var onlineModels = new HashMap<Long, String>();
|
||||
private Map<String, String> parseOnlineModels(JSONObject json) {
|
||||
var onlineModels = new HashMap<String, String>();
|
||||
JSONArray online = json.getJSONArray("online");
|
||||
System.out.println(online.toString(2));
|
||||
for (int i = 0; i < online.length(); i++) {
|
||||
JSONObject m = online.getJSONObject(i);
|
||||
String preview = site.getBaseUrl() + "/files/" + m.optString("big_img") + ".jpg";
|
||||
onlineModels.put(m.optLong("uid"), preview);
|
||||
//onlineModels.put(m.optLong("uid"), preview);
|
||||
}
|
||||
return onlineModels;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@ import static ctbrec.Model.State.*;
|
|||
import static ctbrec.io.HttpConstants.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
|
@ -16,11 +18,8 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.ModelNotFoundException;
|
||||
import ctbrec.UnknownModel;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -54,16 +53,21 @@ public class Showup extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public Model createModel(String name) {
|
||||
try {
|
||||
for (Model m : getModelList()) {
|
||||
if (Objects.equal(m.getName(), name)) {
|
||||
return m;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new ModelNotFoundException(name, e);
|
||||
}
|
||||
throw new ModelNotFoundException(name);
|
||||
// try {
|
||||
// for (Model m : getModelList()) {
|
||||
// if (Objects.equal(m.getName(), name)) {
|
||||
// return m;
|
||||
// }
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// throw new ModelNotFoundException(name, e);
|
||||
// }
|
||||
// throw new ModelNotFoundException(name);
|
||||
ShowupModel model = new ShowupModel();
|
||||
model.setSite(this);
|
||||
model.setName(name);
|
||||
model.setUrl(BASE_URL + '/' + URLEncoder.encode(name, StandardCharsets.UTF_8));
|
||||
return model;
|
||||
}
|
||||
|
||||
public List<Model> getModelList() throws IOException {
|
||||
|
@ -85,8 +89,6 @@ public class Showup extends AbstractSite {
|
|||
for (int i = 0; i < list.length(); i++) {
|
||||
JSONObject entry = list.getJSONObject(i);
|
||||
ShowupModel model = new ShowupModel();
|
||||
model.setUid(entry.getLong("uid"));
|
||||
//model.setPreview(getBaseUrl() + "/files/" + entry.optString("big_img") + ".jpg");
|
||||
model.setPreview(getBaseUrl() + "/files/" + entry.optString("small_img") + ".jpg");
|
||||
model.setDescription(entry.optString("description"));
|
||||
model.setName(entry.optString("username"));
|
||||
|
|
|
@ -11,10 +11,9 @@ import java.util.concurrent.ExecutionException;
|
|||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.iheartradio.m3u8.ParseException;
|
||||
import com.iheartradio.m3u8.PlaylistException;
|
||||
import com.squareup.moshi.JsonReader;
|
||||
import com.squareup.moshi.JsonWriter;
|
||||
|
||||
import ctbrec.AbstractModel;
|
||||
import ctbrec.Config;
|
||||
|
@ -24,7 +23,6 @@ import ctbrec.recorder.download.StreamSource;
|
|||
|
||||
public class ShowupModel extends AbstractModel {
|
||||
|
||||
private long uid;
|
||||
private String streamId;
|
||||
private String streamTranscoderAddr;
|
||||
private int[] resolution = new int[2];
|
||||
|
@ -36,7 +34,7 @@ public class ShowupModel extends AbstractModel {
|
|||
List<Model> modelList = getShowupSite().getModelList();
|
||||
for (Model model : modelList) {
|
||||
ShowupModel m = (ShowupModel) model;
|
||||
if (m.getUid() == uid) {
|
||||
if (Objects.equal(m.getName(), getName())) {
|
||||
setOnlineState(m.getOnlineState(false));
|
||||
setStreamId(m.getStreamId());
|
||||
setStreamTranscoderAddr(m.getStreamTranscoderAddr());
|
||||
|
@ -63,7 +61,7 @@ public class ShowupModel extends AbstractModel {
|
|||
List<Model> modelList = getShowupSite().getModelList();
|
||||
for (Model model : modelList) {
|
||||
ShowupModel m = (ShowupModel) model;
|
||||
if (m.getUid() == uid) {
|
||||
if (Objects.equal(m.getName(), getName())) {
|
||||
streamId = m.getStreamId();
|
||||
streamTranscoderAddr = m.getStreamTranscoderAddr();
|
||||
}
|
||||
|
@ -100,25 +98,6 @@ public class ShowupModel extends AbstractModel {
|
|||
return false;
|
||||
}
|
||||
|
||||
public long getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(long uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSiteSpecificData(JsonReader reader) throws IOException {
|
||||
reader.nextName();
|
||||
uid = reader.nextLong();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSiteSpecificData(JsonWriter writer) throws IOException {
|
||||
writer.name("uid").value(uid);
|
||||
}
|
||||
|
||||
private Showup getShowupSite() {
|
||||
return (Showup) getSite();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue