Support local file
This commit is contained in:
parent
ab4255336d
commit
0c3f15148d
|
|
@ -5,6 +5,7 @@ import android.text.TextUtils;
|
|||
|
||||
import com.github.catvod.bean.Class;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.utils.Image;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ public class Drive {
|
|||
}
|
||||
|
||||
public String getVodPic() {
|
||||
return TextUtils.isEmpty(vodPic) ? "https://s1.ax1x.com/2023/04/03/pp4F4bT.png" : vodPic;
|
||||
return TextUtils.isEmpty(vodPic) ? Image.FOLDER : vodPic;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ import java.util.List;
|
|||
|
||||
public class Drive {
|
||||
|
||||
@SerializedName("vodPic")
|
||||
private String vodPic;
|
||||
@SerializedName("drives")
|
||||
private List<Drive> drives;
|
||||
@SerializedName("name")
|
||||
|
|
@ -46,10 +44,6 @@ public class Drive {
|
|||
return drives == null ? new ArrayList<>() : drives;
|
||||
}
|
||||
|
||||
public String getVodPic() {
|
||||
return TextUtils.isEmpty(vodPic) ? "" : vodPic;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return TextUtils.isEmpty(name) ? "" : name;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
package com.github.catvod.spider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
|
||||
import com.github.catvod.bean.Class;
|
||||
import com.github.catvod.bean.Result;
|
||||
import com.github.catvod.bean.Sub;
|
||||
import com.github.catvod.bean.Vod;
|
||||
import com.github.catvod.crawler.Spider;
|
||||
import com.github.catvod.utils.Image;
|
||||
import com.github.catvod.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Local extends Spider {
|
||||
|
||||
private SimpleDateFormat format;
|
||||
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
format = new SimpleDateFormat("yyyyy/MM/dd HH:mm:ss", Locale.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String homeContent(boolean filter) throws Exception {
|
||||
List<Class> classes = new ArrayList<>();
|
||||
String root = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
classes.add(new Class(root, "本地文件", "1"));
|
||||
return Result.string(classes, new ArrayList<>());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> extend) throws Exception {
|
||||
List<Vod> items = new ArrayList<>();
|
||||
List<Vod> media = new ArrayList<>();
|
||||
List<Vod> folders = new ArrayList<>();
|
||||
File[] files = new File(tid).listFiles();
|
||||
if (files == null) return Result.string(items);
|
||||
Arrays.sort(files, (a, b) -> a.getName().compareTo(b.getName()));
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) folders.add(create(file));
|
||||
else if (Utils.MEDIA.contains(Utils.getExt(file.getName()))) media.add(create(file));
|
||||
}
|
||||
items.addAll(folders);
|
||||
items.addAll(media);
|
||||
return Result.string(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String detailContent(List<String> ids) {
|
||||
File file = new File(ids.get(0));
|
||||
Vod vod = new Vod();
|
||||
vod.setTypeName("FongMi");
|
||||
vod.setVodId(file.getAbsolutePath());
|
||||
vod.setVodName(file.getName());
|
||||
vod.setVodPic(Image.VIDEO);
|
||||
vod.setVodPlayFrom("播放");
|
||||
vod.setVodPlayUrl(file.getName() + "$" + file.getAbsolutePath());
|
||||
return Result.string(vod);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String playerContent(String flag, String id, List<String> vipFlags) throws Exception {
|
||||
return Result.get().url(id).subs(getSubs(id)).string();
|
||||
}
|
||||
|
||||
private Vod create(File file) {
|
||||
Vod vod = new Vod();
|
||||
vod.setVodId(file.getAbsolutePath());
|
||||
vod.setVodName(file.getName());
|
||||
vod.setVodPic(Image.getIcon(file.isDirectory()));
|
||||
vod.setVodRemarks(format.format(file.lastModified()));
|
||||
vod.setVodTag(file.isDirectory() ? "folder" : "file");
|
||||
return vod;
|
||||
}
|
||||
|
||||
private List<Sub> getSubs(String path) {
|
||||
File file = new File(path);
|
||||
if (file.getParentFile() == null) return Collections.emptyList();
|
||||
List<Sub> subs = new ArrayList<>();
|
||||
for (File f : Objects.requireNonNull(file.getParentFile().listFiles())) {
|
||||
String ext = Utils.getExt(f.getName());
|
||||
if (Utils.isSub(ext)) subs.add(Sub.create().name(Utils.removeExt(f.getName())).ext(ext).url("file://" + f.getAbsolutePath()));
|
||||
}
|
||||
return subs;
|
||||
}
|
||||
}
|
||||
|
|
@ -53,9 +53,9 @@ public class Push extends Ali {
|
|||
File file = new File(url.replace("file://", ""));
|
||||
if (file.getParentFile() == null) return Collections.emptyList();
|
||||
List<Sub> subs = new ArrayList<>();
|
||||
for (File temp : Objects.requireNonNull(file.getParentFile().listFiles())) {
|
||||
String ext = Utils.getExt(temp.getName());
|
||||
if (Utils.isSub(ext)) subs.add(Sub.create().name(Utils.removeExt(temp.getName())).ext(ext).url("file://" + temp.getAbsolutePath()));
|
||||
for (File f : Objects.requireNonNull(file.getParentFile().listFiles())) {
|
||||
String ext = Utils.getExt(f.getName());
|
||||
if (Utils.isSub(ext)) subs.add(Sub.create().name(Utils.removeExt(f.getName())).ext(ext).url("file://" + f.getAbsolutePath()));
|
||||
}
|
||||
return subs;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.github.catvod.bean.webdav.Drive;
|
|||
import com.github.catvod.bean.webdav.Sorter;
|
||||
import com.github.catvod.crawler.Spider;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.github.catvod.utils.Image;
|
||||
import com.github.catvod.utils.Utils;
|
||||
import com.thegrizzlylabs.sardineandroid.DavResource;
|
||||
|
||||
|
|
@ -27,10 +28,8 @@ import java.util.Map;
|
|||
public class WebDAV extends Spider {
|
||||
|
||||
private static List<Drive> drives;
|
||||
private List<String> playExt;
|
||||
private List<String> allExt;
|
||||
private String vodPic;
|
||||
private String ext;
|
||||
private String extend;
|
||||
|
||||
private List<Filter> getFilter() {
|
||||
List<Filter> items = new ArrayList<>();
|
||||
|
|
@ -41,10 +40,9 @@ public class WebDAV extends Spider {
|
|||
|
||||
private void fetchRule() {
|
||||
if (drives != null && !drives.isEmpty()) return;
|
||||
if (ext.startsWith("http")) ext = OkHttp.string(ext);
|
||||
Drive drive = Drive.objectFrom(ext);
|
||||
if (extend.startsWith("http")) extend = OkHttp.string(extend);
|
||||
Drive drive = Drive.objectFrom(extend);
|
||||
drives = drive.getDrives();
|
||||
vodPic = drive.getVodPic();
|
||||
}
|
||||
|
||||
private String getExt(DavResource item) {
|
||||
|
|
@ -61,10 +59,9 @@ public class WebDAV extends Spider {
|
|||
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
playExt = Arrays.asList("mp4", "mkv", "wmv", "flv", "avi", "mp3", "aac", "flac", "m4a");
|
||||
allExt = new ArrayList<>(Arrays.asList("ass", "ssa", "srt"));
|
||||
allExt.addAll(playExt);
|
||||
ext = extend;
|
||||
this.allExt = new ArrayList<>(Arrays.asList("ass", "ssa", "srt"));
|
||||
this.allExt.addAll(Utils.MEDIA);
|
||||
this.extend = extend;
|
||||
fetchRule();
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +85,7 @@ public class WebDAV extends Spider {
|
|||
List<DavResource> files = new ArrayList<>();
|
||||
List<Vod> list = new ArrayList<>();
|
||||
Drive drive = getDrive(key);
|
||||
for (DavResource item : getList(drive, path, playExt)) {
|
||||
for (DavResource item : getList(drive, path, Utils.MEDIA)) {
|
||||
if (item.isDirectory()) folders.add(item);
|
||||
else files.add(item);
|
||||
}
|
||||
|
|
@ -96,8 +93,8 @@ public class WebDAV extends Spider {
|
|||
Sorter.sort(type, order, folders);
|
||||
Sorter.sort(type, order, files);
|
||||
}
|
||||
for (DavResource item : folders) list.add(drive.vod(item, vodPic));
|
||||
for (DavResource item : files) list.add(drive.vod(item, vodPic));
|
||||
for (DavResource item : folders) list.add(drive.vod(item, Image.FOLDER));
|
||||
for (DavResource item : files) list.add(drive.vod(item, Image.VIDEO));
|
||||
return Result.get().vod(list).page().string();
|
||||
}
|
||||
|
||||
|
|
@ -114,15 +111,15 @@ public class WebDAV extends Spider {
|
|||
Sorter.sort("name", "asc", parents);
|
||||
List<String> playUrls = new ArrayList<>();
|
||||
for (DavResource item : parents) {
|
||||
if (playExt.contains(getExt(item))) {
|
||||
if (Utils.MEDIA.contains(getExt(item))) {
|
||||
playUrls.add(item.getName() + "$" + drive.getName() + item.getPath() + findSubs(drive, item, subs));
|
||||
}
|
||||
}
|
||||
Vod vod = new Vod();
|
||||
vod.setVodId(name);
|
||||
vod.setVodName(name);
|
||||
vod.setVodPic(vodPic);
|
||||
vod.setVodPlayFrom(key);
|
||||
vod.setVodPic(Image.VIDEO);
|
||||
vod.setVodPlayUrl(TextUtils.join("#", playUrls));
|
||||
return Result.string(vod);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
package com.github.catvod.utils;
|
||||
|
||||
public class Image {
|
||||
|
||||
public static final String FOLDER = "https://s1.ax1x.com/2023/05/04/p9tgI81.png";
|
||||
public static final String VIDEO = "https://s1.ax1x.com/2023/05/04/p9tgogx.png";
|
||||
|
||||
public static String getIcon(boolean folder) {
|
||||
return folder ? FOLDER : VIDEO;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
package com.github.catvod.utils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Sniffer {
|
||||
|
||||
public static final Pattern RULE = Pattern.compile(
|
||||
"http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|" +
|
||||
"http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|" +
|
||||
"http((?!http).)*?video/tos*"
|
||||
);
|
||||
}
|
||||
|
|
@ -18,10 +18,17 @@ import java.security.MessageDigest;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36";
|
||||
public static final List<String> MEDIA = Arrays.asList("mp4", "mkv", "wmv", "flv", "avi", "mp3", "aac", "flac", "m4a");
|
||||
public static final Pattern RULE = Pattern.compile(
|
||||
"http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|" +
|
||||
"http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|" +
|
||||
"http((?!http).)*?video/tos*"
|
||||
);
|
||||
|
||||
public static boolean isVip(String url) {
|
||||
List<String> hosts = Arrays.asList("iqiyi.com", "v.qq.com", "youku.com", "le.com", "tudou.com", "mgtv.com", "sohu.com", "acfun.cn", "bilibili.com", "baofeng.com", "pptv.com");
|
||||
|
|
@ -31,7 +38,7 @@ public class Utils {
|
|||
|
||||
public static boolean isVideoFormat(String url) {
|
||||
if (url.contains("url=http") || url.contains(".js") || url.contains(".css") || url.contains(".html")) return false;
|
||||
return Sniffer.RULE.matcher(url).find();
|
||||
return RULE.matcher(url).find();
|
||||
}
|
||||
|
||||
public static boolean isMobile() {
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
0b5053aea39f2bdfa8196b8685daa086
|
||||
85bd2b2f0ac608417b010483b61fcd16
|
||||
|
|
|
|||
Loading…
Reference in New Issue