Fix samba

This commit is contained in:
FongMi 2025-04-09 12:18:27 +08:00
parent 843cde8576
commit fc50f6e5d0
4 changed files with 27 additions and 11 deletions

View File

@ -27,6 +27,7 @@ public class Drive {
private SMBClient smbClient;
private DiskShare diskShare;
private Session session;
private String subPath;
public static List<Drive> arrayFrom(String str) {
Type listType = new TypeToken<List<Drive>>() {}.getType();
@ -37,7 +38,7 @@ public class Drive {
this.name = name;
}
public String getName() {
private String getName() {
return TextUtils.isEmpty(name) ? "" : name;
}
@ -45,6 +46,10 @@ public class Drive {
return TextUtils.isEmpty(server) ? "" : server;
}
public String getSubPath() {
return TextUtils.isEmpty(subPath) ? "" : subPath;
}
public DiskShare getShare() {
if (diskShare == null) init();
return diskShare;
@ -54,14 +59,15 @@ public class Drive {
return new Class(getName(), getName(), "1");
}
public void init() {
private void init() {
try {
smbClient = new SMBClient();
Uri uri = Uri.parse(getServer());
String share = uri.getPath().replaceFirst("^/", "").split("/")[0];
String[] parts = uri.getPath().substring(1).split("/", 2);
connection = smbClient.connect(uri.getHost(), uri.getPort() != -1 ? uri.getPort() : SMBClient.DEFAULT_PORT);
session = connection.authenticate(getAuthentication(uri));
diskShare = (DiskShare) session.connectShare(share);
diskShare = (DiskShare) session.connectShare(parts[0]);
subPath = parts.length > 1 ? parts[1] : "";
} catch (Exception e) {
e.printStackTrace();
}
@ -84,6 +90,11 @@ public class Drive {
if (smbClient != null) smbClient.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
connection = null;
diskShare = null;
smbClient = null;
session = null;
}
}

View File

@ -16,7 +16,6 @@ import com.hierynomus.msfscc.fileinformation.FileIdBothDirectoryInformation;
import com.hierynomus.protocol.commons.EnumWithValue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@ -65,7 +64,7 @@ public class Samba extends Spider {
Drive drive = getDrive(key);
List<Vod> list = new ArrayList<>();
for (FileIdBothDirectoryInformation item : getList(drive, path)) {
String vodId = TextUtils.join("/", path.isEmpty() ? Arrays.asList(key, item.getFileName()) : Arrays.asList(key, path, item.getFileName()));
String vodId = getPath(key, path, item.getFileName());
if (isFolder(item)) list.add(new Vod(vodId, item.getFileName(), Image.FOLDER, "", true));
if (isFile(item)) list.add(new Vod(vodId, item.getFileName(), Image.VIDEO, "", false));
}
@ -77,13 +76,13 @@ public class Samba extends Spider {
String tid = ids.get(0);
String key = tid.contains("/") ? tid.substring(0, tid.indexOf("/")) : tid;
String path = tid.contains("/") ? tid.substring(tid.indexOf("/") + 1) : "";
String parent = path.substring(0, path.lastIndexOf("/"));
String name = parent.substring(parent.lastIndexOf("/") + 1);
String parent = path.contains("/") ? path.substring(0, path.lastIndexOf("/")) : "";
String name = parent.contains("/") ? parent.substring(parent.lastIndexOf("/") + 1) : key;
Drive drive = getDrive(key);
List<String> playUrls = new ArrayList<>();
for (FileIdBothDirectoryInformation item : getList(drive, parent)) {
if (isFile(item)) {
playUrls.add(item.getFileName() + "$" + drive.getServer() + "/" + parent + "/" + item.getFileName());
playUrls.add(item.getFileName() + "$" + getPath(drive.getServer(), parent, item.getFileName()));
}
}
Vod vod = new Vod();
@ -99,8 +98,14 @@ public class Samba extends Spider {
return Result.get().url(id).string();
}
private String getPath(String... texts) {
List<String> items = new ArrayList<>();
for (String text : texts) if (!TextUtils.isEmpty(text)) items.add(text);
return TextUtils.join("/", items);
}
private List<FileIdBothDirectoryInformation> getList(Drive drive, String path) {
List<FileIdBothDirectoryInformation> items = drive.getShare().list(path);
List<FileIdBothDirectoryInformation> items = drive.getShare().list(getPath(drive.getSubPath(), path));
Iterator<FileIdBothDirectoryInformation> iterator = items.iterator();
while (iterator.hasNext()) {
FileIdBothDirectoryInformation item = iterator.next();

Binary file not shown.

View File

@ -1 +1 @@
65a8a861fbc445ee153d9e0064aabedc
0810fd9a85bfe678d850a92a9f1d2b6f