Add market

This commit is contained in:
FongMi 2023-10-17 14:59:48 +08:00
parent 5fbe770c5f
commit c0ee0281c2
9 changed files with 161 additions and 1 deletions

View File

@ -45,5 +45,6 @@ dependencies {
implementation 'cn.wanghaomiao:JsoupXpath:2.5.1' implementation 'cn.wanghaomiao:JsoupXpath:2.5.1'
implementation 'com.google.zxing:core:3.3.0' implementation 'com.google.zxing:core:3.3.0'
//implementation 'com.orhanobut:logger:2.2.0' //implementation 'com.orhanobut:logger:2.2.0'
implementation 'androidx.core:core:1.8.0'
implementation 'org.jsoup:jsoup:1.15.3' implementation 'org.jsoup:jsoup:1.15.3'
} }

View File

@ -8,6 +8,9 @@
-keep class com.github.catvod.spider.* { public <methods>; } -keep class com.github.catvod.spider.* { public <methods>; }
-keep class com.github.catvod.parser.* { public <methods>; } -keep class com.github.catvod.parser.* { public <methods>; }
# AndroidX
-keep class androidx.core.** { *; }
# Gson # Gson
-keepattributes Signature -keepattributes Signature
-keepattributes *Annotation* -keepattributes *Annotation*

View File

@ -0,0 +1,43 @@
package com.github.catvod.bean.market;
import android.text.TextUtils;
import com.github.catvod.bean.Vod;
import com.google.gson.Gson;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class Item {
@SerializedName("name")
private String name;
@SerializedName("url")
private String url;
@SerializedName("icon")
private String icon;
public static List<Item> arrayFrom(String str) {
Type listType = new TypeToken<ArrayList<Item>>() {}.getType();
return new Gson().fromJson(str, listType);
}
public String getName() {
return TextUtils.isEmpty(name) ? "" : name;
}
public String getUrl() {
return TextUtils.isEmpty(url) ? "" : url;
}
public String getIcon() {
return TextUtils.isEmpty(icon) ? "" : icon;
}
public Vod vod() {
return new Vod(getUrl(), getName(), getIcon());
}
}

View File

@ -41,6 +41,10 @@ public class OkHttp {
return client().newBuilder().followRedirects(false).followSslRedirects(false).build(); return client().newBuilder().followRedirects(false).followSslRedirects(false).build();
} }
public static Response newCall(String url) throws IOException {
return client().newCall(new Request.Builder().url(url).build()).execute();
}
public static Response newCall(String url, Map<String, String> header) throws IOException { public static Response newCall(String url, Map<String, String> header) throws IOException {
return client().newCall(new Request.Builder().url(url).headers(Headers.of(header)).build()).execute(); return client().newCall(new Request.Builder().url(url).headers(Headers.of(header)).build()).execute();
} }

View File

@ -0,0 +1,82 @@
package com.github.catvod.spider;
import android.app.Activity;
import android.content.Context;
import android.net.Uri;
import com.github.catvod.bean.Result;
import com.github.catvod.bean.Vod;
import com.github.catvod.bean.market.Item;
import com.github.catvod.crawler.Spider;
import com.github.catvod.net.OkHttp;
import com.github.catvod.utils.FileUtil;
import com.github.catvod.utils.Utils;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Response;
public class Market extends Spider {
private List<Item> mItems;
@Override
public void init(Context context, String extend) throws Exception {
mItems = Item.arrayFrom(extend);
}
@Override
public String homeVideoContent() {
List<Vod> list = new ArrayList<>();
for (Item item : mItems) list.add(item.vod());
return Result.string(list);
}
@Override
public String detailContent(List<String> ids) throws Exception {
new Thread(() -> download(ids.get(0))).start();
Init.run(this::finish);
return "";
}
private void finish() {
try {
Activity activity = Init.getActivity();
if (activity != null) activity.finish();
} catch (Exception e) {
e.printStackTrace();
}
}
private void download(String url) {
try {
Utils.notify("正在下載...");
Response response = OkHttp.newCall(url);
File file = FileUtil.getCacheFile(Uri.parse(url).getLastPathSegment());
download(file, response.body().byteStream(), Double.parseDouble(response.header("Content-Length", "1")));
FileUtil.openFile(FileUtil.chmod(file));
} catch (Exception e) {
Utils.notify(e.getMessage());
}
}
private void download(File file, InputStream is, double length) throws Exception {
FileOutputStream os = new FileOutputStream(file);
try (BufferedInputStream input = new BufferedInputStream(is)) {
byte[] buffer = new byte[4096];
int readBytes;
long totalBytes = 0;
while ((readBytes = input.read(buffer)) != -1) {
totalBytes += readBytes;
os.write(buffer, 0, readBytes);
int progress = (int) (totalBytes / length * 100.0);
if (progress % 20 == 0) Utils.notify("正在下載..." + progress + "%");
}
}
}
}

