This commit is contained in:
tonikelope 2017-10-24 00:58:26 +02:00
parent f9051b1aaa
commit 2074f8b85f
13 changed files with 75 additions and 69 deletions

View File

@ -101,7 +101,7 @@ public final class ChunkWriter implements Runnable, SecureSingleThreadNotifiable
@Override
public void run() {
Chunk current_chunk;
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
try {

View File

@ -340,7 +340,7 @@ public final class CryptTools {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
@ -461,7 +461,7 @@ public final class CryptTools {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
@ -569,7 +569,7 @@ public final class CryptTools {
String enc_dlc_key;
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
while ((reads = is.read(buffer)) != -1) {

View File

@ -1042,7 +1042,7 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
long chunk_id = 1;
long tot = 0L;
byte[] chunk_buffer = new byte[16 * 1024];
byte[] chunk_buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
byte[] byte_block = new byte[16];
int[] int_block;
int re, reads, to_read;

View File

@ -20,6 +20,7 @@ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import static java.util.logging.Level.SEVERE;
import java.util.logging.Logger;
import static java.util.logging.Logger.getLogger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -41,10 +42,9 @@ import org.apache.http.impl.client.CloseableHttpClient;
public final class KissVideoStreamServer implements HttpHandler, SecureSingleThreadNotifiable {
public static final int WORKER_STATUS_FILE_INFO = 0x01;
public static final int WORKER_STATUS_CONNECT = 0x02;
public static final int WORKER_STATUS_STREAM = 0x03;
public static final int WORKER_STATUS_RETRY = 0x04;
public static final int WORKER_STATUS_EXIT = 0x05;
public static final int WORKER_STATUS_STREAM = 0x02;
public static final int WORKER_STATUS_RETRY = 0x03;
public static final int WORKER_STATUS_EXIT = 0x04;
public static final int WORKERS = 4;
private final MainPanel _main_panel;
@ -109,7 +109,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
public void start(int port, String context) throws IOException {
swingReflectionInvoke("setForeground", _main_panel.getView().getKiss_server_status(), new Color(0, 128, 0));
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), "Kissvideostreamer on localhost:" + STREAMER_PORT + " (Waiting for request...)");
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), "Stream server running on localhost:" + STREAMER_PORT + " (Waiting for request...)");
HttpServer httpserver = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), port), 0);
@ -141,10 +141,6 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
conta_info++;
break;
case WORKER_STATUS_CONNECT:
conta_connect++;
break;
case WORKER_STATUS_STREAM:
conta_stream++;
break;
@ -159,11 +155,11 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
if (conta_info > 0 || conta_connect > 0 || conta_stream > 0 || conta_retry > 0) {
status = "Kissvideostreamer on localhost:" + STREAMER_PORT + " Info: " + conta_info + " / Conn: " + conta_connect + " / Stream: " + conta_stream + " / Retry: " + conta_retry;
status = "Stream server running on localhost:" + STREAMER_PORT + " Info: " + conta_info + " / Stream: " + conta_stream + " / Retry: " + conta_retry;
} else {
status = "Kissvideostreamer on localhost:" + STREAMER_PORT + " (Waiting for request...)";
status = "Stream server running on localhost:" + STREAMER_PORT + " (Waiting for request...)";
}
swingReflectionInvoke("setText", _main_panel.getView().getKiss_server_status(), status);
@ -419,7 +415,9 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
String link;
String[] url_parts = url_path.substring(url_path.indexOf("/video/") + 7).split("#");
System.out.println(url_path.substring(url_path.indexOf("/video/") + 7));
String[] url_parts = new String(MiscTools.UrlBASE642Bin(url_path.substring(url_path.indexOf("/video/") + 7))).split("#");
mega_account = url_parts[0];
@ -427,7 +425,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
mega_account = null;
}
link = new String(MiscTools.UrlBASE642Bin(url_parts[1]));
link = new String(url_parts[1]);
HashMap cache_info, file_info;
@ -496,7 +494,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
resheaders.add("Connection", "close");
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
@ -571,8 +569,6 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
chunkwriter = new StreamChunkWriter(this, link, file_info, mega_account, pipeout, temp_url, 0, file_size - 1);
}
updateStatus(WORKER_STATUS_CONNECT);
THREAD_POOL.execute(chunkwriter);
for (int i = 0; i < WORKERS; i++) {
@ -602,7 +598,11 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
}
}
} catch (Exception ex) {
//Logger.getLogger(KissVideoStreamServer.class.getName()).log(Level.SEVERE, null, ex);
if (!(ex instanceof IOException)) {
Logger.getLogger(KissVideoStreamServer.class.getName()).log(Level.SEVERE, null, ex);
}
} finally {
System.out.println("KissVideoStreamerHandle: bye bye");

View File

@ -85,6 +85,9 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
swingReflectionInvoke("addItem", use_mega_account_down_combobox, o);
}
swingReflectionInvoke("addItem", use_mega_account_down_combobox, "");
} else {
swingReflectionInvoke("setEnabled", use_mega_account_down_combobox, false);
swingReflectionInvoke("setEnabled", use_mega_account_down_label, false);
@ -282,7 +285,7 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
@ -352,7 +355,7 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
private void use_mega_account_down_comboboxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_use_mega_account_down_comboboxItemStateChanged
String selected_item = (String) use_mega_account_down_combobox.getSelectedItem();
if (_main_panel.isUse_mega_account_down() && selected_item != null && !selected_item.equals(_last_selected_account)) {
if (_main_panel.isUse_mega_account_down() && !"".equals(selected_item) && selected_item != null && !selected_item.equals(_last_selected_account)) {
use_mega_account_down_combobox.setEnabled(false);
@ -444,6 +447,8 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
swingReflectionInvokeAndWait("setEnabled", ((LinkGrabberDialog) tthis).getDance_button(), true);
}
});
} else if(!selected_item.equals(_last_selected_account)) {
_last_selected_account=null;
}
}//GEN-LAST:event_use_mega_account_down_comboboxItemStateChanged

