- Added file already existing handling

- Switch to Executor Service to handle only 5 SwingWorkers at a time
- Added chromedriver.exe task killer at window close
This commit is contained in:
2021-04-06 00:15:54 +02:00
parent f8dd7be711
commit 8d00ff7f90
5 changed files with 63 additions and 11 deletions

View File

@@ -37,7 +37,7 @@ public class DownloadTask extends SwingWorker<Void, Void> {
@Override
public String toString() {
return episodeWrapper.getTitle();
return episodeWrapper.getTitle()+" : " + getState();
}
/** The bytes size of the file to download */
@@ -59,37 +59,50 @@ public class DownloadTask extends SwingWorker<Void, Void> {
ConnectionUtil util = new ConnectionUtil();
util.prepare(downloadURL);
fileSize = util.getContentLength();
InputStream inputStream = util.getInputStream();
String fixedTitle = episodeWrapper.getTitle().replace(":", " ");
File outputFile = new File(SettingsRipperPanel.DOWNLOADFOLDER, fixedTitle+".mp4");
File outputShowFolder = new File(SettingsRipperPanel.DOWNLOADFOLDER, episodeWrapper.getShow());
if(!outputShowFolder.exists()){
outputShowFolder.mkdir();
}
File outputSeasonFolder = new File(outputShowFolder, episodeWrapper.getSeason());
if(!outputSeasonFolder.exists()){
outputSeasonFolder.mkdir();
}
File outputFile = new File(outputSeasonFolder, fixedTitle+".mp4");
if(outputFile.exists()){
if(outputFile.length() == fileSize){
done();
return null;
}else{
outputFile.delete();
}
}
try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;
totalBytesRead = 0;
percentCompleted = 0;
int oldPercentCompleted = 0;
fileSize = util.getContentLength();
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
percentCompleted = (int) (totalBytesRead * 100 / fileSize);
firePropertyChange(Long.toString(episodeWrapper.getId()), oldPercentCompleted, percentCompleted);
oldPercentCompleted = percentCompleted;
//setProgress(percentCompleted);
}
}
util.disconnect();
// Enable MetaDataWriter
// MetaDataWriter mdp = new MetaDataWriter();
// mdp.writeMetadata(outputFile.getAbsolutePath(), episodeWrapper.getTitle(), episodeWrapper.getShow(), episodeWrapper.getShow(), episodeWrapper.getEpisode());
} catch (IOException ex) {
cancel(true);
}