mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-05-14 21:37:12 +02:00
3.91
-SmartProxy -KissVideoStreamer
This commit is contained in:
parent
7eda408971
commit
8db9050e1a
@ -37,6 +37,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
|
||||
|
||||
public static final int THREAD_START = 0x01;
|
||||
public static final int THREAD_STOP = 0x02;
|
||||
public static final int DEFAULT_WORKERS = 10;
|
||||
|
||||
private final MainPanel _main_panel;
|
||||
private final ConcurrentHashMap<String, HashMap<String, Object>> _link_cache;
|
||||
@ -436,7 +437,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
|
||||
|
||||
THREAD_POOL.execute(chunkwriter);
|
||||
|
||||
for (int i = 0; i < StreamChunkWriter.BUFFER_CHUNKS_SIZE; i++) {
|
||||
for (int i = 0; i < DEFAULT_WORKERS; i++) {
|
||||
|
||||
StreamChunkDownloader worker = new StreamChunkDownloader(i + 1, chunkwriter);
|
||||
|
||||
|
@ -48,7 +48,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
*/
|
||||
public final class MainPanel {
|
||||
|
||||
public static final String VERSION = "3.9";
|
||||
public static final String VERSION = "3.91";
|
||||
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
||||
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
|
||||
public static final int STREAMER_PORT = 1337;
|
||||
|
@ -854,8 +854,8 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
MainPanel.getProxy_manager().setExit(true);
|
||||
|
||||
synchronized (MainPanel.getProxy_manager().getRefresh_lock()) {
|
||||
MainPanel.getProxy_manager().getRefresh_lock().notify();
|
||||
synchronized (MainPanel.getProxy_manager()) {
|
||||
MainPanel.getProxy_manager().notify();
|
||||
}
|
||||
|
||||
this.getMain_panel().setProxy_manager(null);
|
||||
|
@ -6,12 +6,13 @@ import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import static com.tonikelope.megabasterd.MainPanel.THREAD_POOL;
|
||||
import static com.tonikelope.megabasterd.MiscTools.getApacheKissHttpClient;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
@ -23,19 +24,20 @@ import org.apache.http.impl.client.CloseableHttpClient;
|
||||
public class SmartMegaProxyManager implements Runnable {
|
||||
|
||||
public static final int PROXY_TIMEOUT = 30;
|
||||
public static final int REFRESH_PROXY_LIST_TIMEOUT = 1800;
|
||||
public static final int PROXY_MAX_EXCLUDE_COUNTER = 5;
|
||||
public static final int PROXY_EXCLUDE_SECS = 10;
|
||||
private volatile String _proxy_list_url;
|
||||
private final ConcurrentLinkedQueue<String> _proxy_list;
|
||||
private final ConcurrentHashMap<String, HashMap> _proxy_info;
|
||||
private final MainPanel _main_panel;
|
||||
private volatile boolean _exit;
|
||||
private final Object _refresh_lock;
|
||||
|
||||
public SmartMegaProxyManager(MainPanel main_panel, String proxy_list_url) {
|
||||
_main_panel = main_panel;
|
||||
_proxy_list_url = proxy_list_url;
|
||||
_proxy_list = new ConcurrentLinkedQueue<>();
|
||||
_proxy_info = new ConcurrentHashMap<>();
|
||||
_exit = false;
|
||||
_refresh_lock = new Object();
|
||||
}
|
||||
|
||||
public String getProxy_list_url() {
|
||||
@ -54,38 +56,51 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
synchronized (_refresh_lock) {
|
||||
|
||||
_refreshProxyList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Object getRefresh_lock() {
|
||||
return _refresh_lock;
|
||||
}
|
||||
|
||||
public String getFastestProxy() {
|
||||
|
||||
return _proxy_list.peek();
|
||||
for (String proxy : _proxy_list) {
|
||||
|
||||
HashMap<String, Object> proxy_info = (HashMap<String, Object>) _proxy_info.get(proxy);
|
||||
|
||||
Long extimestamp = (Long) proxy_info.get("extimestamp");
|
||||
|
||||
if (extimestamp == null || extimestamp + PROXY_EXCLUDE_SECS * 1000 < System.currentTimeMillis()) {
|
||||
|
||||
return proxy;
|
||||
|
||||
} else {
|
||||
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy is temporary excluded -> {1}", new Object[]{Thread.currentThread().getName(), proxy});
|
||||
}
|
||||
}
|
||||
|
||||
public String getRandomProxy() {
|
||||
|
||||
synchronized (_refresh_lock) {
|
||||
return _proxy_list.toArray(new String[_proxy_list.size()])[(new Random()).nextInt(_proxy_list.size())];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void excludeProxy(String proxy) {
|
||||
|
||||
if (_proxy_list.contains(proxy)) {
|
||||
if (_proxy_info.containsKey(proxy)) {
|
||||
|
||||
synchronized (_refresh_lock) {
|
||||
HashMap<String, Object> proxy_info = (HashMap<String, Object>) _proxy_info.get(proxy);
|
||||
|
||||
int excount = (int) proxy_info.get("excount") + 1;
|
||||
|
||||
if (excount < PROXY_MAX_EXCLUDE_COUNTER) {
|
||||
|
||||
proxy_info.put("excount", excount);
|
||||
|
||||
proxy_info.put("extimestamp", System.currentTimeMillis());
|
||||
|
||||
} else {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy removed -> {1}", new Object[]{Thread.currentThread().getName(), proxy});
|
||||
|
||||
_proxy_list.remove(proxy);
|
||||
}
|
||||
_proxy_info.remove(proxy);
|
||||
|
||||
_main_panel.getView().updateSmartProxyStatus("SmartProxy: " + _proxy_list.size());
|
||||
|
||||
@ -95,15 +110,13 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
synchronized (_refresh_lock) {
|
||||
|
||||
_refreshProxyList();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void _refreshProxyList() {
|
||||
|
||||
@ -139,11 +152,16 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
if (proxy_list.length > 0) {
|
||||
|
||||
_proxy_list.clear();
|
||||
_proxy_info.clear();
|
||||
|
||||
for (String proxy : proxy_list) {
|
||||
|
||||
if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
|
||||
this._proxy_list.add(proxy);
|
||||
_proxy_list.add(proxy);
|
||||
HashMap<String, Object> proxy_info = new HashMap<>();
|
||||
proxy_info.put("extimestamp", null);
|
||||
proxy_info.put("excount", 0);
|
||||
_proxy_info.put(proxy.trim(), proxy_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,19 +185,20 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
|
||||
_main_panel.getView().updateSmartProxyStatus("");
|
||||
|
||||
while (!_exit) {
|
||||
this._refreshProxyList();
|
||||
|
||||
synchronized (_refresh_lock) {
|
||||
while (!_exit) {
|
||||
|
||||
this._refreshProxyList();
|
||||
|
||||
try {
|
||||
_refresh_lock.wait(1000 * REFRESH_PROXY_LIST_TIMEOUT);
|
||||
synchronized (this) {
|
||||
wait();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_main_panel.getView().updateSmartProxyStatus("");
|
||||
|
||||
|
@ -16,8 +16,8 @@ import static com.tonikelope.megabasterd.MiscTools.*;
|
||||
*/
|
||||
public class StreamChunkWriter implements Runnable, SecureMultiThreadNotifiable {
|
||||
|
||||
public static final int CHUNK_SIZE = 10485760; //10 MB
|
||||
public static final int BUFFER_CHUNKS_SIZE = 4;
|
||||
public static final int CHUNK_SIZE = 1048576;
|
||||
public static final int BUFFER_CHUNKS_SIZE = 20;
|
||||
private long _next_offset_required;
|
||||
private long _bytes_written;
|
||||
private final long _start_offset;
|
||||
|
Loading…
x
Reference in New Issue
Block a user