22
22
import app .revanced .extension .shared .Logger ;
23
23
import app .revanced .extension .shared .Utils ;
24
24
import app .revanced .extension .shared .settings .BaseSettings ;
25
- import app .revanced .extension .shared .spoof .AudioStreamLanguage ;
26
25
import app .revanced .extension .shared .spoof .ClientType ;
27
26
28
27
/**
36
35
*/
37
36
public class StreamingDataRequest {
38
37
39
- private static final ClientType [] CLIENT_ORDER_TO_USE = ClientType .values ();
38
+ private static final ClientType [] CLIENT_ORDER_TO_USE ;
39
+
40
+ static {
41
+ ClientType [] allClientTypes = ClientType .values ();
42
+ ClientType preferredClient = BaseSettings .SPOOF_VIDEO_STREAMS_CLIENT_TYPE .get ();
43
+
44
+ CLIENT_ORDER_TO_USE = new ClientType [allClientTypes .length ];
45
+ CLIENT_ORDER_TO_USE [0 ] = preferredClient ;
46
+
47
+ int i = 1 ;
48
+ for (ClientType c : allClientTypes ) {
49
+ if (c != preferredClient ) {
50
+ CLIENT_ORDER_TO_USE [i ++] = c ;
51
+ }
52
+ }
53
+ }
40
54
41
55
private static final String AUTHORIZATION_HEADER = "Authorization" ;
42
56
@@ -73,6 +87,13 @@ protected boolean removeEldestEntry(Entry eldest) {
73
87
}
74
88
});
75
89
90
+ private static volatile ClientType lastSpoofedClientType ;
91
+
92
+ public static String getLastSpoofedClientName () {
93
+ ClientType client = lastSpoofedClientType ;
94
+ return client == null ? "Unknown" : client .friendlyName ;
95
+ }
96
+
76
97
private final String videoId ;
77
98
78
99
private final Future <ByteBuffer > future ;
@@ -164,20 +185,14 @@ private static ByteBuffer fetch(String videoId, Map<String, String> playerHeader
164
185
// Show an error if the last client type fails, or if the debug is enabled then show for all attempts.
165
186
final boolean showErrorToast = (++i == CLIENT_ORDER_TO_USE .length ) || debugEnabled ;
166
187
167
- if (clientType == ClientType .ANDROID_VR_NO_AUTH
168
- && BaseSettings .SPOOF_VIDEO_STREAMS_LANGUAGE .get () == AudioStreamLanguage .DEFAULT ) {
169
- // Only use no auth Android VR if a non default audio language is selected.
170
- continue ;
171
- }
172
-
173
188
HttpURLConnection connection = send (clientType , videoId , playerHeaders , showErrorToast );
174
189
if (connection != null ) {
175
190
try {
176
191
// gzip encoding doesn't response with content length (-1),
177
192
// but empty response body does.
178
193
if (connection .getContentLength () == 0 ) {
179
194
if (BaseSettings .DEBUG .get ()) {
180
- Logger .printException (() -> "Ignoring empty client response : " + clientType );
195
+ Logger .printException (() -> "Ignoring empty client: " + clientType );
181
196
}
182
197
} else {
183
198
try (InputStream inputStream = new BufferedInputStream (connection .getInputStream ());
@@ -188,6 +203,7 @@ private static ByteBuffer fetch(String videoId, Map<String, String> playerHeader
188
203
while ((bytesRead = inputStream .read (buffer )) >= 0 ) {
189
204
baos .write (buffer , 0 , bytesRead );
190
205
}
206
+ lastSpoofedClientType = clientType ;
191
207
192
208
return ByteBuffer .wrap (baos .toByteArray ());
193
209
}
@@ -198,7 +214,8 @@ private static ByteBuffer fetch(String videoId, Map<String, String> playerHeader
198
214
}
199
215
}
200
216
201
- handleConnectionError ("Could not fetch any client streams" , null , debugEnabled );
217
+ lastSpoofedClientType = null ;
218
+ handleConnectionError ("Could not fetch any client streams" , null , true );
202
219
return null ;
203
220
}
204
221
0 commit comments