Clean code
This commit is contained in:
parent
d0279ef130
commit
63485070a2
|
|
@ -61,7 +61,7 @@ public class Config {
|
|||
}
|
||||
|
||||
public String getPlayUrl(String port, String playing) {
|
||||
return "http://" + getUri().getHost() + ":" + port + "/" + playing;
|
||||
return "http://" + getUri().getHost() + ":" + port + "/" + playing.replace(":/", "");
|
||||
}
|
||||
|
||||
public void loadUser() {
|
||||
|
|
@ -97,7 +97,7 @@ public class Config {
|
|||
public String getM3U8(String id, String token, String port) {
|
||||
String base = "http://" + getUri().getHost() + ":" + port + "/";
|
||||
String m3u8 = OkHttp.string(base + id + ".m3u8?token=" + token);
|
||||
if (m3u8.contains("\"Reason\"")) return "";
|
||||
if (m3u8.isEmpty() || m3u8.contains("\"Reason\"")) return "";
|
||||
String[] lines = m3u8.split("\\r?\\n");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String line : lines) {
|
||||
|
|
|
|||
|
|
@ -51,29 +51,38 @@ public class MQiTV extends Spider {
|
|||
public static Object[] proxy(Map<String, String> params) {
|
||||
String ip = params.get("ip");
|
||||
String port = params.get("port");
|
||||
String playing = params.get("playing");
|
||||
if (port == null) port = "5003";
|
||||
Config config = getConfig(ip);
|
||||
String token = config.getUser().getToken();
|
||||
if (token.isEmpty()) {
|
||||
Map<String, String> header = new HashMap<>();
|
||||
String playing = params.get("playing");
|
||||
header.put("Location", config.getPlayUrl(port, playing));
|
||||
Object[] result = new Object[4];
|
||||
result[0] = 302;
|
||||
result[1] = "text/plain";
|
||||
result[2] = new ByteArrayInputStream("302 Found".getBytes());
|
||||
result[3] = header;
|
||||
return result;
|
||||
return get302(config.getPlayUrl(port, playing));
|
||||
} else {
|
||||
String id = params.get("id");
|
||||
String auth = config.getAuth(id, token);
|
||||
if (!"OK".equals(auth)) config.clear();
|
||||
if (!"OK".equals(auth)) return proxy(params);
|
||||
Object[] result = new Object[3];
|
||||
result[0] = 200;
|
||||
result[1] = "application/vnd.apple.mpegurl";
|
||||
result[2] = new ByteArrayInputStream(config.getM3U8(id, token, port).getBytes());
|
||||
return result;
|
||||
String m3u8 = config.getM3U8(id, token, port);
|
||||
return m3u8.isEmpty() ? get302(config.getPlayUrl(port, playing)) : get200(m3u8);
|
||||
}
|
||||
}
|
||||
|
||||
private static Object[] get302(String location) {
|
||||
Map<String, String> header = new HashMap<>();
|
||||
header.put("Location", location);
|
||||
Object[] result = new Object[4];
|
||||
result[0] = 302;
|
||||
result[1] = "text/plain";
|
||||
result[2] = new ByteArrayInputStream("302 Found".getBytes());
|
||||
result[3] = header;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static Object[] get200(String m3u8) {
|
||||
Object[] result = new Object[3];
|
||||
result[0] = 200;
|
||||
result[1] = "application/vnd.apple.mpegurl";
|
||||
result[2] = new ByteArrayInputStream(m3u8.getBytes());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
ff11d5120db402fd29fb05331915079d
|
||||
bb676e5879183620dcc84bce471629cb
|
||||
|
|
|
|||
Loading…
Reference in New Issue