// Minimal VOD sample; example.com is illustrative.
package com.github.catvod.spider;
import com.github.catvod.crawler.Spider;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
public class Demo extends Spider {
// Returns the category list.
@Override
public String homeContent(boolean filter) throws Exception {
JSONObject item = new JSONObject().put("type_id", "movie").put("type_name", "Movies");
return new JSONObject().put("class", new JSONArray().put(item)).toString();
}
// The sample has one page; later pages return an empty list.
@Override
public String categoryContent(String tid, String pg, boolean filter,
HashMap<String, String> extend) throws Exception {
int page = Math.max(1, Integer.parseInt(pg));
JSONArray items = new JSONArray();
if (page == 1) items.put(card("demo-1", "Sample item"));
return new JSONObject().put("list", items).put("page", page)
.put("pagecount", 1).put("limit", 20).put("total", 1).toString();
}
// Episodes use stable IDs; the real URL is resolved on play.
@Override
public String detailContent(List<String> ids) throws Exception {
JSONObject item = card(ids.get(0), "Sample item").put("vod_play_from", "Demo")
.put("vod_play_url", "Episode 1$demo://episode/1");
return new JSONObject().put("list", new JSONArray().put(item)).toString();
}
// Turns the playback ID into a real URL.
@Override
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
String url = id.replace("demo://", "https://example.com/");
return new JSONObject().put("parse", 0).put("url", url).toString();
}
private JSONObject card(String id, String name) throws Exception {
return new JSONObject().put("vod_id", id).put("vod_name", name)
.put("vod_pic", "https://example.com/poster.jpg");
}
}