| 22 | import java.util.List; |
| 23 | |
| 24 | public class Samba extends Spider { |
| 25 | |
| 26 | private List<Drive> drives; |
| 27 | private String extend; |
| 28 | |
| 29 | private void fetchRule() { |
| 30 | if (drives != null && !drives.isEmpty()) return; |
| 31 | if (extend.startsWith("http")) extend = OkHttp.string(extend); |
| 32 | drives = Drive.arrayFrom(extend); |
| 33 | } |
| 34 | |
| 35 | private Drive getDrive(String name) { |
| 36 | return drives.get(drives.indexOf(new Drive(name))); |
| 37 | } |
| 38 | |
| 39 | private boolean isFolder(FileIdBothDirectoryInformation item) { |
| 40 | return EnumWithValue.EnumUtils.isSet(item.getFileAttributes(), FileAttributes.FILE_ATTRIBUTE_DIRECTORY); |
| 41 | } |
| 42 | |
| 43 | private boolean isFile(FileIdBothDirectoryInformation item) { |
| 44 | return !EnumWithValue.EnumUtils.isSet(item.getFileAttributes(), FileAttributes.FILE_ATTRIBUTE_DIRECTORY); |
| 45 | } |
| 46 | |
| 47 | @Override |
| 48 | public void init(Context context, String extend) { |
| 49 | this.extend = extend; |
| 50 | fetchRule(); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public String homeContent(boolean filter) { |
| 55 | List<Class> classes = new ArrayList<>(); |
| 56 | for (Drive drive : drives) classes.add(drive.toType()); |
| 57 | return Result.string(classes); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public String categoryContent(String tid, String pg, boolean filter, HashMap<String, String> hashMap) { |
| 62 | String key = tid.contains("/") ? tid.substring(0, tid.indexOf("/")) : tid; |
| 63 | String path = tid.contains("/") ? tid.substring(tid.indexOf("/") + 1) : ""; |
| 64 | Drive drive = getDrive(key); |
| 65 | List<Vod> list = new ArrayList<>(); |
| 66 | for (FileIdBothDirectoryInformation item : getList(drive, path)) { |
| 67 | String vodId = getPath(key, path, item.getFileName()); |
| 68 | if (isFolder(item)) list.add(new Vod(vodId, item.getFileName(), Image.FOLDER, "", true)); |
| 69 | if (isFile(item)) list.add(new Vod(vodId, item.getFileName(), Image.VIDEO, "", false)); |
| 70 | } |
| 71 | return Result.get().vod(list).page().string(); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public String detailContent(List<String> ids) { |
| 76 | String tid = ids.get(0); |
| 77 | String key = tid.contains("/") ? tid.substring(0, tid.indexOf("/")) : tid; |
| 78 | String path = tid.contains("/") ? tid.substring(tid.indexOf("/") + 1) : ""; |
| 79 | String parent = path.contains("/") ? path.substring(0, path.lastIndexOf("/")) : ""; |
| 80 | String name = parent.contains("/") ? parent.substring(parent.lastIndexOf("/") + 1) : key; |
| 81 | Drive drive = getDrive(key); |
nothing calls this directly
no outgoing calls
no test coverage detected