mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-05-13 04:47:12 +02:00
2.20
This commit is contained in:
parent
f7f893c70c
commit
bafa3e916b
@ -233,7 +233,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
|
||||
return file_info;
|
||||
}
|
||||
|
||||
private String getMegaFileDownloadUrl(String link, String pass_hash, String noexpire_token, String mega_account) throws IOException, InterruptedException {
|
||||
public String getMegaFileDownloadUrl(String link, String pass_hash, String noexpire_token, String mega_account) throws IOException, InterruptedException {
|
||||
String dl_url = null;
|
||||
int retry = 0;
|
||||
boolean error;
|
||||
@ -389,11 +389,6 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
|
||||
return ranges;
|
||||
}
|
||||
|
||||
private String cookRangeUrl(String url, long[] ranges, int sync_bytes) {
|
||||
System.out.println(url + "/" + String.valueOf(ranges[0] - sync_bytes) + (ranges[1] >= 0 ? "-" + String.valueOf(ranges[1]) : ""));
|
||||
return url + "/" + String.valueOf(ranges[0] - sync_bytes) + (ranges[1] >= 0 ? "-" + String.valueOf(ranges[1]) : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(HttpExchange xchg) throws IOException {
|
||||
|
||||
@ -567,13 +562,13 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
|
||||
|
||||
xchg.sendResponseHeaders(HttpStatus.SC_PARTIAL_CONTENT, clength);
|
||||
|
||||
chunkwriter = new StreamChunkWriter(pipeout, ranges[0] - sync_bytes, ranges[1] >= 0 ? ranges[1] : file_size - 1);
|
||||
chunkwriter = new StreamChunkWriter(this, link, file_info, mega_account, pipeout, temp_url, ranges[0] - sync_bytes, ranges[1] >= 0 ? ranges[1] : file_size - 1);
|
||||
|
||||
} else {
|
||||
|
||||
xchg.sendResponseHeaders(HttpStatus.SC_OK, file_size);
|
||||
|
||||
chunkwriter = new StreamChunkWriter(pipeout, 0, file_size - 1);
|
||||
chunkwriter = new StreamChunkWriter(this, link, file_info, mega_account, pipeout, temp_url, 0, file_size - 1);
|
||||
}
|
||||
|
||||
updateStatus(WORKER_STATUS_CONNECT);
|
||||
@ -582,7 +577,7 @@ public final class KissVideoStreamServer implements HttpHandler, SecureSingleThr
|
||||
|
||||
for (int i = 0; i < WORKERS; i++) {
|
||||
|
||||
StreamChunkDownloader worker = new StreamChunkDownloader(i + 1, temp_url, chunkwriter);
|
||||
StreamChunkDownloader worker = new StreamChunkDownloader(i + 1, chunkwriter);
|
||||
|
||||
chunkworkers.add(worker);
|
||||
|
||||
|
@ -59,7 +59,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
*/
|
||||
public final class MainPanel {
|
||||
|
||||
public static final String VERSION = "2.19";
|
||||
public static final String VERSION = "2.20";
|
||||
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
||||
public static final int STREAMER_PORT = 1337;
|
||||
public static final int WATCHDOG_PORT = 1338;
|
||||
|
@ -1,8 +1,4 @@
|
||||
/*
|
||||
* 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.ByteArrayInputStream;
|
||||
@ -19,15 +15,15 @@ public final class StreamChunk {
|
||||
private final String _url;
|
||||
private final ByteArrayOutputStream _data_os;
|
||||
|
||||
public StreamChunk(long offset, long size, String file_url) throws ChunkInvalidException {
|
||||
public StreamChunk(long offset, long size, String url) throws ChunkInvalidException {
|
||||
|
||||
if (offset < 0 || size < 0) {
|
||||
if (offset < 0 || size < 0 || url == null) {
|
||||
throw new ChunkInvalidException("Offset: " + offset + " Size: " + size);
|
||||
}
|
||||
|
||||
_offset = offset;
|
||||
_size = size;
|
||||
_url = file_url != null ? file_url + "/" + _offset + "-" + (_offset + _size - 1) : null;
|
||||
_url = url + "/" + _offset + "-" + (_offset + _size - 1);
|
||||
_data_os = new ByteArrayOutputStream((int) _size);
|
||||
}
|
||||
|
||||
|
@ -26,12 +26,10 @@ public class StreamChunkDownloader implements Runnable {
|
||||
|
||||
private final int _id;
|
||||
private final StreamChunkWriter _chunkwriter;
|
||||
private final String _url;
|
||||
private volatile boolean _exit;
|
||||
|
||||
public StreamChunkDownloader(int id, String url, StreamChunkWriter chunkwriter) {
|
||||
public StreamChunkDownloader(int id, StreamChunkWriter chunkwriter) {
|
||||
_id = id;
|
||||
_url = url;
|
||||
_chunkwriter = chunkwriter;
|
||||
_exit = false;
|
||||
}
|
||||
@ -48,10 +46,12 @@ public class StreamChunkDownloader implements Runnable {
|
||||
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;
|
||||
|
||||
@ -69,11 +69,15 @@ public class StreamChunkDownloader implements Runnable {
|
||||
if (!error) {
|
||||
|
||||
offset = _chunkwriter.nextOffset();
|
||||
|
||||
} else {
|
||||
|
||||
url=_chunkwriter.getUrl();
|
||||
}
|
||||
|
||||
if (offset >= 0) {
|
||||
|
||||
chunk_stream = new StreamChunk(offset, _chunkwriter.calculateChunkSize(offset), _url);
|
||||
chunk_stream = new StreamChunk(offset, _chunkwriter.calculateChunkSize(offset), url);
|
||||
|
||||
System.out.println(Thread.currentThread().getName() + " Worker [" + _id + "]: offset: " + offset + " size: " + chunk_stream.getSize());
|
||||
|
||||
@ -142,6 +146,8 @@ public class StreamChunkDownloader implements Runnable {
|
||||
getLogger(ChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (ChunkInvalidException ex) {
|
||||
Logger.getLogger(StreamChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(StreamChunkDownloader.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
_chunkwriter.secureNotifyAll();
|
||||
|
@ -9,6 +9,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
@ -21,19 +22,28 @@ import static java.util.logging.Logger.getLogger;
|
||||
public class StreamChunkWriter implements Runnable, SecureMultiThreadNotifiable {
|
||||
|
||||
public static final int CHUNK_SIZE = 1048576;
|
||||
public static final int BUFFER_CHUNKS_SIZE = 10;
|
||||
public static final int BUFFER_CHUNKS_SIZE = 20;
|
||||
private long _next_offset_required;
|
||||
private long _bytes_written;
|
||||
private final long _start_offset;
|
||||
private final long _end_offset;
|
||||
private final String _mega_account;
|
||||
private final ConcurrentHashMap<Long, StreamChunk> _chunk_queue;
|
||||
private final ConcurrentHashMap<Thread, Boolean> _notified_threads;
|
||||
private final PipedOutputStream _pipeos;
|
||||
private String _url;
|
||||
private final HashMap _file_info;
|
||||
private final String _link;
|
||||
private final Object _secure_notify_lock;
|
||||
private final Object _chunk_offset_lock;
|
||||
private volatile boolean _exit;
|
||||
private final KissVideoStreamServer _server;
|
||||
private volatile boolean _exit;
|
||||
|
||||
public StreamChunkWriter(PipedOutputStream pipeos, long start_offset, long end_offset) {
|
||||
public StreamChunkWriter(KissVideoStreamServer server, String link, HashMap file_info, String mega_account, PipedOutputStream pipeos, String url, long start_offset, long end_offset) {
|
||||
_server=server;
|
||||
_link=link;
|
||||
_mega_account=mega_account;
|
||||
_file_info=file_info;
|
||||
_bytes_written = start_offset;
|
||||
_pipeos = pipeos;
|
||||
_start_offset = start_offset;
|
||||
@ -43,9 +53,22 @@ public class StreamChunkWriter implements Runnable, SecureMultiThreadNotifiable
|
||||
_notified_threads = new ConcurrentHashMap<>();
|
||||
_secure_notify_lock = new Object();
|
||||
_chunk_offset_lock = new Object();
|
||||
_url=url;
|
||||
_exit = false;
|
||||
}
|
||||
|
||||
public String getUrl() throws IOException, InterruptedException {
|
||||
|
||||
if(!MiscTools.checkMegaDownloadUrl(_url)) {
|
||||
|
||||
_url = _server.getMegaFileDownloadUrl(_link, (String)_file_info.get("pass_hash"), (String)_file_info.get("noexpiretoken"), _mega_account);
|
||||
_file_info.put("url", _url);
|
||||
_server.getLink_cache().put(_link, _file_info);
|
||||
}
|
||||
|
||||
return _url;
|
||||
}
|
||||
|
||||
public boolean isExit() {
|
||||
return _exit;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user