View File

@ -59,8 +59,9 @@ import org.apache.http.auth.UsernamePasswordCredentials;
*/
public final class MainPanel {
public static final String VERSION = "2.20";
public static final String VERSION = "2.21";
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;
public static final int WATCHDOG_PORT = 1338;
public static final int DEFAULT_MEGA_PROXY_PORT = 9999;

View File

@ -310,7 +310,7 @@ public final class MegaAPI {
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;

View File

@ -65,7 +65,7 @@ public final class MegaCrypterAPI {
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;

View File

@ -576,7 +576,7 @@ public final class MiscTools {
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
byte[] buffer = new byte[16 * 1024];
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;

View File

@ -1,4 +1,3 @@
package megabasterd;
import java.io.ByteArrayInputStream;

View File

@ -41,19 +41,13 @@ public class StreamChunkDownloader implements Runnable {
@Override
public void run() {
StreamChunk chunk_stream;
int reads, http_status;
byte[] buffer = new byte[THROTTLE_SLICE_SIZE];
InputStream is;
boolean error;
System.out.println(Thread.currentThread().getName() + " Worker [" + _id + "]: let's do some work!");
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
String url = _chunkwriter.getUrl();
error = false;
boolean error = false;
long offset = -1;
@ -77,7 +71,11 @@ public class StreamChunkDownloader implements Runnable {
if (offset >= 0) {
chunk_stream = new StreamChunk(offset, _chunkwriter.calculateChunkSize(offset), url);
int reads, http_status;
byte[] buffer = new byte[THROTTLE_SLICE_SIZE];
StreamChunk chunk_stream = new StreamChunk(offset, _chunkwriter.calculateChunkSize(offset), url);
System.out.println(Thread.currentThread().getName() + " Worker [" + _id + "]: offset: " + offset + " size: " + chunk_stream.getSize());
@ -89,7 +87,7 @@ public class StreamChunkDownloader implements Runnable {
if (!_exit) {
is = httpresponse.getEntity().getContent();
InputStream is = httpresponse.getEntity().getContent();
http_status = httpresponse.getStatusLine().getStatusCode();
@ -152,7 +150,7 @@ public class StreamChunkDownloader implements Runnable {
_chunkwriter.secureNotifyAll();
System.out.println("Worker [" + _id + "]: bye bye");
System.out.println(Thread.currentThread().getName() + " Worker [" + _id + "]: bye bye");
}
}

View File

@ -1,8 +1,3 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package megabasterd;
import java.io.IOException;
@ -80,10 +75,6 @@ public class StreamChunkWriter implements Runnable, SecureMultiThreadNotifiable
@Override
public void run() {
StreamChunk current_chunk;
byte[] buffer = new byte[16 * 1024];
int reads;
try {
System.out.println("StreamChunkWriter: let's do some work! Start: " + _start_offset + " End: " + _end_offset);
@ -92,10 +83,14 @@ public class StreamChunkWriter implements Runnable, SecureMultiThreadNotifiable
while (!_exit && _bytes_written < _end_offset && _chunk_queue.containsKey(_bytes_written)) {
current_chunk = _chunk_queue.get(_bytes_written);
StreamChunk current_chunk = _chunk_queue.get(_bytes_written);
InputStream is = current_chunk.getInputStream();
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
int reads;
while (!_exit && (reads = is.read(buffer)) != -1) {
_pipeos.write(buffer, 0, reads);
@ -132,7 +127,9 @@ public class StreamChunkWriter implements Runnable, SecureMultiThreadNotifiable
_exit = true;
System.out.println("StreamChunkWriter: bye bye");
secureNotifyAll();
System.out.println(Thread.currentThread().getName() + " StreamChunkWriter: bye bye");
}
public long nextOffset() {

View File

@ -68,6 +68,8 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
swingReflectionInvoke("addItem", use_mega_account_down_combobox, o);
}
swingReflectionInvoke("addItem", use_mega_account_down_combobox, "");
} else {
swingReflectionInvoke("setEnabled", use_mega_account_down_combobox, false);
swingReflectionInvoke("setEnabled", use_mega_account_down_label, false);
@ -207,7 +209,9 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
if (findFirstRegex("://mega(\\.co)?\\.nz/#[^fF]", link, 0) != null || findFirstRegex("https?://[^/]+/![^!]+![0-9a-fA-F]+", link, 0) != null) {
stream_link = "http://localhost:1337/video/" + (_last_selected_account != null ? _last_selected_account : "") + "#" + MiscTools.Bin2UrlBASE64(link.getBytes());
data = MiscTools.Bin2UrlBASE64(((_last_selected_account != null ? _last_selected_account : "") + "#" + link).getBytes());
stream_link = "http://localhost:1337/video/" + data;
} else {
@ -245,7 +249,7 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
private void use_mega_account_down_comboboxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_use_mega_account_down_comboboxItemStateChanged
String selected_item = (String) use_mega_account_down_combobox.getSelectedItem();
if (_main_panel.isUse_mega_account_down() && selected_item != null && !selected_item.equals(_last_selected_account)) {
if (_main_panel.isUse_mega_account_down() && !"".equals(selected_item) && selected_item != null && !selected_item.equals(_last_selected_account)) {
use_mega_account_down_combobox.setEnabled(false);
@ -337,6 +341,8 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
swingReflectionInvokeAndWait("setEnabled", ((StreamerDialog) tthis).getDance_button(), true);
}
});
} else if(!selected_item.equals(_last_selected_account)) {
_last_selected_account=null;
}
}//GEN-LAST:event_use_mega_account_down_comboboxItemStateChanged