mirror of
https://github.com/lizongying/my-tv.git
synced 2026-11-12 22:46:33 +08:00
add ysp
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
package com.lizongying.mytv.api
|
||||
|
||||
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
|
||||
|
||||
class ApiClient {
|
||||
private val yspUrl = "https://player-api.yangshipin.cn/"
|
||||
|
||||
val yspApiService: YSPApiService by lazy {
|
||||
Retrofit.Builder()
|
||||
.baseUrl(yspUrl)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build().create(YSPApiService::class.java)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.lizongying.mytv.api
|
||||
|
||||
import android.util.Log
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.RequestBody
|
||||
import okio.BufferedSink
|
||||
import java.io.IOException
|
||||
|
||||
data class LiveInfo(
|
||||
val code: Int,
|
||||
val msg: String,
|
||||
val data: LiveInfoData,
|
||||
)
|
||||
|
||||
data class LiveInfoData(
|
||||
val playurl: String
|
||||
)
|
||||
|
||||
data class LiveInfoRequest(
|
||||
var data: String,
|
||||
) : RequestBody() {
|
||||
override fun contentType(): MediaType? {
|
||||
return MediaType.parse("application/json;charset=UTF-8")
|
||||
}
|
||||
|
||||
override fun writeTo(sink: BufferedSink) {
|
||||
try {
|
||||
sink.writeUtf8(data)
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "$e")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "LiveInfoRequest"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.lizongying.mytv.api
|
||||
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.RequestBody
|
||||
import okio.BufferedSink
|
||||
import java.io.IOException
|
||||
|
||||
data class Page(
|
||||
val code: Int,
|
||||
val msg: String,
|
||||
val data: Data,
|
||||
)
|
||||
|
||||
data class Data(
|
||||
val feedModuleList: List<Module>
|
||||
)
|
||||
|
||||
data class Module(
|
||||
val dataTvChannelList: List<TvChannelListData>
|
||||
)
|
||||
|
||||
data class TvChannelListData(
|
||||
val dataTvChannelList: List<TvChannelListData>
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
package com.lizongying.mytv.api
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import com.lizongying.mytv.Encryptor
|
||||
import com.lizongying.mytv.MainActivity
|
||||
import com.lizongying.mytv.models.TVViewModel
|
||||
import java.util.Date
|
||||
import kotlin.math.floor
|
||||
|
||||
class YSP(var context: Context) {
|
||||
private var cnlid = ""
|
||||
|
||||
private var livepid = ""
|
||||
|
||||
private var stream = "2"
|
||||
|
||||
private var guid = ""
|
||||
|
||||
private var cKey = ""
|
||||
|
||||
private var adjust = 1
|
||||
|
||||
private val sphttps = "1"
|
||||
|
||||
private var platform = "5910204"
|
||||
|
||||
private val cmd = "2"
|
||||
|
||||
private val encryptVer = "8.1"
|
||||
|
||||
private val dtype = "1"
|
||||
|
||||
private val devid = "devid"
|
||||
|
||||
private val otype = "ojson"
|
||||
|
||||
private val appVer = "V1.0.0"
|
||||
|
||||
private val appVersion = "V1.0.0"
|
||||
|
||||
private var randStr = ""
|
||||
|
||||
private val channel = "ysp_tx"
|
||||
|
||||
private var defn = ""
|
||||
|
||||
private var timeStr = ""
|
||||
|
||||
private var signature = ""
|
||||
|
||||
private var encryptor: Encryptor? = null
|
||||
private var sharedPref: SharedPreferences? = null
|
||||
|
||||
init {
|
||||
if (context is MainActivity) {
|
||||
encryptor = Encryptor()
|
||||
encryptor!!.init(context)
|
||||
|
||||
sharedPref = (context as MainActivity).getPreferences(Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
guid = getGuid()
|
||||
}
|
||||
|
||||
fun switch(tvModel: TVViewModel): String {
|
||||
livepid = tvModel.getTV().pid
|
||||
cnlid = tvModel.getTV().sid
|
||||
defn = "fhd"
|
||||
|
||||
guid = getGuid()
|
||||
randStr = getRand()
|
||||
timeStr = getTimeStr()
|
||||
|
||||
// guid = "lq3oqitm_1e15dnzgjnb"
|
||||
// randStr = "BfcCPQp8Hq"
|
||||
// timeStr = "1702166501"
|
||||
|
||||
cKey =
|
||||
encryptor!!.encrypt(cnlid, timeStr, appVer, guid, platform)
|
||||
signature = getSignature()
|
||||
return """{"cnlid":"$cnlid","livepid":"$livepid","stream":"$stream","guid":"$guid","cKey":"$cKey","adjust":$adjust,"sphttps":"$sphttps","platform":"$platform","cmd":"$cmd","encryptVer":"$encryptVer","dtype":"$dtype","devid":"$devid","otype":"$otype","appVer":"$appVer","app_version":"$appVersion","rand_str":"$randStr","channel":"$channel","defn":"$defn","signature":"$signature"}"""
|
||||
|
||||
}
|
||||
|
||||
private fun getTimeStr(): String {
|
||||
return (Date().time / 1000).toString()
|
||||
}
|
||||
|
||||
private fun generateGuid(): String {
|
||||
val timestamp = (System.currentTimeMillis()).toString(36)
|
||||
val originalString = Math.random().toString()
|
||||
val resultString = if (originalString.startsWith("0.")) {
|
||||
originalString.substring(2)
|
||||
} else {
|
||||
originalString
|
||||
}
|
||||
val randomPart = resultString.toLong().toString(36)
|
||||
return timestamp + "_" + randomPart
|
||||
}
|
||||
|
||||
private fun getGuid(): String {
|
||||
// var guid = sharedPref?.getString("guid", "").toString()
|
||||
if (guid == "") {
|
||||
guid = generateGuid()
|
||||
with(sharedPref!!.edit()) {
|
||||
putString("guid", guid)
|
||||
apply()
|
||||
}
|
||||
}
|
||||
return guid
|
||||
}
|
||||
|
||||
private fun getRand(): String {
|
||||
var n = ""
|
||||
val e = "ABCDEFGHIJKlMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
|
||||
val r = e.length
|
||||
for (i in 0 until 10) {
|
||||
n += e[floor(Math.random() * r).toInt()]
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
private fun getSignature(): String {
|
||||
val e =
|
||||
"adjust=${adjust}&appVer=${appVer}&app_version=$appVersion&cKey=$cKey&channel=$channel&cmd=$cmd&cnlid=$cnlid&defn=${defn}&devid=${devid}&dtype=${dtype}&encryptVer=${encryptVer}&guid=${guid}&livepid=${livepid}&otype=${otype}&platform=${platform}&rand_str=${randStr}&sphttps=${sphttps}&stream=${stream}".toByteArray()
|
||||
|
||||
val hashedData = encryptor?.hash(e) ?: return ""
|
||||
return hashedData.let { it -> it.joinToString("") { "%02x".format(it) } }
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "YSP"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.lizongying.mytv.api
|
||||
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.Header
|
||||
import retrofit2.http.Headers
|
||||
import retrofit2.http.POST
|
||||
|
||||
|
||||
interface YSPApiService {
|
||||
@POST("v1/player/get_live_info")
|
||||
@Headers(
|
||||
"content-type: application/json;charset=UTF-8",
|
||||
"referer: https://www.yangshipin.cn/",
|
||||
"yspappid: 519748109",
|
||||
"cookie: guid=1; vplatform=109"
|
||||
)
|
||||
fun getLiveInfo(
|
||||
@Body request: LiveInfoRequest,
|
||||
): Call<LiveInfo>
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.lizongying.mytv.api
|
||||
|
||||
import com.lizongying.mytv.proto.Ysp.cn.yangshipin.oms.common.proto.pageModel
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Headers
|
||||
import retrofit2.http.Path
|
||||
|
||||
interface YSPProtoService {
|
||||
@GET("api/oms/pc/page/PG00000004")
|
||||
@Headers(
|
||||
"yspappid: 519748109",
|
||||
"platform: 109",
|
||||
)
|
||||
fun getPage(
|
||||
): Call<pageModel.Response>
|
||||
|
||||
@GET("api/yspepg/program/{livepid}/{cnlid}")
|
||||
@Headers(
|
||||
"yspappid: 519748109",
|
||||
"platform: 109",
|
||||
)
|
||||
fun getProgram(
|
||||
@Path("livepid") livepid: String,
|
||||
@Path("cnlid") cnlid: String,
|
||||
): Call<LiveInfo>
|
||||
}
|
||||
Reference in New Issue
Block a user