| 18 | import java.util.Locale; |
| 19 | |
| 20 | public class Jable extends Spider { |
| 21 | |
| 22 | private static final String siteUrl = "https://jable.tv"; |
| 23 | private static final String cateUrl = siteUrl + "/categories/"; |
| 24 | private static final String detailUrl = siteUrl + "/videos/"; |
| 25 | private static final String searchUrl = siteUrl + "/search/"; |
| 26 | |
| 27 | private HashMap<String, String> getHeaders() { |
| 28 | HashMap<String, String> headers = new HashMap<>(); |
| 29 | headers.put("User-Agent", Util.CHROME); |
| 30 | headers.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"); |
| 31 | headers.put("Accept-Language", "zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7"); |
| 32 | headers.put("Referer", siteUrl + "/"); |
| 33 | return headers; |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public String homeContent(boolean filter) { |
| 38 | Document doc = Jsoup.parse(OkHttp.string(siteUrl, getHeaders())); |
| 39 | List<Class> classes = parseClasses(doc); |
| 40 | List<Vod> list = parseVods(doc); |
| 41 | for (Class item : parseClasses(Jsoup.parse(OkHttp.string(cateUrl, getHeaders())))) { |
| 42 | if (!classes.contains(item)) classes.add(item); |
| 43 | } |
| 44 | if (list.isEmpty() && !classes.isEmpty()) { |
| 45 | list = parseVods(Jsoup.parse(OkHttp.string(getCategoryUrl(classes.get(0).getTypeId(), "1"), getHeaders()))); |
| 46 | } |
| 47 | return Result.string(classes, list); |
| 48 | } |
| 49 | |
| 50 | List<Class> parseClasses(Document doc) { |
| 51 | List<Class> classes = new ArrayList<>(); |
| 52 | for (Element element : doc.select("div.img-box > a, div.horizontal-img-box > a")) { |
| 53 | String typeId = getLastPathSegment(element.attr("href")); |
| 54 | String typeName = element.select("div.absolute-center > h4").text(); |
| 55 | if (typeName.isEmpty()) typeName = element.select("div.detail > h6.title").text(); |
| 56 | if (typeId.isEmpty() || typeName.isEmpty()) continue; |
| 57 | classes.add(new Class(typeId, typeName)); |
| 58 | } |
| 59 | return classes; |
| 60 | } |
| 61 | |
| 62 | List<Vod> parseVods(Document doc) { |
| 63 | List<Vod> list = new ArrayList<>(); |
| 64 | for (Element element : doc.select("div.video-img-box")) { |
| 65 | String pic = element.select("img").attr("data-src"); |
| 66 | if (pic.isEmpty()) pic = element.select("img").attr("src"); |
| 67 | String url = element.select("a").attr("href"); |
| 68 | String name = element.select("div.detail > h6").text(); |
| 69 | String id = getLastPathSegment(url); |
| 70 | if (pic.endsWith(".gif") || name.isEmpty() || id.isEmpty()) continue; |
| 71 | list.add(new Vod(id, name, pic)); |
| 72 | } |
| 73 | return list; |
| 74 | } |
| 75 | |
| 76 | String getLastPathSegment(String url) { |
| 77 | int query = url.indexOf('?'); |
nothing calls this directly
no outgoing calls
no test coverage detected