forked from j62/ctbrec
Implement createModelFromUrl for FC2Live
This commit is contained in:
parent
df38ed3027
commit
8e2abd2f11
|
@ -1,6 +1,8 @@
|
|||
package ctbrec.sites.fc2live;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
|
@ -36,6 +38,24 @@ public class Fc2Live extends AbstractSite {
|
|||
return model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Model createModelFromUrl(String url) {
|
||||
Matcher m = Pattern.compile("http.*?fc2.*?.com/(\\d+)/?").matcher(url);
|
||||
if(m.find()) {
|
||||
Fc2Model model = (Fc2Model) createModel("");
|
||||
model.setId(m.group(1));
|
||||
try {
|
||||
model.loadModelInfo();
|
||||
model.setUrl(url);
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
return super.createModelFromUrl(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getTokenBalance() throws IOException {
|
||||
return 0d;
|
||||
|
|
|
@ -60,7 +60,7 @@ public class Fc2Model extends AbstractModel {
|
|||
return online;
|
||||
}
|
||||
|
||||
private void loadModelInfo() throws IOException {
|
||||
void loadModelInfo() throws IOException {
|
||||
String url = Fc2Live.BASE_URL + "/api/memberApi.php";
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("channel", "1")
|
||||
|
@ -90,6 +90,10 @@ public class Fc2Model extends AbstractModel {
|
|||
online = false;
|
||||
}
|
||||
version = channelData.optString("version");
|
||||
if (data.has("profile_data")) {
|
||||
JSONObject profileData = data.getJSONObject("profile_data");
|
||||
setName(profileData.getString("name").replace('/', '_'));
|
||||
}
|
||||
} else {
|
||||
resp.close();
|
||||
throw new IOException("HTTP status " + resp.code() + " " + resp.message());
|
||||
|
|
Loading…
Reference in New Issue