parent
6f03a1323d
commit
069b641b04
@ -1,58 +0,0 @@ |
||||
package com.github.catvod.ui; |
||||
|
||||
import android.content.Context; |
||||
import android.graphics.Rect; |
||||
import android.text.TextPaint; |
||||
import android.util.AttributeSet; |
||||
import android.view.animation.LinearInterpolator; |
||||
import android.widget.Scroller; |
||||
import android.widget.TextView; |
||||
|
||||
public class ScrollTextView extends TextView { |
||||
|
||||
private final Scroller scroller; |
||||
private int duration; |
||||
|
||||
public ScrollTextView(Context context) { |
||||
this(context, null); |
||||
} |
||||
|
||||
public ScrollTextView(Context context, AttributeSet attrs) { |
||||
this(context, attrs, android.R.attr.textViewStyle); |
||||
} |
||||
|
||||
public ScrollTextView(Context context, AttributeSet attrs, int defStyle) { |
||||
super(context, attrs, defStyle); |
||||
setSingleLine(); |
||||
setEllipsize(null); |
||||
setHorizontallyScrolling(true); |
||||
setScroller(scroller = new Scroller(getContext(), new LinearInterpolator())); |
||||
} |
||||
|
||||
public void setDuration(int duration) { |
||||
this.duration = duration; |
||||
} |
||||
|
||||
public void startScroll() { |
||||
scroller.startScroll(-getWidth(), 0, calculateScrollingLen(), 0, duration * 1000); |
||||
} |
||||
|
||||
public void stopScroll() { |
||||
if (scroller != null) scroller.abortAnimation(); |
||||
setVisibility(GONE); |
||||
} |
||||
|
||||
private int calculateScrollingLen() { |
||||
TextPaint paint = getPaint(); |
||||
Rect rect = new Rect(); |
||||
String text = getText().toString(); |
||||
paint.getTextBounds(text, 0, text.length(), rect); |
||||
return rect.width() + getWidth(); |
||||
} |
||||
|
||||
@Override |
||||
public void computeScroll() { |
||||
super.computeScroll(); |
||||
if (scroller != null && scroller.isFinished()) stopScroll(); |
||||
} |
||||
} |
||||
@ -1,84 +0,0 @@ |
||||
package com.github.catvod.utils; |
||||
|
||||
import android.os.SystemClock; |
||||
import android.text.TextUtils; |
||||
|
||||
import com.github.catvod.net.OkHttp; |
||||
import com.github.catvod.spider.Proxy; |
||||
|
||||
import org.json.JSONObject; |
||||
|
||||
import java.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
|
||||
import okhttp3.Response; |
||||
|
||||
public class ProxyVideo { |
||||
|
||||
private static final String GO_SERVER = "http://127.0.0.1:7777/"; |
||||
|
||||
public static void go() { |
||||
boolean close = OkHttp.string(GO_SERVER).isEmpty(); |
||||
if (close) OkHttp.string("http://127.0.0.1:" + Proxy.getPort() + "/go"); |
||||
if (close) while (OkHttp.string(GO_SERVER).isEmpty()) SystemClock.sleep(20); |
||||
} |
||||
|
||||
public static String goVer() { |
||||
try { |
||||
go(); |
||||
String result = OkHttp.string(GO_SERVER + "version"); |
||||
return new JSONObject(result).optString("version"); |
||||
} catch (Exception e) { |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
public static String url(String url, int thread) { |
||||
if (!TextUtils.isEmpty(goVer()) && url.contains("/proxy?")) url += "&response=url"; |
||||
return String.format(Locale.getDefault(), "%s?url=%s&thread=%d", GO_SERVER, URLEncoder.encode(url), thread); |
||||
} |
||||
|
||||
public static Object[] proxy(String url, Map<String, String> headers) throws Exception { |
||||
Response response = OkHttp.newCall(url, headers); |
||||
String contentType = response.headers().get("Content-Type"); |
||||
String contentDisposition = response.headers().get("Content-Disposition"); |
||||
if (contentDisposition != null) contentType = getMimeType(contentDisposition); |
||||
Map<String, String> respHeaders = new HashMap<>(); |
||||
for (String key : response.headers().names()) respHeaders.put(key, response.headers().get(key)); |
||||
return new Object[]{206, contentType, response.body().byteStream(), respHeaders}; |
||||
} |
||||
|
||||
private static String getMimeType(String contentDisposition) { |
||||
if (contentDisposition.endsWith(".mp4")) { |
||||
return "video/mp4"; |
||||
} else if (contentDisposition.endsWith(".webm")) { |
||||
return "video/webm"; |
||||
} else if (contentDisposition.endsWith(".avi")) { |
||||
return "video/x-msvideo"; |
||||
} else if (contentDisposition.endsWith(".wmv")) { |
||||
return "video/x-ms-wmv"; |
||||
} else if (contentDisposition.endsWith(".flv")) { |
||||
return "video/x-flv"; |
||||
} else if (contentDisposition.endsWith(".mov")) { |
||||
return "video/quicktime"; |
||||
} else if (contentDisposition.endsWith(".mkv")) { |
||||
return "video/x-matroska"; |
||||
} else if (contentDisposition.endsWith(".mpeg")) { |
||||
return "video/mpeg"; |
||||
} else if (contentDisposition.endsWith(".3gp")) { |
||||
return "video/3gpp"; |
||||
} else if (contentDisposition.endsWith(".ts")) { |
||||
return "video/MP2T"; |
||||
} else if (contentDisposition.endsWith(".mp3")) { |
||||
return "audio/mp3"; |
||||
} else if (contentDisposition.endsWith(".wav")) { |
||||
return "audio/wav"; |
||||
} else if (contentDisposition.endsWith(".aac")) { |
||||
return "audio/aac"; |
||||
} else { |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
Binary file not shown.
@ -1 +1 @@ |
||||
41d830d74afd5a31464b2f6678cd3f2e |
||||
3cbe660633a395f10a0ae0ee543e935a |
||||
|
||||
Loading…
Reference in new issue