diff --git a/.idea/misc.xml b/.idea/misc.xml index 1155f452..b0e41412 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -39,6 +39,7 @@ + diff --git a/app/src/main/java/com/github/tvbox/osc/base/App.java b/app/src/main/java/com/github/tvbox/osc/base/App.java index 4324f840..5b2a1657 100644 --- a/app/src/main/java/com/github/tvbox/osc/base/App.java +++ b/app/src/main/java/com/github/tvbox/osc/base/App.java @@ -49,6 +49,7 @@ public class App extends MultiDexApplication { .setSupportSP(false) .setSupportSubunits(Subunits.MM); PlayerHelper.init(); + JSEngine.getInstance().init(); } private void initParams() { diff --git a/app/src/main/java/com/github/tvbox/osc/js/JSEngine.java b/app/src/main/java/com/github/tvbox/osc/js/JSEngine.java index c358aea5..32323c5b 100644 --- a/app/src/main/java/com/github/tvbox/osc/js/JSEngine.java +++ b/app/src/main/java/com/github/tvbox/osc/js/JSEngine.java @@ -44,7 +44,7 @@ public class JSEngine { return instance; } - private void init() { + public void init() { try { quickJS = QuickJS.createRuntimeWithEventQueue(); module = new ES6Module(quickJS); @@ -60,7 +60,6 @@ public class JSEngine { public Spider getSpider(SourceBean sourceBean) { if (sourceBean.getExt().length() == 0) return new SpiderNull(); - if (quickJS == null) init(); if (spiders.containsKey(sourceBean.getKey())) return spiders.get(sourceBean.getKey()); String key = "J" + MD5.string2MD5(sourceBean.getKey() + System.currentTimeMillis()); String moduleJsStr = ""; @@ -165,17 +164,21 @@ public class JSEngine { public void stopAll() { OkGo.getInstance().cancelTag("js_okhttp_tag"); - clear(); + clearAll(); } - public void clear() { + public void clearAll() { if (quickJS == null) return; - spiders.clear(); + clear(); module.close(); quickJS.close(); - jsCache.clear(); module = null; quickJS = null; } + public void clear() { + spiders.clear(); + jsCache.clear(); + } + } diff --git a/app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java b/app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java new file mode 100644 index 00000000..cb482e9a --- /dev/null +++ b/app/src/main/java/com/github/tvbox/osc/picasso/MyOkhttpDownLoader.java @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2013 Square, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.tvbox.osc.picasso; + +import android.text.TextUtils; + +import androidx.annotation.NonNull; +import androidx.annotation.VisibleForTesting; +import com.squareup.picasso.Downloader; + +import java.io.IOException; + +import okhttp3.Cache; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +/** + * A {@link Downloader} which uses OkHttp to download images. + */ +public final class MyOkhttpDownLoader implements Downloader { + @VisibleForTesting + final Call.Factory client; + private final Cache cache; + private boolean sharedClient = true; + + /** + * Create a new downloader that uses the specified OkHttp instance. A response cache will not be + * automatically configured. + */ + public MyOkhttpDownLoader(OkHttpClient client) { + this.client = client; + this.cache = client.cache(); + } + + /** + * Create a new downloader that uses the specified {@link Call.Factory} instance. + */ + public MyOkhttpDownLoader(Call.Factory client) { + this.client = client; + this.cache = null; + } + + @NonNull + @Override + public Response load(@NonNull Request request) throws IOException { + String url = request.url().toString(); + + String refer = null; + String ua = null; + String cookie = null; + + //检查链接里面是否有自定义cookie + String[] cookieUrl = url.split("@Cookie="); + if (cookieUrl.length > 1) { + url = cookieUrl[0]; + cookie = cookieUrl[1]; + } + + //检查链接里面是否有自定义UA和referer + String[] s = url.split("@Referer="); + if (s.length > 1) { + if (s[0].contains("@User-Agent=")) { + refer = s[1]; + url = s[0].split("@User-Agent=")[0]; + ua = s[0].split("@User-Agent=")[1]; + } else if (s[1].contains("@User-Agent=")) { + refer = s[1].split("@User-Agent=")[0]; + url = s[0]; + ua = s[1].split("@User-Agent=")[1]; + } else { + refer = s[1]; + url = s[0]; + } + } else { + if (url.contains("@Referer=")) { + url = url.replace("@Referer=", ""); + refer = ""; + } + if (url.contains("@User-Agent=")) { + ua = url.split("@User-Agent=")[1]; + url = url.split("@User-Agent=")[0]; + } + } + Request.Builder mRequestBuilder = new Request.Builder().url(url); + + if (!TextUtils.isEmpty(cookie)) { + mRequestBuilder.addHeader("cookie", cookieUrl[1]); + } + if (!TextUtils.isEmpty(ua)) { + if (TextUtils.isEmpty(refer)) { + mRequestBuilder.addHeader("user-agent", ua); + } else { + mRequestBuilder.addHeader("user-agent", ua).addHeader("referer", refer); + } + } else { + if (!TextUtils.isEmpty(refer)) { + mRequestBuilder.addHeader("referer", refer); + } + } + return client.newCall(mRequestBuilder.build()).execute(); + } + + @Override + public void shutdown() { + if (!sharedClient && cache != null) { + try { + cache.close(); + } catch (IOException ignored) { + } + } + } +} diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/FastSearchActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/FastSearchActivity.java index cacede42..b691b8b6 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/FastSearchActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/FastSearchActivity.java @@ -2,6 +2,7 @@ package com.github.tvbox.osc.ui.activity; import android.content.Intent; import android.os.Bundle; +import android.text.TextUtils; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; @@ -450,21 +451,31 @@ public class FastSearchActivity extends BaseActivity { } } + private boolean matchSearchResult(String name, String searchTitle) { + if (TextUtils.isEmpty(name) || TextUtils.isEmpty(searchTitle)) return false; + searchTitle = searchTitle.trim(); + String[] arr = searchTitle.split("\\s+"); + int matchNum = 0; + for(String one : arr) { + if (name.contains(one)) matchNum++; + } + return matchNum == arr.length ? true : false; + } + private void searchData(AbsXml absXml) { String lastSourceKey = ""; if (absXml != null && absXml.movie != null && absXml.movie.videoList != null && absXml.movie.videoList.size() > 0) { List data = new ArrayList<>(); for (Movie.Video video : absXml.movie.videoList) { - if (video.name.contains(searchTitle)) { - data.add(video); - if (!resultVods.containsKey(video.sourceKey)) { - resultVods.put(video.sourceKey, new ArrayList()); - } - resultVods.get(video.sourceKey).add(video); - if (video.sourceKey != lastSourceKey) { - lastSourceKey = this.addWordAdapterIfNeed(video.sourceKey); - } + if (!matchSearchResult(video.name, searchTitle)) continue; + data.add(video); + if (!resultVods.containsKey(video.sourceKey)) { + resultVods.put(video.sourceKey, new ArrayList()); + } + resultVods.get(video.sourceKey).add(video); + if (video.sourceKey != lastSourceKey) { + lastSourceKey = this.addWordAdapterIfNeed(video.sourceKey); } } diff --git a/app/src/main/java/com/github/tvbox/osc/ui/activity/SearchActivity.java b/app/src/main/java/com/github/tvbox/osc/ui/activity/SearchActivity.java index 06029ad9..c3b8e537 100644 --- a/app/src/main/java/com/github/tvbox/osc/ui/activity/SearchActivity.java +++ b/app/src/main/java/com/github/tvbox/osc/ui/activity/SearchActivity.java @@ -482,12 +482,22 @@ public class SearchActivity extends BaseActivity { } } + private boolean matchSearchResult(String name, String searchTitle) { + if (TextUtils.isEmpty(name) || TextUtils.isEmpty(searchTitle)) return false; + searchTitle = searchTitle.trim(); + String[] arr = searchTitle.split("\\s+"); + int matchNum = 0; + for(String one : arr) { + if (name.contains(one)) matchNum++; + } + return matchNum == arr.length ? true : false; + } + private void searchData(AbsXml absXml) { if (absXml != null && absXml.movie != null && absXml.movie.videoList != null && absXml.movie.videoList.size() > 0) { List data = new ArrayList<>(); for (Movie.Video video : absXml.movie.videoList) { - if (video.name.contains(searchTitle)) - data.add(video); + if (matchSearchResult(video.name, searchTitle)) data.add(video); } if (searchAdapter.getData().size() > 0) { searchAdapter.addData(data); diff --git a/app/src/main/java/com/github/tvbox/osc/util/OkGoHelper.java b/app/src/main/java/com/github/tvbox/osc/util/OkGoHelper.java index 76bfed55..c3e15d7d 100644 --- a/app/src/main/java/com/github/tvbox/osc/util/OkGoHelper.java +++ b/app/src/main/java/com/github/tvbox/osc/util/OkGoHelper.java @@ -1,13 +1,15 @@ package com.github.tvbox.osc.util; +import android.graphics.Bitmap; + import com.github.tvbox.osc.base.App; +import com.github.tvbox.osc.picasso.MyOkhttpDownLoader; import com.github.tvbox.osc.util.SSL.SSLSocketFactoryCompat; import com.lzy.okgo.OkGo; import com.lzy.okgo.https.HttpsUtils; import com.lzy.okgo.interceptor.HttpLoggingInterceptor; import com.lzy.okgo.model.HttpHeaders; import com.orhanobut.hawk.Hawk; -import com.squareup.picasso.OkHttp3Downloader; import com.squareup.picasso.Picasso; import java.io.File; @@ -160,8 +162,12 @@ public class OkGoHelper { } static void initPicasso(OkHttpClient client) { - OkHttp3Downloader downloader = new OkHttp3Downloader(client); - Picasso picasso = new Picasso.Builder(App.getInstance()).downloader(downloader).build(); + client.dispatcher().setMaxRequestsPerHost(10); + MyOkhttpDownLoader downloader = new MyOkhttpDownLoader(client); + Picasso picasso = new Picasso.Builder(App.getInstance()) + .downloader(downloader) + .defaultBitmapConfig(Bitmap.Config.RGB_565) + .build(); Picasso.setSingletonInstance(picasso); } diff --git a/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java b/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java index b5f83a6e..390b8edd 100644 --- a/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java +++ b/app/src/main/java/com/github/tvbox/osc/viewmodel/SourceViewModel.java @@ -485,9 +485,12 @@ public class SourceViewModel extends ViewModel { String search = sp.searchContent(wd, false); if(!TextUtils.isEmpty(search)){ json(searchResult, search, sourceBean.getKey()); + } else { + json(searchResult, "", sourceBean.getKey()); } } catch (Throwable th) { th.printStackTrace(); + json(searchResult, "", sourceBean.getKey()); } } else if (type == 0 || type == 1) { OkGo.get(sourceBean.getApi()) diff --git a/app/src/main/res/layout/activity_live_play.xml b/app/src/main/res/layout/activity_live_play.xml index d0f143ff..378aa36c 100644 --- a/app/src/main/res/layout/activity_live_play.xml +++ b/app/src/main/res/layout/activity_live_play.xml @@ -770,7 +770,8 @@ android:layout_toLeftOf="@+id/iv_circle_bg" android:gravity="center" android:singleLine="true" - android:text="11Kb/s" + android:text="" + tools:text="0Kb/s" android:textColor="#FFFCFFFF" android:textSize="@dimen/vs_20" />