Clean
This commit is contained in:
parent
848d47b3e1
commit
1068162666
|
|
@ -10,7 +10,6 @@ import com.github.catvod.bean.jianpian.Detail;
|
|||
import com.github.catvod.bean.jianpian.Resp;
|
||||
import com.github.catvod.bean.jianpian.Search;
|
||||
import com.github.catvod.crawler.Spider;
|
||||
import com.github.catvod.crawler.SpiderDebug;
|
||||
import com.github.catvod.net.OkHttp;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ import android.content.res.XmlResourceParser;
|
|||
import android.database.Cursor;
|
||||
import android.database.MatrixCursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.text.TextUtils;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -57,16 +58,16 @@ public class FileProvider extends ContentProvider {
|
|||
synchronized (sCache) {
|
||||
sCache.remove(authority);
|
||||
}
|
||||
mStrategy = getPathStrategy(context, authority, 0);
|
||||
mStrategy = getPathStrategy(context, authority);
|
||||
}
|
||||
|
||||
public static Uri getUriForFile(Context context, String authority, File file) {
|
||||
final PathStrategy strategy = getPathStrategy(context, authority, 0);
|
||||
final PathStrategy strategy = getPathStrategy(context, authority);
|
||||
return strategy.getUriForFile(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
final File file = mStrategy.getFileForUri(uri);
|
||||
String displayName = uri.getQueryParameter(DISPLAYNAME_FIELD);
|
||||
if (projection == null) {
|
||||
|
|
@ -92,7 +93,7 @@ public class FileProvider extends ContentProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
public String getType(@NonNull Uri uri) {
|
||||
final File file = mStrategy.getFileForUri(uri);
|
||||
final int lastDot = file.getName().lastIndexOf('.');
|
||||
if (lastDot >= 0) {
|
||||
|
|
@ -106,38 +107,36 @@ public class FileProvider extends ContentProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
public Uri insert(@NonNull Uri uri, ContentValues values) {
|
||||
throw new UnsupportedOperationException("No external inserts");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
public int update(@NonNull Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
||||
throw new UnsupportedOperationException("No external updates");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
public int delete(@NonNull Uri uri, String selection, String[] selectionArgs) {
|
||||
final File file = mStrategy.getFileForUri(uri);
|
||||
return file.delete() ? 1 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
|
||||
final File file = mStrategy.getFileForUri(uri);
|
||||
final int fileMode = modeToMode(mode);
|
||||
return ParcelFileDescriptor.open(file, fileMode);
|
||||
}
|
||||
|
||||
private static PathStrategy getPathStrategy(Context context, String authority, int resourceId) {
|
||||
private static PathStrategy getPathStrategy(Context context, String authority) {
|
||||
PathStrategy strat;
|
||||
synchronized (sCache) {
|
||||
strat = sCache.get(authority);
|
||||
if (strat == null) {
|
||||
try {
|
||||
strat = parsePathStrategy(context, authority, resourceId);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalArgumentException("Failed to parse " + META_DATA_FILE_PROVIDER_PATHS + " meta-data", e);
|
||||
} catch (XmlPullParserException e) {
|
||||
strat = parsePathStrategy(context, authority);
|
||||
} catch (IOException | XmlPullParserException e) {
|
||||
throw new IllegalArgumentException("Failed to parse " + META_DATA_FILE_PROVIDER_PATHS + " meta-data", e);
|
||||
}
|
||||
sCache.put(authority, strat);
|
||||
|
|
@ -146,14 +145,10 @@ public class FileProvider extends ContentProvider {
|
|||
return strat;
|
||||
}
|
||||
|
||||
static XmlResourceParser getFileProviderPathsMetaData(Context context, String authority, ProviderInfo info, int resourceId) {
|
||||
static XmlResourceParser getFileProviderPathsMetaData(Context context, String authority, ProviderInfo info) {
|
||||
if (info == null) {
|
||||
throw new IllegalArgumentException("Couldn't find meta-data for provider with authority " + authority);
|
||||
}
|
||||
if (info.metaData == null && resourceId != 0) {
|
||||
info.metaData = new Bundle(1);
|
||||
info.metaData.putInt(META_DATA_FILE_PROVIDER_PATHS, resourceId);
|
||||
}
|
||||
final XmlResourceParser in = info.loadXmlMetaData(context.getPackageManager(), META_DATA_FILE_PROVIDER_PATHS);
|
||||
if (in == null) {
|
||||
throw new IllegalArgumentException("Missing " + META_DATA_FILE_PROVIDER_PATHS + " meta-data");
|
||||
|
|
@ -161,10 +156,10 @@ public class FileProvider extends ContentProvider {
|
|||
return in;
|
||||
}
|
||||
|
||||
private static PathStrategy parsePathStrategy(Context context, String authority, int resourceId) throws IOException, XmlPullParserException {
|
||||
private static PathStrategy parsePathStrategy(Context context, String authority) throws IOException, XmlPullParserException {
|
||||
final SimplePathStrategy strat = new SimplePathStrategy(authority);
|
||||
final ProviderInfo info = context.getPackageManager().resolveContentProvider(authority, PackageManager.GET_META_DATA);
|
||||
final XmlResourceParser in = getFileProviderPathsMetaData(context, authority, info, resourceId);
|
||||
final XmlResourceParser in = getFileProviderPathsMetaData(context, authority, info);
|
||||
int type;
|
||||
while ((type = in.next()) != END_DOCUMENT) {
|
||||
if (type == START_TAG) {
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@ import android.text.TextUtils;
|
|||
import com.github.catvod.spider.Init;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.net.URLConnection;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
|
@ -39,22 +37,6 @@ public class FileUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static String md5(File file) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] bytes = new byte[4096];
|
||||
int count;
|
||||
while ((count = fis.read(bytes)) != -1) digest.update(bytes, 0, count);
|
||||
fis.close();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : digest.digest()) sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
|
||||
return sb.toString();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static Uri getShareUri(File file) {
|
||||
return Build.VERSION.SDK_INT < Build.VERSION_CODES.N ? Uri.fromFile(file) : FileProvider.getUriForFile(Init.context(), Init.context().getPackageName() + ".provider", file);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
package com.github.catvod.utils;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import com.github.catvod.spider.Init;
|
||||
|
||||
public class ResUtil {
|
||||
|
||||
private static DisplayMetrics getDisplayMetrics() {
|
||||
return Init.context().getResources().getDisplayMetrics();
|
||||
}
|
||||
|
||||
public static int dp2px(int dp) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getDisplayMetrics());
|
||||
}
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package com.github.catvod.utils;
|
|||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.github.catvod.spider.Init;
|
||||
|
||||
|
|
@ -14,18 +13,11 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class Util {
|
||||
|
||||
public static final Pattern RULE = Pattern.compile("http((?!http).){12,}?\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|mkv|flv|mp3|m4a|aac)|http((?!http).)*?video/tos*");
|
||||
public static final Pattern THUNDER = Pattern.compile("(magnet|thunder|ed2k):.*");
|
||||
public static final String CHROME = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36";
|
||||
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";
|
||||
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");
|
||||
public static final List<String> SUB = Arrays.asList("srt", "ass", "ssa", "vtt");
|
||||
|
||||
public static boolean isVip(String url) {
|
||||
List<String> hosts = Arrays.asList("iqiyi.com", "v.qq.com", "youku.com", "le.com", "tudou.com", "mgtv.com", "sohu.com", "acfun.cn", "bilibili.com", "baofeng.com", "pptv.com");
|
||||
for (String host : hosts) if (url.contains(host)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isThunder(String url) {
|
||||
return THUNDER.matcher(url).find() || isTorrent(url);
|
||||
}
|
||||
|
|
@ -34,11 +26,6 @@ public class Util {
|
|||
return !url.startsWith("magnet") && url.split(";")[0].endsWith(".torrent");
|
||||
}
|
||||
|
||||
public static boolean isVideoFormat(String url) {
|
||||
if (url.contains("url=http") || url.contains(".js") || url.contains(".css") || url.contains(".html")) return false;
|
||||
return RULE.matcher(url).find();
|
||||
}
|
||||
|
||||
public static boolean isSub(String text) {
|
||||
return SUB.contains(getExt(text).toLowerCase());
|
||||
}
|
||||
|
|
@ -58,18 +45,6 @@ public class Util {
|
|||
return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
|
||||
}
|
||||
|
||||
public static String fixUrl(String base, String src) {
|
||||
if (src.startsWith("//")) {
|
||||
Uri parse = Uri.parse(base);
|
||||
return parse.getScheme() + ":" + src;
|
||||
} else if (!src.contains("://")) {
|
||||
Uri parse = Uri.parse(base);
|
||||
return parse.getScheme() + "://" + parse.getHost() + src;
|
||||
} else {
|
||||
return src;
|
||||
}
|
||||
}
|
||||
|
||||
public static String removeExt(String text) {
|
||||
return text.contains(".") ? text.substring(0, text.lastIndexOf(".")) : text;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue