@@ -26,7 +26,6 @@ import retrofit2.Response
2626import  javax.crypto.Cipher 
2727import  javax.crypto.spec.IvParameterSpec 
2828import  javax.crypto.spec.SecretKeySpec 
29- import  kotlin.reflect.KFunction0 
3029
3130
3231class  Request  {
@@ -93,27 +92,6 @@ class Request {
9392        ysp =  YSP (context)
9493    }
9594
96-     fun  fetchToken (fragmentReady :  KFunction0 <Unit >) {
97-         yspTokenService.getInfo()
98-             .enqueue(object  :  Callback <Info > {
99-                 override  fun  onResponse (call :  Call <Info >, response :  Response <Info >) {
100-                     if  (response.isSuccessful) {
101-                         val  info =  response.body()
102-                         token =  info?.data?.token
103-                         Log .i(TAG , " info success $token " 
104-                     } else  {
105-                         Log .e(TAG , " info status error" 
106-                     }
107-                     fragmentReady()
108-                 }
109- 
110-                 override  fun  onFailure (call :  Call <Info >, t :  Throwable ) {
111-                     Log .e(TAG , " info request error $t " 
112-                     fragmentReady()
113-                 }
114-             })
115-     }
116- 
11795    fun  fetchVideo (tvModel :  TVViewModel , cookie :  String ) {
11896        if  (::myRunnable.isInitialized) {
11997            handler.removeCallbacks(myRunnable)
@@ -150,26 +128,38 @@ class Request {
150128                                Log .i(TAG , " $title  url $url " 
151129                                tvModel.addVideoUrl(url)
152130                                tvModel.allReady()
153- 
131+                                 tvModel.retryTimes  =   0 
154132                                myRunnable =  MyRunnable (tvModel)
155133                                handler.post(myRunnable)
156134                            } else  {
157135                                Log .e(TAG , " $title  key error" 
158-                                 tvModel.firstSource()
136+                                 if  (tvModel.retryTimes <  tvModel.retryMaxTimes) {
137+                                     tvModel.retryTimes++ 
138+                                     fetchData(tvModel)
139+                                 }
159140                            }
160141                        } else  {
161142                            Log .e(TAG , " $title  url error $request " 
162-                             tvModel.firstSource()
143+                             if  (tvModel.retryTimes <  tvModel.retryMaxTimes) {
144+                                 tvModel.retryTimes++ 
145+                                 fetchData(tvModel)
146+                             }
163147                        }
164148                    } else  {
165149                        Log .e(TAG , " $title  status error" 
166-                         tvModel.firstSource()
150+                         if  (tvModel.retryTimes <  tvModel.retryMaxTimes) {
151+                             tvModel.retryTimes++ 
152+                             fetchData(tvModel)
153+                         }
167154                    }
168155                }
169156
170157                override  fun  onFailure (call :  Call <LiveInfo >, t :  Throwable ) {
171158                    Log .e(TAG , " $title  request error" 
172-                     tvModel.firstSource()
159+                     if  (tvModel.retryTimes <  tvModel.retryMaxTimes) {
160+                         tvModel.retryTimes++ 
161+                         fetchData(tvModel)
162+                     }
173163                }
174164            })
175165    }
@@ -207,11 +197,19 @@ class Request {
207197                            fetchVideo(tvModel, cookie)
208198                        } else  {
209199                            Log .e(TAG , " info status error" 
200+                             if  (tvModel.retryTimes <  tvModel.retryMaxTimes) {
201+                                 tvModel.retryTimes++ 
202+                                 fetchData(tvModel)
203+                             }
210204                        }
211205                    }
212206
213207                    override  fun  onFailure (call :  Call <Info >, t :  Throwable ) {
214208                        Log .e(TAG , " info request error $t " 
209+                         if  (tvModel.retryTimes <  tvModel.retryMaxTimes) {
210+                             tvModel.retryTimes++ 
211+                             fetchData(tvModel)
212+                         }
215213                    }
216214                })
217215        } else  {
@@ -251,7 +249,6 @@ class Request {
251249                        //                         Log.d(TAG, "$title kvcollect success")
252250                    } else  {
253251                        Log .e(TAG , " $title  kvcollect status error" 
254-                         tvModel.firstSource()
255252                    }
256253                }
257254
0 commit comments