MCPcopy Create free account
hub / github.com/FongMi/CatVodSpider / Util

Class Util

app/src/main/java/com/github/catvod/utils/Util.java:14–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12import java.util.regex.Pattern;
13
14public class Util {
15
16 public static final Pattern THUNDER = Pattern.compile("(magnet|thunder|ed2k):.*");
17 public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36";
18 public static final List<String> MEDIA = Arrays.asList("mp4", "mkv", "mov", "wav", "wma", "wmv", "flv", "avi", "iso", "mpg", "ts", "mp3", "aac", "flac", "m4a", "ape", "ogg", "rm", "rmvb", "asf", "dts", "dsf", "dff");
19 public static final List<String> SUB = Arrays.asList("srt", "ass", "ssa", "vtt");
20
21 public static boolean isThunder(String url) {
22 return THUNDER.matcher(url).find() || isTorrent(url);
23 }
24
25 public static boolean isTorrent(String url) {
26 return !url.startsWith("magnet") && url.split(";")[0].endsWith(".torrent");
27 }
28
29 public static boolean isSub(String text) {
30 return SUB.contains(getExt(text).toLowerCase());
31 }
32
33 public static boolean isMedia(String text) {
34 return MEDIA.contains(getExt(text).toLowerCase());
35 }
36
37 public static String getExt(String name) {
38 return name.contains(".") ? name.substring(name.lastIndexOf(".") + 1).toLowerCase() : name.toLowerCase();
39 }
40
41 public static String getSize(double size) {
42 if (size <= 0) return "";
43 String[] units = new String[]{"bytes", "KB", "MB", "GB", "TB"};
44 int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
45 return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
46 }
47
48 public static String removeExt(String text) {
49 return text.contains(".") ? text.substring(0, text.lastIndexOf(".")) : text;
50 }
51
52 public static String substring(String text) {
53 return substring(text, 1);
54 }
55
56 public static String substring(String text, int num) {
57 if (text != null && text.length() > num) {
58 return text.substring(0, text.length() - num);
59 } else {
60 return text;
61 }
62 }
63
64 public static String getVar(String data, String param) {
65 for (String var : data.split("var")) if (var.contains(param)) return checkVar(var);
66 return "";
67 }
68
69 private static String checkVar(String var) {
70 if (var.contains("'")) return var.split("'")[1];
71 if (var.contains("\"")) return var.split("\"")[1];

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected