Skip to content

Commit

Permalink
merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
okcaptain committed Aug 29, 2024
2 parents fe829dd + ae12683 commit 2f6855d
Show file tree
Hide file tree
Showing 26 changed files with 92 additions and 43 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
minSdk 21
//noinspection ExpiredTargetSdkVersion
targetSdk 28
versionCode 247
versionName "2.4.7"
versionCode 250
versionName "2.5.0"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
Expand Down Expand Up @@ -149,7 +149,7 @@ dependencies {
implementation(ext: 'aar', name: 'dlna-dmr-release', group: 'fongmi', version: 'release')
leanbackImplementation 'androidx.leanback:leanback:1.2.0-alpha04'
leanbackImplementation 'com.github.hedzr:android-file-chooser:v1.2.0-final'
leanbackImplementation 'me.jessyan:autosize:1.2.1'
leanbackImplementation 'com.github.JessYanCoding:AndroidAutoSize:1.2.1'
mobileImplementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
mobileImplementation 'com.google.android.flexbox:flexbox:3.0.0'
mobileImplementation('com.journeyapps:zxing-android-embedded:4.3.0') { transitive = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public class CollectActivity extends BaseActivity {

Expand Down Expand Up @@ -127,7 +125,7 @@ private void setSite() {
private void search() {
mAdapter.add(Collect.all());
mBinding.pager.getAdapter().notifyDataSetChanged();
mExecutor = new PauseExecutor(Constant.THREAD_POOL, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
mExecutor = new PauseExecutor(Constant.THREAD_POOL);
mBinding.result.setText(getString(R.string.collect_result, getKeyword()));
for (Site site : mSites) mExecutor.execute(() -> search(site));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public boolean goRoot() {

@Override
public void onItemClick(Vod item) {
if (item.isFolder()) {
if (item.isAction()) {
mViewModel.action(getKey(), item.getAction());
} else if (item.isFolder()) {
mPages.add(Page.get(item, mBinding.recycler.getSelectedPosition()));
mBinding.recycler.setMoveTop(false);
getVideo(item.getVodId(), "1");
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/fongmi/android/tv/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class App extends Application {

public App() {
instance = this;
executor = Executors.newFixedThreadPool(Constant.THREAD_POOL * 2);
executor = Executors.newFixedThreadPool(Constant.THREAD_POOL);
handler = HandlerCompat.createAsync(Looper.getMainLooper());
gson = new Gson();
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/fongmi/android/tv/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ public class Constant {
//传送超時時間
public static final int TIMEOUT_TRANSMIT = 60 * 1000;
//搜尋線程數量
public static final int THREAD_POOL = 5;
public static final int THREAD_POOL = 10;
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/fongmi/android/tv/bean/Sub.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static Sub from(String path) {
if (path.startsWith("http")) {
return http(path);
} else {
return file(Path.utf8(Path.local(path)));
return file(Path.local(path));
}
}

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/fongmi/android/tv/bean/Vod.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public class Vod implements Parcelable {
@SerializedName("vod_tag")
private String vodTag;

@SerializedName("action")
private String action;

@SerializedName("cate")
private Cate cate;

Expand Down Expand Up @@ -167,6 +170,10 @@ public String getVodTag() {
return TextUtils.isEmpty(vodTag) ? "" : vodTag;
}

public String getAction() {
return TextUtils.isEmpty(action) ? "" : action;
}

public Cate getCate() {
return cate;
}
Expand Down Expand Up @@ -231,6 +238,10 @@ public boolean isFolder() {
return "folder".equals(getVodTag()) || getCate() != null;
}

public boolean isAction() {
return !getAction().isEmpty();
}

public boolean isManga() {
return "manga".equals(getVodTag());
}
Expand Down Expand Up @@ -303,6 +314,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeString(this.vodPlayFrom);
dest.writeString(this.vodPlayUrl);
dest.writeString(this.vodTag);
dest.writeString(this.action);
dest.writeInt(this.land);
dest.writeInt(this.circle);
dest.writeFloat(this.ratio);
Expand All @@ -326,6 +338,7 @@ protected Vod(Parcel in) {
this.vodPlayFrom = in.readString();
this.vodPlayUrl = in.readString();
this.vodTag = in.readString();
this.action = in.readString();
this.land = in.readInt();
this.circle = in.readInt();
this.ratio = in.readFloat();
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/fongmi/android/tv/model/SiteViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class SiteViewModel extends ViewModel {
public MutableLiveData<Result> result;
public MutableLiveData<Result> player;
public MutableLiveData<Result> search;
public MutableLiveData<Result> action;
public MutableLiveData<Danmu> danmaku;
public MutableLiveData<Result> download;
private ExecutorService executor;
Expand All @@ -57,6 +58,7 @@ public SiteViewModel() {
this.result = new MutableLiveData<>();
this.player = new MutableLiveData<>();
this.search = new MutableLiveData<>();
this.action = new MutableLiveData<>();
this.download = new MutableLiveData<>();
}

Expand Down Expand Up @@ -207,6 +209,15 @@ public void download(String key, String flag, String id) {
executePlayer(download, key, flag, id);
}

public void action(String key, String action) {
execute(this.action, () -> {
Site site = VodConfig.get().getSite(key);
if (site.getType() == 3) return Result.fromJson(site.recent().spider().action(action));
if (site.getType() == 4) return Result.fromJson(OkHttp.string(action));
return Result.empty();
});
}

public void searchContent(Site site, String keyword, boolean quick) throws Throwable {
if (site.getType() == 3) {
String searchContent = site.spider().searchContent(Trans.t2s(keyword), quick);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public Map<String, String> getHeaders() {
public void setSub(Sub sub) {
this.sub = sub;
if (isIjk()) return;
setPosition(getPosition());
setMediaSource();
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/fongmi/android/tv/player/Source.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void addCallable(Iterator<Episode> iterator, List<Callable<List<Episode>

public void parse(List<Flag> flags) throws Exception {
for (Flag flag : flags) {
ExecutorService executor = Executors.newFixedThreadPool(Constant.THREAD_POOL * 2);
ExecutorService executor = Executors.newFixedThreadPool(Constant.THREAD_POOL);
List<Callable<List<Episode>>> items = new ArrayList<>();
Iterator<Episode> iterator = flag.getEpisodes().iterator();
while (iterator.hasNext()) addCallable(iterator, items);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.fongmi.android.tv.utils;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
Expand All @@ -12,12 +12,14 @@ public class PauseExecutor extends ThreadPoolExecutor {
private final Condition condition;
private boolean isPaused;

public PauseExecutor(int corePoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
super(corePoolSize, corePoolSize, keepAliveTime, unit, workQueue);
public PauseExecutor(int corePoolSize) {
super(corePoolSize, corePoolSize, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
pauseLock = new ReentrantLock();
condition = pauseLock.newCondition();
}


@Override
protected void beforeExecute(Thread t, Runnable r) {
super.beforeExecute(t, r);
pauseLock.lock();
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/fongmi/android/tv/utils/Traffic.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class Traffic {
private static final DecimalFormat format = new DecimalFormat("#.0");
private static final String UNIT_KB = " KB/s";
private static final String UNIT_MB = " MB/s";
private static long lastTotalRxBytes = 0;
private static long lastTimeStamp = 0;
private static long lastTotalRxBytes;
private static long lastTimeStamp;

public static void setSpeed(TextView view) {
if (unsupported()) return;
Expand All @@ -27,8 +27,8 @@ private static boolean unsupported() {
}

private static String getSpeed() {
long nowTotalRxBytes = TrafficStats.getTotalRxBytes() / 1024;
long nowTimeStamp = System.currentTimeMillis();
long nowTotalRxBytes = TrafficStats.getTotalRxBytes() / 1024;
long speed = (nowTotalRxBytes - lastTotalRxBytes) * 1000 / Math.max(nowTimeStamp - lastTimeStamp, 1);
lastTimeStamp = nowTimeStamp;
lastTotalRxBytes = nowTotalRxBytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Response;
Expand Down Expand Up @@ -192,7 +190,7 @@ private void search() {
mBinding.view.setVisibility(View.VISIBLE);
mBinding.result.setVisibility(View.VISIBLE);
if (mExecutor != null) mExecutor.shutdownNow();
mExecutor = new PauseExecutor(Constant.THREAD_POOL * 2, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
mExecutor = new PauseExecutor(Constant.THREAD_POOL * 2);
String keyword = mBinding.keyword.getText().toString().trim();
for (Site site : mSites) mExecutor.execute(() -> search(site, keyword));
App.post(() -> mRecordAdapter.add(keyword), 250);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ public void onLoadMore(String page) {

@Override
public void onItemClick(Vod item) {
if (item.isFolder()) {
if (item.isAction()) {
mViewModel.action(getKey(), item.getAction());
} else if (item.isFolder()) {
mPages.add(Page.get(item, findPosition()));
getVideo(item.getVodId(), "1");
} else {
Expand Down
4 changes: 4 additions & 0 deletions catvod/src/main/java/com/github/catvod/crawler/Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public Object[] proxyLocal(Map<String, String> params) throws Exception {
return null;
}

public String action(String action) throws Exception {
return null;
}

public void destroy() {
}

Expand Down
4 changes: 0 additions & 4 deletions catvod/src/main/java/com/github/catvod/utils/Path.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ public static File write(File file, byte[] data) {
}
}

public static File utf8(File file) {
return write(cache(file.getName()), Util.utf8(readToByte(file)));
}

public static void move(File in, File out) {
copy(in, out);
clear(in);
Expand Down
14 changes: 0 additions & 14 deletions catvod/src/main/java/com/github/catvod/utils/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

import com.github.catvod.Init;

import org.mozilla.universalchardet.UniversalDetector;

import java.io.File;
import java.io.FileInputStream;
import java.math.BigInteger;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Enumeration;
Expand Down Expand Up @@ -68,17 +65,6 @@ public static boolean equals(String name, String md5) {
return md5(Path.jar(name)).equalsIgnoreCase(md5);
}

public static byte[] utf8(byte[] bytes) {
try {
UniversalDetector detector = new UniversalDetector(null);
detector.handleData(bytes, 0, bytes.length);
detector.dataEnd();
return new String(bytes, detector.getDetectedCharset()).getBytes(StandardCharsets.UTF_8);
} catch (Exception e) {
return bytes;
}
}

public static String md5(String src) {
try {
if (TextUtils.isEmpty(src)) return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public Object[] proxyLocal(Map<String, String> params) {
return result;
}

@Override
public String action(String action) {
return app.callAttr("action", obj, action).toString();
}

@Override
public void destroy() {
app.callAttr("destroy", obj);
Expand Down
6 changes: 6 additions & 0 deletions pyramid/src/main/python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ def destroy(ru):
ru.destroy()


def action(ru, action):
result = ru.action(action)
formatJo = json.dumps(result, ensure_ascii=False)
return formatJo


def run():
pass

Expand Down
3 changes: 3 additions & 0 deletions pyramid/src/main/python/base/spider.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def isVideoFormat(self, url):
def manualVideoCheck(self):
pass

def action(self, action):
pass

def destroy(self):
pass

Expand Down
5 changes: 4 additions & 1 deletion pyramid/src/main/python/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@ def isVideoFormat(self, url):
def manualVideoCheck(self):
return self.spider.manualVideoCheck()

def action(self, action):
return self.spider.action(action)

def destroy(self):
return self.spider.destroy()
self.spider.destroy()
6 changes: 5 additions & 1 deletion pyramid/src/main/python/trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def isVideoFormat(sp_obj, url):
def manualVideoCheck(sp_obj):
return sp_obj.manualVideoCheck()

@staticmethod
def action(sp_obj, action):
return sp_obj.action(action)

@staticmethod
def destroy(sp_obj):
return sp_obj.destroy()
sp_obj.destroy()
5 changes: 5 additions & 0 deletions quickjs/src/main/java/com/fongmi/quickjs/crawler/Spider.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ public Object[] proxyLocal(Map<String, String> params) throws Exception {
else return submit(() -> proxy1(params)).get();
}

@Override
public String action(String action) throws Exception {
return (String) call("action", action);
}

@Override
public void destroy() {
try {
Expand Down
2 changes: 2 additions & 0 deletions quickjs/src/main/java/com/fongmi/quickjs/method/Async.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ private CompletableFuture<Object> call(JSObject object, String name, Object[] ar
Object result = function.call(args);
if (result instanceof JSObject) then(result);
else future.complete(result);
function.release();
return future;
}

Expand All @@ -36,6 +37,7 @@ private void then(Object result) {
JSObject promise = (JSObject) result;
JSFunction then = promise.getJSFunction("then");
if (then != null) then.call(callback);
if (then != null) then.release();
}

private final JSCallFunction callback = new JSCallFunction() {
Expand Down
Loading

0 comments on commit 2f6855d

Please sign in to comment.