dns cache
This commit is contained in:
parent
61f62121f2
commit
f0f43e0fda
|
|
@ -7,11 +7,9 @@ import android.util.Base64
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.lizongying.mytv.Utils.getDateFormat
|
import com.lizongying.mytv.Utils.getDateFormat
|
||||||
import com.lizongying.mytv.api.ApiClient
|
import com.lizongying.mytv.api.ApiClient
|
||||||
import com.lizongying.mytv.api.BtraceClient
|
|
||||||
import com.lizongying.mytv.api.Info
|
import com.lizongying.mytv.api.Info
|
||||||
import com.lizongying.mytv.api.LiveInfo
|
import com.lizongying.mytv.api.LiveInfo
|
||||||
import com.lizongying.mytv.api.LiveInfoRequest
|
import com.lizongying.mytv.api.LiveInfoRequest
|
||||||
import com.lizongying.mytv.api.ProtoClient
|
|
||||||
import com.lizongying.mytv.api.YSP
|
import com.lizongying.mytv.api.YSP
|
||||||
import com.lizongying.mytv.api.YSPApiService
|
import com.lizongying.mytv.api.YSPApiService
|
||||||
import com.lizongying.mytv.api.YSPBtraceService
|
import com.lizongying.mytv.api.YSPBtraceService
|
||||||
|
|
@ -31,8 +29,8 @@ import javax.crypto.spec.SecretKeySpec
|
||||||
class Request {
|
class Request {
|
||||||
private var yspTokenService: YSPTokenService = ApiClient().yspTokenService
|
private var yspTokenService: YSPTokenService = ApiClient().yspTokenService
|
||||||
private var yspApiService: YSPApiService = ApiClient().yspApiService
|
private var yspApiService: YSPApiService = ApiClient().yspApiService
|
||||||
private var yspBtraceService: YSPBtraceService = BtraceClient().yspBtraceService
|
private var yspBtraceService: YSPBtraceService = ApiClient().yspBtraceService
|
||||||
private var yspProtoService: YSPProtoService = ProtoClient().yspProtoService
|
private var yspProtoService: YSPProtoService = ApiClient().yspProtoService
|
||||||
private var ysp: YSP? = null
|
private var ysp: YSP? = null
|
||||||
|
|
||||||
// TODO onDestroy
|
// TODO onDestroy
|
||||||
|
|
@ -62,7 +60,6 @@ class Request {
|
||||||
"CGTN阿拉伯语频道" to "CGTN 阿拉伯语频道",
|
"CGTN阿拉伯语频道" to "CGTN 阿拉伯语频道",
|
||||||
"CGTN西班牙语频道" to "CGTN 西班牙语频道",
|
"CGTN西班牙语频道" to "CGTN 西班牙语频道",
|
||||||
"CGTN外语纪录频道" to "CGTN 纪录频道",
|
"CGTN外语纪录频道" to "CGTN 纪录频道",
|
||||||
|
|
||||||
"东方卫视" to "东方卫视",
|
"东方卫视" to "东方卫视",
|
||||||
"湖南卫视" to "湖南卫视",
|
"湖南卫视" to "湖南卫视",
|
||||||
"湖北卫视" to "湖北卫视",
|
"湖北卫视" to "湖北卫视",
|
||||||
|
|
@ -137,8 +134,8 @@ class Request {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (liveInfo?.data?.errinfo != null && liveInfo.data.errinfo != "success!") {
|
if (liveInfo?.data?.errinfo != null && liveInfo.data.errinfo == "应版权方要求,暂停提供直播信号,请点击观看其他精彩节目") {
|
||||||
Log.e(TAG, "$title url error ${liveInfo.data.errinfo}")
|
Log.e(TAG, "$title error ${liveInfo.data.errinfo}")
|
||||||
tvModel.setErrInfo(liveInfo.data.errinfo)
|
tvModel.setErrInfo(liveInfo.data.errinfo)
|
||||||
} else {
|
} else {
|
||||||
Log.e(TAG, "$title url error $request $liveInfo")
|
Log.e(TAG, "$title url error $request $liveInfo")
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,26 @@
|
||||||
package com.lizongying.mytv.api
|
package com.lizongying.mytv.api
|
||||||
|
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
|
import retrofit2.converter.protobuf.ProtoConverterFactory
|
||||||
|
|
||||||
|
|
||||||
class ApiClient {
|
class ApiClient {
|
||||||
private val yspUrl = "https://player-api.yangshipin.cn/"
|
private val yspUrl = "https://player-api.yangshipin.cn/"
|
||||||
private val myUrl = "https://lyrics.run/"
|
private val myUrl = "https://lyrics.run/"
|
||||||
// private val myUrl = "http://10.0.2.2:8081/"
|
private val protoUrl = "https://capi.yangshipin.cn/"
|
||||||
|
private val traceUrl = "https://btrace.yangshipin.cn/"
|
||||||
|
|
||||||
|
private var okHttpClient = OkHttpClient.Builder()
|
||||||
|
.dns(DnsCache())
|
||||||
|
.build()
|
||||||
|
|
||||||
val yspApiService: YSPApiService by lazy {
|
val yspApiService: YSPApiService by lazy {
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(yspUrl)
|
.baseUrl(yspUrl)
|
||||||
|
.client(okHttpClient)
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
.build().create(YSPApiService::class.java)
|
.build().create(YSPApiService::class.java)
|
||||||
}
|
}
|
||||||
|
|
@ -20,7 +28,24 @@ class ApiClient {
|
||||||
val yspTokenService: YSPTokenService by lazy {
|
val yspTokenService: YSPTokenService by lazy {
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl(myUrl)
|
.baseUrl(myUrl)
|
||||||
|
.client(okHttpClient)
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
.build().create(YSPTokenService::class.java)
|
.build().create(YSPTokenService::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val yspProtoService: YSPProtoService by lazy {
|
||||||
|
Retrofit.Builder()
|
||||||
|
.baseUrl(protoUrl)
|
||||||
|
.client(okHttpClient)
|
||||||
|
.addConverterFactory(ProtoConverterFactory.create())
|
||||||
|
.build().create(YSPProtoService::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
val yspBtraceService: YSPBtraceService by lazy {
|
||||||
|
Retrofit.Builder()
|
||||||
|
.baseUrl(traceUrl)
|
||||||
|
.client(okHttpClient)
|
||||||
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
|
.build().create(YSPBtraceService::class.java)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
package com.lizongying.mytv.api
|
|
||||||
|
|
||||||
|
|
||||||
import retrofit2.Retrofit
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
|
||||||
|
|
||||||
|
|
||||||
class BtraceClient {
|
|
||||||
private val yspUrl = "https://btrace.yangshipin.cn/"
|
|
||||||
|
|
||||||
val yspBtraceService: YSPBtraceService by lazy {
|
|
||||||
Retrofit.Builder()
|
|
||||||
.baseUrl(yspUrl)
|
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
|
||||||
.build().create(YSPBtraceService::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.lizongying.mytv.api
|
||||||
|
|
||||||
|
import okhttp3.Dns
|
||||||
|
import java.net.InetAddress
|
||||||
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
|
class DnsCache : Dns {
|
||||||
|
private val dnsCache: MutableMap<String, List<InetAddress>> = ConcurrentHashMap()
|
||||||
|
|
||||||
|
override fun lookup(hostname: String): List<InetAddress> {
|
||||||
|
dnsCache[hostname]?.let {
|
||||||
|
return it
|
||||||
|
}
|
||||||
|
|
||||||
|
val addresses = InetAddress.getAllByName(hostname).toList()
|
||||||
|
|
||||||
|
if (addresses.isNotEmpty()) {
|
||||||
|
dnsCache[hostname] = addresses
|
||||||
|
}
|
||||||
|
|
||||||
|
return addresses
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
package com.lizongying.mytv.api
|
|
||||||
|
|
||||||
import retrofit2.Retrofit
|
|
||||||
import retrofit2.converter.protobuf.ProtoConverterFactory
|
|
||||||
|
|
||||||
|
|
||||||
class ProtoClient {
|
|
||||||
private val protoUrl = "https://capi.yangshipin.cn/"
|
|
||||||
|
|
||||||
val yspProtoService: YSPProtoService by lazy {
|
|
||||||
Retrofit.Builder()
|
|
||||||
.baseUrl(protoUrl)
|
|
||||||
.addConverterFactory(ProtoConverterFactory.create())
|
|
||||||
.build().create(YSPProtoService::class.java)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -70,6 +70,8 @@ class YSP(var context: Context) {
|
||||||
defn = "fhd"
|
defn = "fhd"
|
||||||
|
|
||||||
randStr = getRand()
|
randStr = getRand()
|
||||||
|
|
||||||
|
guid = newGuid()
|
||||||
timeStr = getTimeStr()
|
timeStr = getTimeStr()
|
||||||
|
|
||||||
// guid = "lq3oqitm_1e15dnzgjnb"
|
// guid = "lq3oqitm_1e15dnzgjnb"
|
||||||
|
|
@ -105,6 +107,15 @@ class YSP(var context: Context) {
|
||||||
return guid
|
return guid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun newGuid(): String {
|
||||||
|
guid = generateGuid()
|
||||||
|
with(sharedPref!!.edit()) {
|
||||||
|
putString("guid", guid)
|
||||||
|
apply()
|
||||||
|
}
|
||||||
|
return guid
|
||||||
|
}
|
||||||
|
|
||||||
fun getRand(): String {
|
fun getRand(): String {
|
||||||
var n = ""
|
var n = ""
|
||||||
val e = "ABCDEFGHIJKlMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
val e = "ABCDEFGHIJKlMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||||
private var itemPosition: Int = 0
|
private var itemPosition: Int = 0
|
||||||
|
|
||||||
var retryTimes: Int = 0
|
var retryTimes: Int = 0
|
||||||
var retryMaxTimes: Int = 3
|
var retryMaxTimes: Int = 5
|
||||||
var programUpdateTime: Long = 0
|
var programUpdateTime: Long = 0
|
||||||
|
|
||||||
private val _errInfo = MutableLiveData<String>()
|
private val _errInfo = MutableLiveData<String>()
|
||||||
|
|
@ -71,7 +71,7 @@ class TVViewModel(private var tv: TV) : ViewModel() {
|
||||||
val ready: LiveData<Boolean>
|
val ready: LiveData<Boolean>
|
||||||
get() = _ready
|
get() = _ready
|
||||||
|
|
||||||
private var mMinimumLoadableRetryCount = 3
|
private var mMinimumLoadableRetryCount = 5
|
||||||
|
|
||||||
var seq = 0
|
var seq = 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue