pull/323/head
FongMi 2 years ago
parent bf8c96c34e
commit 1f5bf6cf2d
  1. 8
      app/src/main/java/com/fongmi/android/tv/api/config/VodConfig.java
  2. 12
      app/src/main/java/com/fongmi/android/tv/bean/Config.java
  3. 6
      app/src/main/java/com/fongmi/android/tv/db/AppDatabase.java
  4. 48
      catvod/src/main/java/com/github/catvod/bean/WrappedCookie.java
  5. 24
      catvod/src/main/java/com/github/catvod/net/OkCookieJar.java
  6. 2
      catvod/src/main/java/com/github/catvod/utils/Prefers.java

@ -194,7 +194,7 @@ public class VodConfig {
}
private void initLive(JsonObject object) {
Config temp = Config.find(config, 1);
Config temp = Config.find(config, 1).save();
boolean sync = LiveConfig.get().needSync(config.getUrl());
if (sync) LiveConfig.get().clear().config(temp).parse(object);
}
@ -360,20 +360,20 @@ public class VodConfig {
public void setParse(Parse parse) {
this.parse = parse;
this.parse.setActivated(true);
config.parse(parse.getName()).update();
config.parse(parse.getName()).save();
for (Parse item : getParses()) item.setActivated(parse);
}
public void setHome(Site home) {
this.home = home;
this.home.setActivated(true);
config.home(home.getKey()).update();
config.home(home.getKey()).save();
for (Site item : getSites()) item.setActivated(home);
}
private void setWall(String wall) {
this.wall = wall;
boolean load = !TextUtils.isEmpty(wall) && WallConfig.get().needSync(wall);
if (load) WallConfig.get().config(Config.find(wall, config.getName(), 2).update());
if (load) WallConfig.get().config(Config.find(wall, config.getName(), 2).save());
}
}

@ -38,7 +38,8 @@ public class Config {
private String parse;
public static List<Config> arrayFrom(String str) {
Type listType = new TypeToken<List<Config>>() {}.getType();
Type listType = new TypeToken<List<Config>>() {
}.getType();
List<Config> items = App.gson().fromJson(str, listType);
return items == null ? Collections.emptyList() : items;
}
@ -221,12 +222,17 @@ public class Config {
return this;
}
public Config save() {
if (isEmpty()) return this;
AppDatabase.get().getConfigDao().update(this);
return this;
}
public Config update() {
if (isEmpty()) return this;
setTime(System.currentTimeMillis());
Prefers.put("config_" + getType(), getUrl());
AppDatabase.get().getConfigDao().update(this);
return this;
return save();
}
public void delete() {

@ -80,9 +80,9 @@ public abstract class AppDatabase extends RoomDatabase {
File wal = new File(Path.tv(), NAME + "-wal");
File shm = new File(Path.tv(), NAME + "-shm");
File pref = new File(Path.tv(), NAME + "-pref");
if (db.exists()) Path.move(db, App.get().getDatabasePath(db.getName()).getAbsoluteFile());
if (wal.exists()) Path.move(wal, App.get().getDatabasePath(wal.getName()).getAbsoluteFile());
if (shm.exists()) Path.move(shm, App.get().getDatabasePath(shm.getName()).getAbsoluteFile());
if (db.exists()) Path.copy(db, App.get().getDatabasePath(db.getName()).getAbsoluteFile());
if (wal.exists()) Path.copy(wal, App.get().getDatabasePath(wal.getName()).getAbsoluteFile());
if (shm.exists()) Path.copy(shm, App.get().getDatabasePath(shm.getName()).getAbsoluteFile());
if (pref.exists()) Prefers.restore(pref);
App.post(callback::success);
});

@ -1,48 +0,0 @@
package com.github.catvod.bean;
import okhttp3.Cookie;
import okhttp3.HttpUrl;
public class WrappedCookie {
private final Cookie cookie;
public static WrappedCookie wrap(Cookie cookie) {
return new WrappedCookie(cookie);
}
private WrappedCookie(Cookie cookie) {
this.cookie = cookie;
}
public Cookie unwrap() {
return cookie;
}
public boolean isExpired() {
return cookie.expiresAt() < System.currentTimeMillis();
}
public boolean matches(HttpUrl url) {
return cookie.matches(url);
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (!(obj instanceof WrappedCookie)) return false;
WrappedCookie it = (WrappedCookie) obj;
return cookie.name().equals(it.cookie.name()) && cookie.domain().equals(it.cookie.domain()) && cookie.path().equals(it.cookie.path()) && cookie.secure() == it.cookie.secure() && cookie.hostOnly() == it.cookie.hostOnly();
}
@Override
public int hashCode() {
int result = 17;
result = 31 * result + cookie.name().hashCode();
result = 31 * result + cookie.domain().hashCode();
result = 31 * result + cookie.path().hashCode();
result = 31 * result + (cookie.secure() ? 0 : 1);
result = 31 * result + (cookie.hostOnly() ? 0 : 1);
return result;
}
}

@ -5,12 +5,8 @@ import android.webkit.CookieManager;
import androidx.annotation.NonNull;
import com.github.catvod.bean.WrappedCookie;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import okhttp3.Cookie;
import okhttp3.CookieJar;
@ -18,11 +14,9 @@ import okhttp3.HttpUrl;
public class OkCookieJar implements CookieJar {
private final Set<WrappedCookie> cache;
private final CookieManager manager;
public OkCookieJar() {
cache = new HashSet<>();
manager = CookieManager.getInstance();
}
@ -30,25 +24,13 @@ public class OkCookieJar implements CookieJar {
@Override
public synchronized List<Cookie> loadForRequest(@NonNull HttpUrl url) {
List<Cookie> items = new ArrayList<>();
for (WrappedCookie item : cache) if (item.isExpired()) cache.remove(item);
for (WrappedCookie item : cache) if (item.matches(url)) items.add(item.unwrap());
items.addAll(fromManager(url));
String cookie = manager.getCookie(url.toString());
if (!TextUtils.isEmpty(cookie)) for (String split : cookie.split(";")) items.add(Cookie.parse(url, split));
return items;
}
@Override
public synchronized void saveFromResponse(@NonNull HttpUrl url, List<Cookie> cookies) {
List<WrappedCookie> items = new ArrayList<>();
for (Cookie cookie : cookies) items.add(WrappedCookie.wrap(cookie));
for (Cookie cookie : cookies) manager.setCookie(url.toString(), cookie.toString());
cache.removeAll(items);
cache.addAll(items);
}
private List<Cookie> fromManager(HttpUrl url) {
List<Cookie> items = new ArrayList<>();
String cookie = manager.getCookie(url.toString());
if (!TextUtils.isEmpty(cookie)) for (String split : cookie.split(";")) items.add(Cookie.parse(url, split));
return items;
}
}
}

@ -100,8 +100,6 @@ public class Prefers {
for (Map.Entry<String, ?> entry : map.entrySet()) Prefers.put(entry.getKey(), convert(entry));
} catch (Exception e) {
e.printStackTrace();
} finally {
Path.clear(file);
}
}

Loading…
Cancel
Save