|
|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|