View File

@ -1,5 +1,12 @@
package com.github.catvod.utils; package com.github.catvod.utils;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import androidx.core.content.FileProvider;
import com.github.catvod.spider.Init; import com.github.catvod.spider.Init;
import java.io.File; import java.io.File;
@ -7,6 +14,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.URLConnection;
public class FileUtil { public class FileUtil {
@ -64,4 +72,21 @@ public class FileUtil {
return ""; return "";
} }
} }
public static void openFile(File file) {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.setDataAndType(getShareUri(file), FileUtil.getMimeType(file.getName()));
Init.context().startActivity(intent);
}
private static String getMimeType(String fileName) {
String mimeType = URLConnection.guessContentTypeFromName(fileName);
return TextUtils.isEmpty(mimeType) ? "*/*" : mimeType;
}
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);
}
} }

Binary file not shown.

View File

@ -1 +1 @@
6aa99ddfd99dd2e5b68615edd29ddb43 1857d736869fbeb63ddf63e9065d053b

View File

@ -8,6 +8,7 @@ java -jar "%~dp0\3rd\baksmali-2.5.2.jar" d "%~dp0\..\app\build\intermediates\dex
rd /s/q "%~dp0\spider.jar\smali\com\github\catvod\spider" rd /s/q "%~dp0\spider.jar\smali\com\github\catvod\spider"
rd /s/q "%~dp0\spider.jar\smali\com\github\catvod\parser" rd /s/q "%~dp0\spider.jar\smali\com\github\catvod\parser"
rd /s/q "%~dp0\spider.jar\smali\com\github\catvod\js" rd /s/q "%~dp0\spider.jar\smali\com\github\catvod\js"
rd /s/q "%~dp0\spider.jar\smali\androidx\core"
if not exist "%~dp0\spider.jar\smali\com\github\catvod\" md "%~dp0\spider.jar\smali\com\github\catvod\" if not exist "%~dp0\spider.jar\smali\com\github\catvod\" md "%~dp0\spider.jar\smali\com\github\catvod\"
@ -16,6 +17,7 @@ java -Dfile.encoding=utf-8 -jar "%~dp0\3rd\oss.jar" "%~dp0\Smali_classes"
move "%~dp0\Smali_classes\com\github\catvod\spider" "%~dp0\spider.jar\smali\com\github\catvod\" move "%~dp0\Smali_classes\com\github\catvod\spider" "%~dp0\spider.jar\smali\com\github\catvod\"
move "%~dp0\Smali_classes\com\github\catvod\parser" "%~dp0\spider.jar\smali\com\github\catvod\" move "%~dp0\Smali_classes\com\github\catvod\parser" "%~dp0\spider.jar\smali\com\github\catvod\"
move "%~dp0\Smali_classes\com\github\catvod\js" "%~dp0\spider.jar\smali\com\github\catvod\" move "%~dp0\Smali_classes\com\github\catvod\js" "%~dp0\spider.jar\smali\com\github\catvod\"
move "%~dp0\Smali_classes\androidx\core" "%~dp0\spider.jar\smali\androidx\core\"
java -jar "%~dp0\3rd\apktool_2.4.1.jar" b "%~dp0\spider.jar" -c java -jar "%~dp0\3rd\apktool_2.4.1.jar" b "%~dp0\spider.jar" -c