|
21 | 21 | import android.media.AudioManager; |
22 | 22 | import java.net.*; |
23 | 23 | import javax.net.ssl.HttpsURLConnection; |
| 24 | +import java.util.*; |
| 25 | + |
24 | 26 |
|
25 | 27 |
|
26 | 28 | public class MainActivity extends Activity { |
@@ -95,49 +97,87 @@ public void load(boolean dl) { |
95 | 97 | } |
96 | 98 |
|
97 | 99 | web.setWebViewClient(new WebViewClient() { |
98 | | - @Override |
99 | | - public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { |
100 | | - String url = request.getUrl().toString(); |
101 | | - |
102 | | - if (url.contains("youtube.com/ytpro_cdn/npm")) { |
103 | | - |
104 | | - String modifiedUrl = url.replace("youtube.com/ytpro_cdn", "cdn.jsdelivr.net"); |
105 | | - try { |
106 | | - URL newUrl = new URL(modifiedUrl); |
107 | | - HttpsURLConnection connection = (HttpsURLConnection) newUrl.openConnection(); |
108 | | - |
109 | | - connection.setUseCaches(false); |
110 | | - connection.setDefaultUseCaches(false); |
111 | | - connection.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); |
112 | | - connection.addRequestProperty("Pragma", "no-cache"); |
113 | | - connection.addRequestProperty("Expires", "0"); |
114 | | - connection.setRequestProperty("User-Agent", "YTPRO"); |
115 | | - connection.setRequestProperty("Accept", "*/*"); |
116 | | - |
117 | | - connection.setConnectTimeout(10000); |
118 | | - connection.setReadTimeout(10000); |
119 | | - |
120 | | - connection.setRequestMethod("GET"); |
121 | | - |
122 | | - connection.connect(); |
123 | | - |
124 | | - String mimeType = connection.getContentType(); |
125 | | - String encoding = connection.getContentEncoding(); |
126 | | - if (encoding == null) encoding = "utf-8"; |
127 | | - |
128 | | - InputStream inputStream = connection.getInputStream(); |
129 | | - |
130 | | - return new WebResourceResponse(mimeType, encoding, inputStream); |
131 | | - |
132 | | - } catch (Exception e) { |
133 | | - e.printStackTrace(); |
134 | | - return super.shouldInterceptRequest(view, request); |
135 | | - } |
136 | | - |
137 | | - } |
138 | | - |
139 | | - return super.shouldInterceptRequest(view, request); |
140 | | - } |
| 100 | + @Override |
| 101 | + public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { |
| 102 | + String url = request.getUrl().toString(); |
| 103 | + |
| 104 | + if (url.contains("youtube.com/ytpro_cdn/")) { |
| 105 | + |
| 106 | + |
| 107 | + String modifiedUrl = null; |
| 108 | + |
| 109 | + if (url.contains("youtube.com/ytpro_cdn/esm")) { |
| 110 | + modifiedUrl = url.replace("youtube.com/ytpro_cdn/esm", "esm.sh"); |
| 111 | + } else if (url.contains("youtube.com/ytpro_cdn/npm")) { |
| 112 | + modifiedUrl = url.replace("youtube.com/ytpro_cdn", "cdn.jsdelivr.net"); |
| 113 | + } |
| 114 | + try { |
| 115 | + URL newUrl = new URL(modifiedUrl); |
| 116 | + HttpsURLConnection connection = (HttpsURLConnection) newUrl.openConnection(); |
| 117 | + |
| 118 | + connection.setUseCaches(false); |
| 119 | + connection.setDefaultUseCaches(false); |
| 120 | + connection.addRequestProperty("Cache-Control", "no-cache, no-store, must-revalidate"); |
| 121 | + connection.addRequestProperty("Pragma", "no-cache"); |
| 122 | + connection.addRequestProperty("Expires", "0"); |
| 123 | + connection.setRequestProperty("User-Agent", "YTPRO"); |
| 124 | + connection.setRequestProperty("Accept", "**"); |
| 125 | + |
| 126 | + connection.setConnectTimeout(10000); |
| 127 | + connection.setReadTimeout(10000); |
| 128 | + |
| 129 | + connection.setRequestMethod("GET"); |
| 130 | + |
| 131 | + connection.connect(); |
| 132 | + |
| 133 | + String mimeType = connection.getContentType(); |
| 134 | + String encoding = connection.getContentEncoding(); |
| 135 | + if (encoding == null) encoding = "utf-8"; |
| 136 | + String contentType = connection.getContentType(); |
| 137 | + if (contentType == null) { |
| 138 | + contentType = "application/javascript"; |
| 139 | + |
| 140 | + Map < String, String > headers = new HashMap < > (); |
| 141 | + headers.put("Access-Control-Allow-Origin", "*"); |
| 142 | + headers.put("Access-Control-Allow-Methods", "GET, POST, OPTIONS"); |
| 143 | + headers.put("Access-Control-Allow-Headers", "*"); |
| 144 | + headers.put("Content-Type", contentType); |
| 145 | + |
| 146 | + headers.put("Access-Control-Allow-Credentials", "true"); |
| 147 | + headers.put("Cross-Origin-Resource-Policy", "cross-origin"); |
| 148 | + |
| 149 | + if (request.getMethod().equals("OPTIONS")) { |
| 150 | + return new WebResourceResponse( |
| 151 | + "text/plain", |
| 152 | + "UTF-8", |
| 153 | + 204, |
| 154 | + "No Content", |
| 155 | + headers, |
| 156 | + null |
| 157 | + ); |
| 158 | + } |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + return new WebResourceResponse( |
| 163 | + mimeType, |
| 164 | + encoding, |
| 165 | + connection.getResponseCode(), |
| 166 | + "OK", |
| 167 | + headers, |
| 168 | + connection.getInputStream() |
| 169 | + ); |
| 170 | + |
| 171 | + |
| 172 | + } catch (Exception e) { |
| 173 | + e.printStackTrace(); |
| 174 | + return super.shouldInterceptRequest(view, request); |
| 175 | + } |
| 176 | + |
| 177 | + } |
| 178 | + |
| 179 | + return super.shouldInterceptRequest(view, request); |
| 180 | + } |
141 | 181 | @Override |
142 | 182 | public void onPageStarted(WebView p1, String p2, Bitmap p3) { |
143 | 183 |
|
@@ -664,3 +704,4 @@ public void onDestroy() { |
664 | 704 |
|
665 | 705 |
|
666 | 706 |
|
| 707 | + |
0 commit comments