Compare commits

...
26 Commits
Author SHA1 Message Date
death-claw 4107048f12 v3.0.9 2020-09-27 10:14:08 +01:00
death-claw f5d9ab85a2 Revert to appending post id to download folders
Fix a bug that lead to adding duplicate posts
Remove old unused settings
2020-09-27 10:12:29 +01:00
death-claw b82ee7b494 v3.0.8 2020-08-22 19:01:08 +01:00
death-claw 8a31dfc012 Bug fix which breaks concurrent downloads 2020-08-22 18:59:44 +01:00
death-claw 734c1b72c7 v3.0.7 2020-08-22 16:45:43 +01:00
death-claw 7abb7df1f6 Fix MacOs build 2020-08-22 16:44:24 +01:00
death-claw 0a7fa99a64 v3.0.6 2020-08-18 08:33:57 +01:00
death-claw 691026c8a9 Fix TurboImageHost 2020-08-18 08:32:33 +01:00
death-claw 3ef004b947 v3.0.5 2020-08-17 20:06:12 +01:00
death-claw 1b22a93e28 Update packages
Host class refactoring
2020-08-17 20:04:39 +01:00
death-claw 2639df0aaa Update packages
Host class refactoring
2020-08-17 20:04:23 +01:00
death-claw d5ae5d57d1 v3.0.4 2020-08-16 16:11:11 +01:00
death-claw 537d76d7be Improve rename UI 2020-08-16 16:06:17 +01:00
death-claw c1247faacc v3.0.3 2020-08-16 11:29:01 +01:00
death-claw efcc685f30 Remove notification feature 2020-08-16 11:26:57 +01:00
death-claw c825b22ce4 Fix some bugs with MacOS 2020-08-16 10:58:19 +01:00
death-claw 6ef5d5474f Fix some bugs with MacOS 2020-08-16 10:20:56 +01:00
death-claw bd25801c6c Fix base dir configuration for MacOS 2020-08-16 00:18:18 +01:00
death-claw 377b93c1ac Fix base dir configuration for AppImage 2020-08-16 00:02:18 +01:00
death-claw d498d20f6b Set default download path to user's home 2020-08-15 23:23:43 +01:00
death-claw d18544d414 Fix bin location for mac 2020-08-15 23:10:58 +01:00
death-claw 3c872b79bd Update app data configuration 2020-08-15 23:00:48 +01:00
death-claw 37900cac49 v3.0.2 2020-08-15 15:38:53 +01:00
death-claw be57c76d93 Fix bugs with download queue 2020-08-15 15:36:47 +01:00
death-claw 8b52ad7858 v3.0.1 2020-08-03 18:48:45 +01:00
death-claw a0976bde02 Fix bugs with download queue 2020-08-03 18:43:42 +01:00
67 changed files with 1506 additions and 1347 deletions
+39
View File
@@ -1,5 +1,44 @@
# Changelog
## [3.0.9] - 2020-09-27
### Changed
- Revert to appending post id to download folders
- Fix a bug that lead to adding duplicate posts
- Remove old unused settings
## [3.0.8] - 2020-08-22
### Changed
- Bug fix which breaks concurrent downloads
## [3.0.7] - 2020-08-22
### Changed
- Fix MacOs build
## [3.0.6] - 2020-08-18
### Changed
- Fix TurboImageHost
## [3.0.5] - 2020-08-17
### Changed
- Update packages
- Host class refactoring
## [3.0.4] - 2020-08-16
### Changed
- Improve rename UI
## [3.0.3] - 2020-08-16
### Changed
- Fix bugs with electron app
## [3.0.2] - 2020-08-15
### Changed
- Fix bugs with download queue
## [3.0.1] - 2020-08-03
### Changed
- Fix bugs with download queue
## [3.0.0] - 2020-08-03
### Changed
- Major rewrites
+1 -1
View File
@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.0.0</version>
<version>3.0.9</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
+63 -50
View File
@@ -1,13 +1,16 @@
require('v8-compile-cache');
const { app, BrowserWindow } = require("electron");
const {app, BrowserWindow} = require("electron");
const path = require("path");
const url = require("url");
const getPort = require("get-port");
const { spawn } = require("child_process");
const { ipcMain } = require("electron");
const { dialog } = require("electron");
const {spawn} = require("child_process");
const {ipcMain} = require("electron");
const {dialog} = require("electron");
const axios = require('axios');
const appDir = process.env.APPDIR;
// non null value when it is an AppImage
const appImageDir = process.env.APPDIR;
const appImagePath = process.env.APPIMAGE;
let win;
let vripperServer;
@@ -23,14 +26,14 @@ process.on("uncaughtException", err => {
process.exit(1);
});
function createWindow() {
createWindow = () => {
if (process.platform === 'win32') {
app.setAppUserModelId("tn.mnlr.vripper");
}
let icon;
if(process.platform === "win32") {
if (process.platform === "win32") {
icon = __dirname + '/icon.ico';
} else {
icon = __dirname + '/icon.png';
@@ -66,6 +69,33 @@ function createWindow() {
});
}
shutdownServer = () => {
axios.post('http://localhost:' + serverPort + '/actuator/shutdown', {}, {
headers: {'content-type': 'application/json'},
}).then((response) => {
terminationInteval = setInterval(() => {
terminationAttemps++;
if (terminated) {
console.log('viper server terminated');
clearInterval(terminationInteval);
app.quit();
} else if (terminationAttemps > maxTerminationAttemps) {
console.log('viper server is not terminated');
console.log('Proceed to kill');
vripperServer.kill('SIGKILL');
clearInterval(terminationInteval);
app.quit();
}
}, 1000);
}).catch((error) => {
// Terminate immediately
console.log(error);
vripperServer.kill('SIGKILL');
terminated = true;
app.quit();
});
}
const gotTheLock = app.requestSingleInstanceLock();
if (!gotTheLock) {
@@ -76,29 +106,30 @@ if (!gotTheLock) {
ipcMain.on("get-port", event => {
event.reply("port", port);
});
let javaBinPath;
if(appDir !== undefined) {
javaBinPath = path.join(appDir, "java-runtime/bin/java");
const appPath = path.join(app.getAppPath(), '../../');
let javaBinPath, jarPath, baseDir;
if (appImageDir !== undefined && process.platform === 'linux') {
javaBinPath = path.join(appImageDir, "java-runtime/bin/java");
jarPath = path.join(appImageDir, "bin/vripper-server.jar");
baseDir = path.join(appImagePath, '..');
} else if (process.platform === 'darwin') {
javaBinPath = path.join(appPath, "java-runtime/bin/java");
jarPath = path.join(appPath, "bin/vripper-server.jar");
baseDir = app.getPath('appData');
} else if (process.platform === 'win32') {
javaBinPath = path.join(appPath, "java-runtime/bin/java");
jarPath = path.join(appPath, "bin/vripper-server.jar");
baseDir = appPath;
} else {
if(process.platform === 'darwin') {
javaBinPath = path.join(app.getPath('exe'), "../../java-runtime/bin/java");
} else {
javaBinPath = path.join(app.getPath('exe'), "../java-runtime/bin/java");
}
}
let jarPath;
if(appDir !== undefined) {
jarPath = path.join(appDir, "bin/vripper-server.jar");
} else {
if(process.platform === 'darwin') {
jarPath = path.join(app.getPath('exe'), "../../bin/vripper-server.jar");
} else {
jarPath = path.join(app.getPath('exe'), "../bin/vripper-server.jar");
}
console.error(`Unknown platform ${process.platform}`);
app.quit();
}
vripperServer = spawn(javaBinPath, [
"-Xms256m",
"-Dvripper.server.port=" + port,
"-Dbase.dir=" + baseDir,
"-jar",
jarPath
], {
@@ -122,31 +153,13 @@ if (!gotTheLock) {
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
axios.post('http://localhost:' + serverPort + '/actuator/shutdown', {}, {
headers: { 'content-type': 'application/json' },
}).then((response) => {
terminationInteval= setInterval(() => {
terminationAttemps++;
if(terminated) {
console.log('viper server terminated');
clearInterval(terminationInteval);
app.quit();
} else if(terminationAttemps > maxTerminationAttemps) {
console.log('viper server is not terminated');
console.log('Proceed to kill');
vripperServer.kill('SIGKILL');
clearInterval(terminationInteval);
app.quit();
}
}, 1000);
})
.catch((error) => {
// Terminate immediately
console.log(error);
vripperServer.kill('SIGKILL');
terminated = true;
app.quit();
});
shutdownServer();
}
});
app.on("will-quit", () => {
if (process.platform === "darwin") {
shutdownServer();
}
});
+4 -4
View File
@@ -1,6 +1,6 @@
{
"name": "vripper-electron",
"version": "3.0.0",
"version": "3.0.9",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -1578,9 +1578,9 @@
}
},
"lodash": {
"version": "4.17.15",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
"version": "4.17.20",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz",
"integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA=="
},
"lowercase-keys": {
"version": "1.0.1",
+2 -7
View File
@@ -1,6 +1,6 @@
{
"name": "vripper-electron",
"version": "3.0.0",
"version": "3.0.9",
"description": "A ripper for vipergirls.to built using web technolgies",
"main": "main.js",
"author": "death-claw <53543762+death-claw@users.noreply.github.com>",
@@ -40,14 +40,9 @@
"win": {
"icon": "icon.ico",
"target": [
"nsis"
"dir"
]
},
"nsis": {
"createDesktopShortcut": "always",
"oneClick": false,
"perMachine": false
},
"linux": {
"synopsis": "vipergirls.to ripper",
"category": "Utility",
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.0.0</version>
<version>3.0.9</version>
</parent>
<artifactId>vripper-electron</artifactId>
<name>vripper-electron</name>
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.0.0</version>
<version>3.0.9</version>
</parent>
<artifactId>vripper-server</artifactId>
<name>vripper-server</name>
@@ -6,17 +6,14 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
@SpringBootApplication
@Slf4j
public class VripperApplication {
public static final RetryPolicy<Object> retryPolicy = new RetryPolicy<>()
.handleIf(e -> !(e instanceof InterruptedException))
.withDelay(1, 3, ChronoUnit.SECONDS)
.withMaxAttempts(5)
.abortOn(Collections.singletonList(InterruptedException.class))
.onFailedAttempt(e -> log.warn(String.format("#%d tries failed", e.getAttemptCount()), e.getLastFailure()));
public static void main(String[] args) {
@@ -27,6 +24,5 @@ public class VripperApplication {
log.error("Failed to run the application", e);
}
}
}
@@ -15,8 +15,10 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.HtmlProcessorService;
import tn.mnlr.vripper.services.XpathService;
import java.util.ArrayList;
import java.util.List;
@@ -29,11 +31,18 @@ public class AcidimgHost extends Host {
private static final String CONTINUE_BUTTON_XPATH = "//input[@id='continuebutton']";
private static final String IMG_XPATH = "//img[@class='centred']";
@Autowired
private ConnectionManager cm;
private final ConnectionManager cm;
private final HostService hostService;
private final XpathService xpathService;
private final HtmlProcessorService htmlProcessorService;
public AcidimgHost() {
super();
@Autowired
public AcidimgHost(ConnectionManager cm, HostService hostService, XpathService xpathService, HtmlProcessorService htmlProcessorService) {
this.cm = cm;
this.hostService = hostService;
this.xpathService = xpathService;
this.htmlProcessorService = htmlProcessorService;
}
@Override
@@ -47,9 +56,9 @@ public class AcidimgHost extends Host {
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
Node contDiv;
try {
@@ -62,7 +71,7 @@ public class AcidimgHost extends Host {
if (contDiv != null) {
log.debug(String.format("Click button found for %s", url));
HttpClient client = cm.getClient().build();
HttpPost httpPost = cm.buildHttpPost(url);
HttpPost httpPost = cm.buildHttpPost(url, context);
httpPost.addHeader("Referer", url);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("imgContinue", "Continue to your image"));
@@ -99,8 +108,7 @@ public class AcidimgHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? getDefaultImageName(imgUrl) : imgTitle);
return new HostService.NameUrl(imgTitle.isEmpty() ? hostService.getDefaultImageName(imgUrl) : imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -1,76 +1,17 @@
package tn.mnlr.vripper.host;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.HtmlProcessorException;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.*;
import tn.mnlr.vripper.services.HostService;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Iterator;
import java.util.Objects;
@Service
@Slf4j
abstract public class Host {
private static final int READ_BUFFER_SIZE = 8192;
private static final Byte LOCK = 0;
@Autowired
protected HtmlProcessorService htmlProcessorService;
@Autowired
protected XpathService xpathService;
@Autowired
private AppSettingsService appSettingsService;
@Autowired
private DataService dataService;
@Autowired
private ConnectionManager cm;
@Autowired
private DownloadSpeedService downloadSpeedService;
@Autowired
private PathService pathService;
@Autowired
private VipergirlsAuthService authService;
protected Host() {
}
abstract public String getHost();
abstract public String getLookup();
@@ -79,204 +20,7 @@ abstract public class Host {
return url.contains(getLookup());
}
public void download(final Post post, final Image image, final ImageFileData imageFileData) throws DownloadException, InterruptedException {
image.setStatus(Status.DOWNLOADING);
image.setCurrent(0);
dataService.updateImageStatus(image.getStatus(), image.getId());
dataService.updateImageCurrent(image.getCurrent(), image.getId());
HttpClientContext context = HttpClientContext.create();
context.setCookieStore(new BasicCookieStore());
try {
synchronized (LOCK) {
if (!post.getStatus().equals(Status.DOWNLOADING) && !post.getStatus().equals(Status.PARTIAL)) {
post.setStatus(Status.DOWNLOADING);
dataService.updatePostStatus(post.getStatus(), post.getId());
}
}
imageFileData.setPageUrl(image.getUrl());
/*
* HOST SPECIFIC
*/
log.debug(String.format("Getting image url and name from %s using %s", image.getUrl(), this.getHost()));
setNameAndUrl(image.getUrl(), imageFileData, context);
log.debug(String.format("Resolved name for %s: %s", image.getUrl(), imageFileData.getImageName()));
log.debug(String.format("Resolved image url for %s: %s", image.getUrl(), imageFileData.getImageUrl()));
log.debug(String.format("Building image request for %s", image.getUrl()));
setImageRequest(imageFileData);
/*
* END HOST SPECIFIC
*/
String formatImageFileName = pathService.formatImageFileName(imageFileData.getImageName());
log.debug(String.format("Sanitizing image name from %s to %s", imageFileData.getImageName(), formatImageFileName));
imageFileData.setImageName(formatImageFileName);
HttpClient client = cm.getClient().build();
log.debug(String.format("Downloading %s", imageFileData.getImageUrl()));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(imageFileData.getImageRequest(), context)) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
EntityUtils.consumeQuietly(response.getEntity());
throw new DownloadException(String.format("Server returned code %d", response.getStatusLine().getStatusCode()));
}
File destinationFolder;
synchronized (LOCK) {
if (post.getPostFolderName() == null) {
pathService.createDefaultPostFolder(post);
}
destinationFolder = pathService.getDownloadDestinationFolder(post);
authService.leaveThanks(post);
}
File outputFile = new File(destinationFolder.getPath() + File.separator + String.format("%03d_", image.getIndex()) + imageFileData.getImageName() + ".tmp");
try (InputStream downloadStream = response.getEntity().getContent(); FileOutputStream fos = new FileOutputStream(outputFile)) {
image.setTotal(response.getEntity().getContentLength());
dataService.updateImageTotal(image.getTotal(), image.getId());
log.debug(String.format("%s length is %d", imageFileData.getImageUrl(), image.getTotal()));
log.debug(String.format("Starting data transfer for %s", imageFileData.getImageUrl()));
byte[] buffer = new byte[READ_BUFFER_SIZE];
int read;
while ((read = downloadStream.read(buffer, 0, READ_BUFFER_SIZE)) != -1) {
fos.write(buffer, 0, read);
image.increase(read);
downloadSpeedService.increase(read);
dataService.updateImageCurrent(image.getCurrent(), image.getId());
}
fos.flush();
EntityUtils.consumeQuietly(response.getEntity());
} finally {
if (image.getCurrent() == image.getTotal()) {
image.setStatus(Status.COMPLETE);
} else {
image.setStatus(Status.ERROR);
}
dataService.updateImageStatus(image.getStatus(), image.getId());
}
File finalName = checkImageTypeAndRename(post, outputFile, imageFileData.getImageName(), image.getIndex());
imageFileData.setFileName(finalName.getName());
}
} catch (Exception e) {
if (Thread.interrupted() || imageFileData.getImageRequest().isAborted()) {
throw new InterruptedException("Download was interrupted");
}
throw new DownloadException(e);
}
}
private File checkImageTypeAndRename(Post post, File outputFile, String imageName, int index) throws HostException {
try (ImageInputStream iis = ImageIO.createImageInputStream(outputFile)) {
Iterator<ImageReader> it = ImageIO.getImageReaders(iis);
if (!it.hasNext()) {
throw new HostException("Image file is not recognized!");
}
ImageReader reader = it.next();
if (reader.getFormatName().toUpperCase().equals("JPEG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_jpg") && !imageNameLC.endsWith("_jpeg")) {
imageName += ".jpg";
} else {
String toReplace = null;
if (imageNameLC.endsWith("_jpg")) {
toReplace = "_jpg";
} else if (imageNameLC.endsWith("_jpeg")) {
toReplace = "_jpeg";
}
if (toReplace != null) {
imageName = imageName.substring(0, imageName.length() - toReplace.length()) + ".jpg";
}
}
} else if (reader.getFormatName().toUpperCase().equals("PNG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_png")) {
imageName += ".png";
} else {
String toReplace = null;
if (imageNameLC.endsWith("_png")) {
toReplace = "_png";
}
if (toReplace != null) {
imageName = imageName.substring(0, imageName.length() - toReplace.length()) + ".png";
}
}
}
} catch (Exception e) {
throw new HostException("Failed to guess image format", e);
}
try {
File downloadDestinationFolder = pathService.getDownloadDestinationFolder(post);
File outImage = new File(downloadDestinationFolder, (appSettingsService.getSettings().getForceOrder() ? String.format("%03d_", index) : "") + imageName);
if (outImage.exists() && outImage.delete()) {
log.debug(String.format("%s is deleted", outImage.toString()));
}
return Files.move(outputFile.toPath(), outImage.toPath(), StandardCopyOption.ATOMIC_MOVE).toFile();
} catch (Exception e) {
throw new HostException("Failed to rename the image", e);
}
}
final String getDefaultImageName(final String imgUrl) {
String imageTitle = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
log.debug(String.format("Extracting name from url %s: %s", imgUrl, imageTitle));
return imgUrl;
}
final Response getResponse(final String url, final HttpClientContext context) throws HostException {
String basePage;
HttpClient client = cm.getClient().build();
HttpGet httpGet = cm.buildHttpGet(url);
Header[] headers;
log.debug(String.format("Requesting %s", url));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpGet, context)) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new HostException(String.format("Unexpected response code: %d", response.getStatusLine().getStatusCode()));
}
headers = response.getAllHeaders();
basePage = EntityUtils.toString(response.getEntity());
log.debug(String.format("%s response: %n%s", url, basePage));
EntityUtils.consumeQuietly(response.getEntity());
} catch (IOException e) {
throw new HostException(e);
}
try {
log.debug(String.format("Cleaning %s response", url));
return new Response(htmlProcessorService.clean(basePage), headers);
} catch (HtmlProcessorException e) {
throw new HostException(e);
}
}
protected String appendUri(String uri, String appendQuery) throws URISyntaxException {
URI oldUri = new URI(uri);
String newQuery = oldUri.getQuery();
if (newQuery == null) {
newQuery = appendQuery;
} else {
newQuery += "&" + appendQuery;
}
return new URI(oldUri.getScheme(), oldUri.getAuthority(),
oldUri.getPath(), newQuery, oldUri.getFragment()).toString();
}
private void setImageRequest(final ImageFileData imageFileData) {
HttpGet httpGet = cm.buildHttpGet(imageFileData.getImageUrl());
httpGet.addHeader("Referer", imageFileData.getPageUrl());
imageFileData.setImageRequest(httpGet);
}
protected abstract void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException;
public abstract HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException;
@Override
public boolean equals(Object o) {
@@ -291,18 +35,6 @@ abstract public class Host {
return Objects.hash(getHost());
}
@Getter
public static class Response {
protected Response(Document document, Header[] headers) {
this.document = document;
this.headers = headers;
}
private Document document;
private Header[] headers;
}
@Override
public String toString() {
return getHost();
@@ -13,8 +13,10 @@ import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.HtmlProcessorException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.HtmlProcessorService;
import tn.mnlr.vripper.services.XpathService;
import java.io.IOException;
@@ -26,11 +28,17 @@ public class ImageBamHost extends Host {
private static final String CONTINUE_BUTTON_XPATH = "//a[@title='Continue to your image']";
private static final String IMG_XPATH = "//img[@class='image']";
@Autowired
private ConnectionManager cm;
private final HostService hostService;
private final ConnectionManager cm;
private final XpathService xpathService;
private final HtmlProcessorService htmlProcessorService;
public ImageBamHost() {
super();
@Autowired
public ImageBamHost(HostService hostService, ConnectionManager cm, XpathService xpathService, HtmlProcessorService htmlProcessorService) {
this.hostService = hostService;
this.cm = cm;
this.xpathService = xpathService;
this.htmlProcessorService = htmlProcessorService;
}
@Override
@@ -44,9 +52,9 @@ public class ImageBamHost extends Host {
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException {
Response response = getResponse(url, context);
HostService.Response response = hostService.getResponse(url, context);
Document doc = response.getDocument();
Node contDiv;
@@ -60,7 +68,7 @@ public class ImageBamHost extends Host {
if (contDiv != null) {
log.debug(String.format("Click button found for %s", url));
HttpClient client = cm.getClient().build();
HttpGet httpGet = cm.buildHttpGet(url);
HttpGet httpGet = cm.buildHttpGet(url, context);
httpGet.addHeader("Referer", url);
log.debug(String.format("Requesting %s", httpGet));
try (CloseableHttpResponse res = (CloseableHttpResponse) client.execute(httpGet, context)) {
@@ -87,8 +95,7 @@ public class ImageBamHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("id").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
return new HostService.NameUrl(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
import java.util.Optional;
@@ -18,8 +20,13 @@ public class ImageTwistHost extends Host {
private static final String IMG_XPATH = "//img[contains(@class, 'img')]";
private static final String host = "imagetwist.com";
public ImageTwistHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public ImageTwistHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -33,9 +40,9 @@ public class ImageTwistHost extends Host {
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
Node imgNode;
try {
@@ -50,8 +57,7 @@ public class ImageTwistHost extends Host {
String imgTitle = Optional.ofNullable(imgNode.getAttributes().getNamedItem("alt")).map(Node::getTextContent).map(String::trim).orElse(null);
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle);
return new HostService.NameUrl(imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -17,8 +19,13 @@ public class ImageVenueHost extends Host {
private static final String CONTINUE_BUTTON_XPATH = "//a[@title='Continue to ImageVenue']";
private static final String IMG_XPATH = "//a[@data-toggle='full']/img";
public ImageVenueHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public ImageVenueHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -32,18 +39,18 @@ public class ImageVenueHost extends Host {
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String _url, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Response resp = getResponse(url, context);
HostService.Response resp = hostService.getResponse(url, context);
Document doc = resp.getDocument();
try {
log.debug(String.format("Looking for xpath expression %s in %s", CONTINUE_BUTTON_XPATH, url));
if (xpathService.getAsNode(doc, CONTINUE_BUTTON_XPATH) != null) {
//Button detected. No need to actually click it, just make the call again.
resp = getResponse(url, context);
resp = hostService.getResponse(url, context);
doc = resp.getDocument();
}
} catch (XpathException e) {
@@ -67,8 +74,7 @@ public class ImageVenueHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
return new HostService.NameUrl(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -17,8 +19,13 @@ public class ImageZillaHost extends Host {
private static final String lookup = "imagezilla.net/show";
private static final String IMG_XPATH = "//img[@id='photo']";
public ImageZillaHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public ImageZillaHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -32,9 +39,9 @@ public class ImageZillaHost extends Host {
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
String title;
try {
@@ -51,12 +58,11 @@ public class ImageZillaHost extends Host {
}
if (title == null || title.isEmpty()) {
title = getDefaultImageName(url);
title = hostService.getDefaultImageName(url);
}
try {
imageFileData.setImageUrl(url.replace("show", "images"));
imageFileData.setImageName(title);
return new HostService.NameUrl(title, url.replace("show", "images"));
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -16,8 +18,13 @@ public class ImgSpiceHost extends Host {
private static final String host = "imgspice.com";
private static final String IMG_XPATH = "//img[@id='imgpreview']";
public ImgSpiceHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public ImgSpiceHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -31,10 +38,10 @@ public class ImgSpiceHost extends Host {
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String _url, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Response resp = getResponse(url, context);
HostService.Response resp = hostService.getResponse(url, context);
Document doc = resp.getDocument();
Node imgNode;
@@ -50,8 +57,7 @@ public class ImgSpiceHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
return new HostService.NameUrl(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -8,8 +8,8 @@ import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -18,11 +18,14 @@ public class ImgboxHost extends Host {
private static final String host = "imgbox.com";
private static final String IMG_XPATH = "//img[@id='img']";
@Autowired
private ConnectionManager cm;
private final HostService hostService;
private final XpathService xpathService;
public ImgboxHost() {
super();
@Autowired
public ImgboxHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -36,9 +39,9 @@ public class ImgboxHost extends Host {
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
Node imgNode;
try {
@@ -53,8 +56,7 @@ public class ImgboxHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("title").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle);
return new HostService.NameUrl(imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -16,8 +16,10 @@ import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.HtmlProcessorException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.ConnectionManager;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.HtmlProcessorService;
import tn.mnlr.vripper.services.XpathService;
import java.io.IOException;
import java.util.ArrayList;
@@ -31,8 +33,18 @@ public class ImxHost extends Host {
private static final String CONTINUE_BUTTON_XPATH = "//*[@name='imgContinue']";
private static final String IMG_XPATH = "//img[@class='centred']";
private final HostService hostService;
private final XpathService xpathService;
private final ConnectionManager cm;
private final HtmlProcessorService htmlProcessorService;
@Autowired
private ConnectionManager cm;
public ImxHost(HostService hostService, XpathService xpathService, ConnectionManager cm, HtmlProcessorService htmlProcessorService) {
this.hostService = hostService;
this.xpathService = xpathService;
this.cm = cm;
this.htmlProcessorService = htmlProcessorService;
}
@Override
public String getHost() {
@@ -45,10 +57,10 @@ public class ImxHost extends Host {
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String _url, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Response resp = getResponse(url, context);
HostService.Response resp = hostService.getResponse(url, context);
Document doc = resp.getDocument();
Node contDiv;
@@ -69,7 +81,7 @@ public class ImxHost extends Host {
}
log.debug(String.format("Click button found for %s", url));
HttpClient client = cm.getClient().build();
HttpPost httpPost = cm.buildHttpPost(url);
HttpPost httpPost = cm.buildHttpPost(url, context);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("imgContinue", value));
try {
@@ -99,8 +111,7 @@ public class ImxHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
return new HostService.NameUrl(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -16,8 +18,14 @@ public class PimpandhostHost extends Host {
private static final String host = "pimpandhost.com";
private static final String IMG_XPATH = "//img[contains(@class, 'original')]";
public PimpandhostHost() {
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public PimpandhostHost(HostService hostService, XpathService xpathService) {
super();
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -31,16 +39,16 @@ public class PimpandhostHost extends Host {
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String _url, final HttpClientContext context) throws HostException {
String url;
try {
url = appendUri(_url.replace("http://", "https://"), "size=original");
url = hostService.appendUri(_url.replace("http://", "https://"), "size=original");
} catch (Exception e) {
throw new HostException(e);
}
Response resp = getResponse(url, context);
HostService.Response resp = hostService.getResponse(url, context);
Document doc = resp.getDocument();
Node imgNode;
@@ -56,8 +64,10 @@ public class PimpandhostHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = "https:" + imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
return new HostService.NameUrl(
imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle,
imgUrl
);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -16,6 +18,15 @@ public class PixRouteHost extends Host {
private static final String host = "pixroute.com";
private static final String IMG_XPATH = "//img[@id='imgpreview']";
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public PixRouteHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
public String getHost() {
return host;
@@ -27,10 +38,10 @@ public class PixRouteHost extends Host {
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String _url, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
Node imgNode;
try {
@@ -47,8 +58,10 @@ public class PixRouteHost extends Host {
try {
log.debug(String.format("Resolving name and image url for %s", url));
imageFileData.setImageUrl(imgNode.getAttributes().getNamedItem("src").getTextContent().trim());
imageFileData.setImageName(imgNode.getAttributes().getNamedItem("alt").getTextContent().trim());
return new HostService.NameUrl(
imgNode.getAttributes().getNamedItem("alt").getTextContent().trim(),
imgNode.getAttributes().getNamedItem("src").getTextContent().trim()
);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -17,8 +19,13 @@ public class PixhostHost extends Host {
private static final String lookup = "pixhost.to/show";
private static final String IMG_XPATH = "//img[@id='image']";
public PixhostHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public PixhostHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -32,9 +39,9 @@ public class PixhostHost extends Host {
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
Node imgNode;
try {
@@ -49,8 +56,7 @@ public class PixhostHost extends Host {
String imgTitle = imgNode.getAttributes().getNamedItem("alt").getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("src").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.substring(imgTitle.indexOf('_') + 1));
return new HostService.NameUrl(imgTitle.substring(imgTitle.indexOf('_') + 1), imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -17,8 +19,13 @@ public class PixxxelsHost extends Host {
private static final String IMG_XPATH = "//*[@id='download']";
private static final String TITLE_XPATH = "//*[contains(@class,'imagename')]";
public PixxxelsHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public PixxxelsHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -32,10 +39,10 @@ public class PixxxelsHost extends Host {
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String _url, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Response resp = getResponse(url, context);
HostService.Response resp = hostService.getResponse(url, context);
Document doc = resp.getDocument();
Node imgNode, titleNode;
@@ -55,8 +62,7 @@ public class PixxxelsHost extends Host {
String imgTitle = titleNode.getTextContent().trim();
String imgUrl = imgNode.getAttributes().getNamedItem("href").getTextContent().trim();
imageFileData.setImageUrl(imgUrl);
imageFileData.setImageName(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle);
return new HostService.NameUrl(imgTitle.isEmpty() ? imgUrl.substring(imgUrl.lastIndexOf('/') + 1) : imgTitle, imgUrl);
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
import java.util.Optional;
@@ -19,8 +21,13 @@ public class PostImgHost extends Host {
private static final String TITLE_XPATH = "//span[contains(@class,'imagename')]";
private static final String IMG_XPATH = "//a[@id='download']";
public PostImgHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public PostImgHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -34,10 +41,10 @@ public class PostImgHost extends Host {
}
@Override
protected void setNameAndUrl(final String _url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String _url, final HttpClientContext context) throws HostException {
String url = _url.replace("http://", "https://");
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
Node urlNode, titleNode;
try {
@@ -52,10 +59,9 @@ public class PostImgHost extends Host {
try {
log.debug(String.format("Resolving name and image url for %s", url));
String imgTitle = Optional.ofNullable(titleNode).map(node -> node.getTextContent().trim()).orElseGet(() -> getDefaultImageName(url));
String imgTitle = Optional.ofNullable(titleNode).map(node -> node.getTextContent().trim()).orElseGet(() -> hostService.getDefaultImageName(url));
imageFileData.setImageUrl(urlNode.getAttributes().getNamedItem("href").getTextContent().trim());
imageFileData.setImageName(imgTitle);
return new HostService.NameUrl(imgTitle, urlNode.getAttributes().getNamedItem("href").getTextContent().trim());
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -2,12 +2,14 @@ package tn.mnlr.vripper.host;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.protocol.HttpClientContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.XpathException;
import tn.mnlr.vripper.q.ImageFileData;
import tn.mnlr.vripper.services.HostService;
import tn.mnlr.vripper.services.XpathService;
@Service
@Slf4j
@@ -15,10 +17,15 @@ public class TurboImageHost extends Host {
private static final String host = "turboimagehost.com";
private static final String TITLE_XPATH = "//div[contains(@class,'titleFullS')]/h1";
private static final String IMG_XPATH = "//img[@id='uImage']";
private static final String IMG_XPATH = "//img[@id='imageid']";
public TurboImageHost() {
super();
private final HostService hostService;
private final XpathService xpathService;
@Autowired
public TurboImageHost(HostService hostService, XpathService xpathService) {
this.hostService = hostService;
this.xpathService = xpathService;
}
@Override
@@ -32,9 +39,9 @@ public class TurboImageHost extends Host {
}
@Override
protected void setNameAndUrl(final String url, final ImageFileData imageFileData, final HttpClientContext context) throws HostException {
public HostService.NameUrl getNameAndUrl(final String url, final HttpClientContext context) throws HostException {
Document doc = getResponse(url, context).getDocument();
Document doc = hostService.getResponse(url, context).getDocument();
String title;
try {
@@ -51,13 +58,12 @@ public class TurboImageHost extends Host {
}
if (title == null || title.isEmpty()) {
title = getDefaultImageName(url);
title = hostService.getDefaultImageName(url);
}
try {
Node urlNode = xpathService.getAsNode(doc, IMG_XPATH);
imageFileData.setImageUrl(urlNode.getAttributes().getNamedItem("src").getTextContent().trim());
imageFileData.setImageName(title);
return new HostService.NameUrl(title, urlNode.getAttributes().getNamedItem("src").getTextContent().trim());
} catch (Exception e) {
throw new HostException("Unexpected error occurred", e);
}
@@ -27,9 +27,9 @@ public class Management {
private final String backupFolder;
@Autowired
public Management(JdbcTemplate jdbcTemplate, @Value("${base.dir}") String baseDir) {
public Management(JdbcTemplate jdbcTemplate, @Value("${base.dir}") String baseDir, @Value("${base.dir.name}") String baseDirName) {
this.jdbcTemplate = jdbcTemplate;
this.backupFolder = baseDir + File.separator + ".vripper" + File.separator + "backup";
this.backupFolder = baseDir + File.separator + baseDirName + File.separator + "backup";
}
@PostConstruct
@@ -14,8 +14,6 @@ public interface IImageRepository extends IRepository {
List<Image> findByPostId(String postId);
Integer countRemaining();
Integer countError();
List<Image> findByPostIdAndIsNotCompleted(String postId);
@@ -67,14 +67,6 @@ public class ImageRepository implements IImageRepository {
);
}
@Override
public Integer countRemaining() {
return jdbcTemplate.queryForObject(
"SELECT COUNT(*) FROM IMAGE AS image WHERE image.TOTAL = 0 OR image.TOTAL <> image.CURRENT",
Integer.class
);
}
@Override
public Integer countError() {
return jdbcTemplate.queryForObject(
@@ -78,7 +78,7 @@ public class MetadataRepository implements IMetadataRepository {
@Override
public int deleteByPostId(String postId) {
return jdbcTemplate.update(
"DELETE FROM METADATA WHERE POST_ID_REF = (SELECT post.ID FROM POST AS post INNER JOIN METADATA metadata ON post.ID = metadata.POST_ID_REF WHERE post.POST_ID = ?)",
"DELETE FROM METADATA AS metadata WHERE metadata.ID = (SELECT inner_metadata.ID FROM POST AS post INNER JOIN METADATA inner_metadata ON post.ID = inner_metadata.POST_ID_REF WHERE post.POST_ID = ?)",
postId
);
}
@@ -3,38 +3,262 @@ package tn.mnlr.vripper.q;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.jodah.failsafe.function.CheckedRunnable;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.AbstractExecutionAwareRequest;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.util.EntityUtils;
import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.exception.DownloadException;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.jpa.domain.Image;
import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.services.*;
import java.util.Objects;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
@Slf4j
public class DownloadJob implements CheckedRunnable {
public enum ContextAttributes {
OPEN_CONNECTION("OPEN_CONNECTION");
private final String value;
ContextAttributes(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
private static final ReentrantLock LOCK = new ReentrantLock();
private static final int READ_BUFFER_SIZE = 8192;
private final DataService dataService;
private final PathService pathService;
private final ConnectionManager cm;
private final VipergirlsAuthService authService;
private final DownloadSpeedService downloadSpeedService;
private final AppSettingsService appSettingsService;
private final HttpClientContext context;
@Getter
private Image image;
private final Image image;
@Getter
private Post post;
private final Post post;
private boolean stopped = false;
@Getter
private final ImageFileData imageFileData = new ImageFileData();
private boolean finished = false;
DownloadJob(Post post, Image image) {
this.image = image;
this.post = post;
dataService = SpringContext.getBean(DataService.class);
pathService = SpringContext.getBean(PathService.class);
cm = SpringContext.getBean(ConnectionManager.class);
authService = SpringContext.getBean(VipergirlsAuthService.class);
downloadSpeedService = SpringContext.getBean(DownloadSpeedService.class);
appSettingsService = SpringContext.getBean(AppSettingsService.class);
context = HttpClientContext.create();
context.setCookieStore(new BasicCookieStore());
context.setAttribute(ContextAttributes.OPEN_CONNECTION.toString(), Collections.synchronizedList(new ArrayList<AbstractExecutionAwareRequest>()));
}
public void download(final Post post, final Image image) throws DownloadException {
try {
image.setStatus(Status.DOWNLOADING);
image.setCurrent(0);
dataService.updateImageStatus(image.getStatus(), image.getId());
dataService.updateImageCurrent(image.getCurrent(), image.getId());
try {
LOCK.lock();
if (!post.getStatus().equals(Status.DOWNLOADING) && !post.getStatus().equals(Status.PARTIAL)) {
post.setStatus(Status.DOWNLOADING);
dataService.updatePostStatus(post.getStatus(), post.getId());
}
} finally {
LOCK.unlock();
}
if (stopped) {
return;
}
/*
* HOST SPECIFIC
*/
log.debug(String.format("Getting image url and name from %s using %s", image.getUrl(), image.getHost()));
HostService.NameUrl nameAndUrl = image.getHost().getNameAndUrl(image.getUrl(), context);
log.debug(String.format("Resolved name for %s: %s", image.getUrl(), nameAndUrl.getName()));
log.debug(String.format("Resolved image url for %s: %s", image.getUrl(), nameAndUrl.getUrl()));
/*
* END HOST SPECIFIC
*/
if (stopped) {
return;
}
String formatImageFileName = pathService.formatImageFileName(nameAndUrl.getName());
log.debug(String.format("Sanitizing image name from %s to %s", nameAndUrl.getName(), formatImageFileName));
nameAndUrl = new HostService.NameUrl(formatImageFileName, nameAndUrl.getUrl());
HttpClient client = cm.getClient().build();
log.debug(String.format("Downloading %s", nameAndUrl.getUrl()));
HttpGet httpGet = cm.buildHttpGet(nameAndUrl.getUrl(), context);
httpGet.addHeader("Referer", image.getUrl());
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpGet, context)) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
EntityUtils.consumeQuietly(response.getEntity());
throw new DownloadException(String.format("Server returned code %d", response.getStatusLine().getStatusCode()));
}
if (stopped) {
return;
}
File destinationFolder;
try {
LOCK.lock();
Post updatedPost = dataService.findPostById(post.getId()).orElseThrow();
if (updatedPost.getPostFolderName() == null) {
pathService.createDefaultPostFolder(updatedPost);
}
destinationFolder = pathService.getDownloadDestinationFolder(updatedPost);
if (appSettingsService.getSettings().getLeaveThanksOnStart()) {
authService.leaveThanks(updatedPost);
}
} finally {
LOCK.unlock();
}
File outputFile = new File(destinationFolder.getPath() + File.separator + String.format("%03d_", image.getIndex()) + nameAndUrl.getName() + ".tmp");
try (InputStream downloadStream = response.getEntity().getContent(); FileOutputStream fos = new FileOutputStream(outputFile)) {
if (stopped) {
return;
}
image.setTotal(response.getEntity().getContentLength());
dataService.updateImageTotal(image.getTotal(), image.getId());
log.debug(String.format("%s length is %d", nameAndUrl.getUrl(), image.getTotal()));
log.debug(String.format("Starting data transfer for %s", nameAndUrl.getUrl()));
byte[] buffer = new byte[READ_BUFFER_SIZE];
int read;
while ((read = downloadStream.read(buffer, 0, READ_BUFFER_SIZE)) != -1 && !stopped) {
fos.write(buffer, 0, read);
image.increase(read);
downloadSpeedService.increase(read);
dataService.updateImageCurrent(image.getCurrent(), image.getId());
}
fos.flush();
EntityUtils.consumeQuietly(response.getEntity());
if (stopped) {
return;
}
}
checkImageTypeAndRename(dataService.findPostById(post.getId()).orElseThrow(), outputFile, nameAndUrl.getName(), image.getIndex());
}
} catch (Exception e) {
if (stopped) {
return;
}
throw new DownloadException(e);
} finally {
if (image.getCurrent() == image.getTotal()) {
image.setStatus(Status.COMPLETE);
} else if (stopped) {
image.setStatus(Status.STOPPED);
} else {
image.setStatus(Status.ERROR);
}
dataService.updateImageStatus(image.getStatus(), image.getId());
finished = true;
}
}
private void checkImageTypeAndRename(Post post, File outputFile, String imageName, int index) throws HostException {
try (ImageInputStream iis = ImageIO.createImageInputStream(outputFile)) {
Iterator<ImageReader> it = ImageIO.getImageReaders(iis);
if (!it.hasNext()) {
throw new HostException("Image file is not recognized!");
}
ImageReader reader = it.next();
if (reader.getFormatName().toUpperCase().equals("JPEG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_jpg") && !imageNameLC.endsWith("_jpeg")) {
imageName += ".jpg";
} else {
String toReplace = null;
if (imageNameLC.endsWith("_jpg")) {
toReplace = "_jpg";
} else if (imageNameLC.endsWith("_jpeg")) {
toReplace = "_jpeg";
}
if (toReplace != null) {
imageName = imageName.substring(0, imageName.length() - toReplace.length()) + ".jpg";
}
}
} else if (reader.getFormatName().toUpperCase().equals("PNG")) {
String imageNameLC = imageName.toLowerCase();
if (!imageNameLC.endsWith("_png")) {
imageName += ".png";
} else {
String toReplace = null;
if (imageNameLC.endsWith("_png")) {
toReplace = "_png";
}
if (toReplace != null) {
imageName = imageName.substring(0, imageName.length() - toReplace.length()) + ".png";
}
}
}
} catch (Exception e) {
throw new HostException("Failed to guess image format", e);
}
try {
File downloadDestinationFolder = pathService.getDownloadDestinationFolder(post);
File outImage = new File(downloadDestinationFolder, (appSettingsService.getSettings().getForceOrder() ? String.format("%03d_", index) : "") + imageName);
if (outImage.exists() && outImage.delete()) {
log.debug(String.format("%s is deleted", outImage.toString()));
}
Files.move(outputFile.toPath(), outImage.toPath(), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
throw new HostException("Failed to rename the image", e);
}
}
@Override
public void run() throws Exception {
if (stopped) {
finished = true;
return;
}
log.debug(String.format("Starting downloading %s", image.getUrl()));
image.getHost().download(post, image, imageFileData);
download(post, image);
}
@Override
@@ -51,8 +275,13 @@ public class DownloadJob implements CheckedRunnable {
return Objects.hash(image, post);
}
public void refresh() {
post = dataService.findPostById(post.getId()).orElseThrow();
image = dataService.findImageById(image.getId()).orElseThrow();
public void stop() {
List<AbstractExecutionAwareRequest> requests = (List<AbstractExecutionAwareRequest>) this.context.getAttribute(ContextAttributes.OPEN_CONNECTION.toString());
if (requests != null) {
for (AbstractExecutionAwareRequest request : requests) {
request.abort();
}
}
this.stopped = true;
}
}
@@ -6,46 +6,30 @@ import tn.mnlr.vripper.SpringContext;
import tn.mnlr.vripper.VripperApplication;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.MutexService;
import java.util.concurrent.locks.ReentrantLock;
@Slf4j
public class ExecuteRunnable implements Runnable {
private final ExecutionService executionService;
private final DataService dataService;
private final MutexService mutexService;
private final DownloadJob downloadJob;
public ExecuteRunnable(final DownloadJob downloadJob) {
executionService = SpringContext.getBean(ExecutionService.class);
dataService = SpringContext.getBean(DataService.class);
mutexService = SpringContext.getBean(MutexService.class);
this.downloadJob = downloadJob;
}
@Override
public void run() {
mutexService.createPostLock(downloadJob.getPost().getPostId());
ReentrantLock mutex = mutexService.getPostLock(downloadJob.getPost().getPostId());
mutex.lock();
downloadJob.refresh();
executionService.beforeJobStart(downloadJob.getPost().getPostId());
Failsafe.with(VripperApplication.retryPolicy)
.onFailure(e -> {
if (e.getFailure() instanceof InterruptedException || e.getFailure().getCause() instanceof InterruptedException) {
log.debug("Job successfully interrupted");
return;
}
log.error(String.format("Failed to download %s after %d tries", downloadJob.getImage().getUrl(), e.getAttemptCount()), e.getFailure());
downloadJob.getImage().setStatus(Status.ERROR);
dataService.updateImageStatus(downloadJob.getImage().getStatus(), downloadJob.getImage().getId());
})
.onComplete(e -> {
mutex.unlock();
dataService.afterJobFinish(downloadJob.getImage(), downloadJob.getPost());
executionService.afterJobFinish(downloadJob);
log.debug(String.format("Finished downloading %s", downloadJob.getImage().getUrl()));
@@ -10,14 +10,11 @@ import tn.mnlr.vripper.jpa.domain.Post;
import tn.mnlr.vripper.jpa.domain.enums.Status;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.MutexService;
import tn.mnlr.vripper.services.post.PostService;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -31,26 +28,23 @@ public class ExecutionService {
private final ConcurrentHashMap<Host, AtomicInteger> threadCount = new ConcurrentHashMap<>();
private final ExecutorService executor = Executors.newFixedThreadPool(MAX_POOL_SIZE);
private final BlockingQueue<DownloadJob> executionQueue = new LinkedBlockingQueue<>();
private final Map<DownloadJob, Future<?>> futures = new ConcurrentHashMap<>();
private final Map<String, AtomicInteger> downloadCount = new ConcurrentHashMap<>();
private final List<DownloadJob> executing = Collections.synchronizedList(new ArrayList<>());
private final PendingQ pendingQ;
private final AppSettingsService settings;
private final DataService dataService;
private final PostService postService;
private final MutexService mutexService;
private boolean pauseQ = false;
private Thread executionThread;
private Thread pollThread;
@Autowired
public ExecutionService(PendingQ pendingQ, AppSettingsService settings, DataService dataService, PostService postService, MutexService mutexService) {
public ExecutionService(PendingQ pendingQ, AppSettingsService settings, DataService dataService, PostService postService) {
this.pendingQ = pendingQ;
this.settings = settings;
this.dataService = dataService;
this.postService = postService;
this.mutexService = mutexService;
}
@PostConstruct
@@ -75,18 +69,25 @@ public class ExecutionService {
}
private void stopRunning(@NonNull String postId) {
futures
.entrySet()
.stream()
.filter(e -> e.getKey().getImage().getPostId().equals(postId))
.forEach(e -> {
e.getValue().cancel(true);
if (e.getKey().getImageFileData().getImageRequest() != null) {
e.getKey().getImageFileData().getImageRequest().abort();
}
e.getKey().getImage().setStatus(Status.STOPPED);
dataService.updateImageStatus(e.getKey().getImage().getStatus(), e.getKey().getImage().getId());
});
List<DownloadJob> stopping = new ArrayList<>();
Iterator<DownloadJob> iterator = executing.iterator();
while (iterator.hasNext()) {
DownloadJob downloadJob = iterator.next();
if (postId.equals(downloadJob.getPost().getPostId())) {
downloadJob.stop();
iterator.remove();
stopping.add(downloadJob);
}
}
while (!stopping.isEmpty()) {
stopping.removeIf(DownloadJob::isFinished);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
public void stopAll(List<String> posIds) {
@@ -106,7 +107,7 @@ public class ExecutionService {
}
private void restart(@NonNull String postId) {
if (isRunning(postId) || isPending(postId)) {
if (isPending(postId)) {
log.warn(String.format("Cannot restart, jobs are currently running for post id %s", postId));
return;
}
@@ -132,11 +133,6 @@ public class ExecutionService {
return pendingQ.isPending(postId);
}
public boolean isRunning(@NonNull final String postId) {
AtomicInteger runningCount = downloadCount.get(postId);
return runningCount != null && runningCount.get() > 0;
}
private void stop(String postId) {
try {
pauseQ = true;
@@ -147,9 +143,10 @@ public class ExecutionService {
if (FINISHED.contains(post.getStatus())) {
return;
}
pendingQ.remove(post);
pendingQ.stop(post);
stopRunning(postId);
dataService.stopImagesByPostIdAndIsNotCompleted(postId);
dataService.finishPost(post);
postService.stopFetchingMetadata(post);
} finally {
pauseQ = false;
@@ -205,37 +202,24 @@ public class ExecutionService {
}
private void push(DownloadJob downloadJob) {
ExecuteRunnable runnable = new ExecuteRunnable(downloadJob);
log.debug(String.format("Scheduling a job for %s", downloadJob.getImage().getUrl()));
futures.put(downloadJob, executor.submit(runnable));
}
public void beforeJobStart(String postId) {
checkKeyRunningPosts(postId);
downloadCount.get(postId).incrementAndGet();
}
private synchronized void checkKeyRunningPosts(@NonNull final String postId) {
if (!downloadCount.containsKey(postId)) {
downloadCount.put(postId, new AtomicInteger(0));
}
executor.execute(new ExecuteRunnable(downloadJob));
executing.add(downloadJob);
}
public synchronized void afterJobFinish(DownloadJob downloadJob) {
int count = downloadCount.get(downloadJob.getPost().getPostId()).decrementAndGet();
if (count == 0 && !pendingQ.isPending(downloadJob.getPost().getPostId())) {
downloadCount.remove(downloadJob.getPost().getPostId());
int count = pendingQ.decrement(downloadJob.getPost().getPostId());
if (count == 0) {
dataService.finishPost(downloadJob.getPost());
mutexService.removePostLock(downloadJob.getPost().getPostId());
}
threadCount.get(downloadJob.getImage().getHost()).decrementAndGet();
futures.remove(downloadJob);
executing.remove(downloadJob);
synchronized (threadCount) {
threadCount.notify();
}
}
public int runningCount() {
return futures.size();
return executing.size();
}
}
@@ -1,16 +0,0 @@
package tn.mnlr.vripper.q;
import lombok.Getter;
import lombok.Setter;
import org.apache.http.client.methods.HttpUriRequest;
@Getter
@Setter
public class ImageFileData {
private String pageUrl;
private String imageName;
private String fileName;
private String imageUrl;
private HttpUriRequest imageRequest;
}
@@ -14,6 +14,8 @@ import java.util.*;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Predicate;
@Service
@Slf4j
@@ -24,6 +26,7 @@ public class PendingQ {
private final List<Host> hosts;
private final ConcurrentHashMap<Host, BlockingDeque<DownloadJob>> pendingQ = new ConcurrentHashMap<>();
private final ConcurrentHashMap<String, AtomicInteger> toBeExecuted = new ConcurrentHashMap<>();
@Autowired
public PendingQ(DataService dataService, AppSettingsService appSettingsService, List<Host> hosts) {
@@ -44,6 +47,14 @@ public class PendingQ {
dataService.updateImageCurrent(image.getCurrent(), image.getId());
DownloadJob downloadJob = new DownloadJob(post, image);
pendingQ.get(downloadJob.getImage().getHost()).putLast(downloadJob);
checkKey(post.getPostId());
toBeExecuted.get(post.getPostId()).incrementAndGet();
}
private synchronized void checkKey(String postId) {
if (!toBeExecuted.containsKey(postId)) {
toBeExecuted.put(postId, new AtomicInteger(0));
}
}
public void remove(final DownloadJob downloadJob) {
@@ -74,17 +85,31 @@ public class PendingQ {
}
public int size() {
return pendingQ.values().stream().mapToInt(BlockingDeque::size).sum();
return toBeExecuted.values().stream().mapToInt(AtomicInteger::get).sum();
}
public void remove(Post post) {
public void stop(Post post) {
Predicate<DownloadJob> predicate = next -> next.getImage().getPostId().equals(post.getPostId());
for (Map.Entry<Host, BlockingDeque<DownloadJob>> entry : pendingQ.entrySet()) {
entry.getValue().removeIf(next -> next.getImage().getPostId().equals(post.getPostId()));
entry.getValue().stream().filter(predicate).forEach(e -> decrement(post.getPostId()));
entry.getValue().removeIf(predicate);
decrement(post.getPostId());
}
dataService.finishPost(post);
}
public boolean isPending(String postId) {
return pendingQ.values().stream().flatMap(Collection::stream).anyMatch(e -> e.getPost().getPostId().equals(postId));
return toBeExecuted.containsKey(postId);
}
public synchronized int decrement(String postId) {
AtomicInteger counter = toBeExecuted.get(postId);
if (counter == null) {
return 0;
}
int count = counter.decrementAndGet();
if (count == 0) {
toBeExecuted.remove(postId);
}
return count;
}
}
@@ -30,17 +30,13 @@ import static java.nio.file.StandardOpenOption.*;
@Slf4j
public class AppSettingsService {
private final String MAX_TOTAL_THREADS = "MAX_TOTAL_THREADS";
private final String baseDir;
private final Path configPath;
private final ObjectMapper om = new ObjectMapper();
private Settings settings = new Settings();
public AppSettingsService(@Value("${base.dir}") String baseDir) {
this.baseDir = baseDir;
this.configPath = Paths.get(baseDir, ".vripper", "config.json");
public AppSettingsService(@Value("${base.dir}") String baseDir, @Value("${base.dir.name}") String baseDirName) {
this.configPath = Paths.get(baseDir, baseDirName, "config.json");
om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
@@ -53,7 +49,7 @@ public class AppSettingsService {
if (settings.getVLogin()) {
if (!this.settings.getVPassword().equals(settings.getVPassword())) {
settings.setVPassword(settings.getVPassword());
settings.setVPassword(DigestUtils.md5Hex(settings.getVPassword()));
}
} else {
settings.setVUsername("");
@@ -80,7 +76,7 @@ public class AppSettingsService {
}
if (settings.getDownloadPath() == null) {
settings.setDownloadPath(baseDir);
settings.setDownloadPath(System.getProperty("user.home"));
}
if (settings.getMaxThreads() == null) {
@@ -135,23 +131,20 @@ public class AppSettingsService {
settings.setDarkTheme(false);
}
if (settings.getViewPhotos() == null) {
settings.setViewPhotos(false);
if (settings.getAppendPostId() == null) {
settings.setAppendPostId(true);
}
if (settings.getNotification() == null) {
settings.setNotification(false);
if (settings.getLeaveThanksOnStart() == null) {
settings.setLeaveThanksOnStart(false);
}
save();
}
@PreDestroy
public void save() {
try {
// force disable gallery
settings.setViewPhotos(false);
Files.write(configPath, om.writeValueAsBytes(settings), CREATE, WRITE, TRUNCATE_EXISTING, SYNC);
} catch (IOException e) {
@@ -211,43 +204,50 @@ public class AppSettingsService {
@JsonProperty("downloadPath")
private String downloadPath;
@JsonProperty("maxThreads")
private Integer maxThreads;
@JsonProperty("maxTotalThreads")
private Integer maxTotalThreads;
@JsonProperty("autoStart")
private Boolean autoStart;
@JsonProperty("vLogin")
private Boolean vLogin;
@JsonProperty("vUsername")
private String vUsername;
@JsonProperty("vPassword")
private String vPassword;
@JsonProperty("vThanks")
private Boolean vThanks;
@JsonProperty("desktopClipboard")
private Boolean desktopClipboard;
@JsonProperty("forceOrder")
private Boolean forceOrder;
@JsonProperty("subLocation")
private Boolean subLocation;
@JsonProperty("threadSubLocation")
private Boolean threadSubLocation;
@JsonProperty("clearCompleted")
private Boolean clearCompleted;
@JsonProperty("viewPhotos")
private Boolean viewPhotos;
@JsonProperty("notification")
private Boolean notification;
@JsonProperty("darkTheme")
private Boolean darkTheme;
public void setVPassword(String vPassword) {
if (vPassword == null || vPassword.isEmpty()) {
this.vPassword = "";
} else {
this.vPassword = DigestUtils.md5Hex(vPassword);
}
}
@JsonProperty("appendPostId")
private Boolean appendPostId;
@JsonProperty("leaveThanksOnStart")
private Boolean leaveThanksOnStart;
}
}
@@ -2,8 +2,10 @@ package tn.mnlr.vripper.services;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.AbstractExecutionAwareRequest;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.client.LaxRedirectStrategy;
@@ -11,8 +13,10 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import tn.mnlr.vripper.q.DownloadJob;
import java.net.URI;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Service
@@ -53,21 +57,33 @@ public class ConnectionManager {
.setDefaultRequestConfig(rc);
}
public HttpGet buildHttpGet(String url) {
public HttpGet buildHttpGet(String url, final HttpClientContext context) {
HttpGet httpGet = new HttpGet(url.replace(" ", "+"));
httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
addToContext(context, httpGet);
return httpGet;
}
public HttpPost buildHttpPost(String url) {
public HttpPost buildHttpPost(String url, final HttpClientContext context) {
HttpPost httpPost = new HttpPost(url.replace(" ", "+"));
httpPost.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
addToContext(context, httpPost);
return httpPost;
}
public HttpGet buildHttpGet(URI uri) {
public HttpGet buildHttpGet(URI uri, final HttpClientContext context) {
HttpGet httpGet = new HttpGet(uri);
httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36");
addToContext(context, httpGet);
return httpGet;
}
public void addToContext(HttpClientContext context, AbstractExecutionAwareRequest request) {
if (context != null) {
List<AbstractExecutionAwareRequest> requests = (List<AbstractExecutionAwareRequest>) context.getAttribute(DownloadJob.ContextAttributes.OPEN_CONNECTION.toString());
if (requests != null) {
requests.add(request);
}
}
}
}
@@ -169,10 +169,6 @@ public class DataService {
}
public long countRemainingImages() {
return imageRepository.countRemaining();
}
public long countErrorImages() {
return imageRepository.countError();
}
@@ -8,13 +8,11 @@ import java.util.Objects;
public class GlobalState {
private final long running;
private final long queued;
private final long remaining;
private final long error;
GlobalState(long running, long queued, long remaining, long error) {
GlobalState(long running, long remaining, long error) {
this.running = running;
this.queued = queued;
this.remaining = remaining;
this.error = error;
}
@@ -24,11 +22,11 @@ public class GlobalState {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
GlobalState that = (GlobalState) o;
return running == that.running && queued == that.queued && remaining == that.remaining && error == that.error;
return running == that.running && remaining == that.remaining && error == that.error;
}
@Override
public int hashCode() {
return Objects.hash(running, queued, remaining, error);
return Objects.hash(running, remaining, error);
}
}
@@ -35,7 +35,6 @@ public class GlobalStateService {
GlobalState newGlobalState = new GlobalState(
executionService.runningCount(),
pendingQ.size(),
dataService.countRemainingImages(),
dataService.countErrorImages());
if (!newGlobalState.equals(currentState)) {
currentState = newGlobalState;
@@ -0,0 +1,105 @@
package tn.mnlr.vripper.services;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.Header;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.w3c.dom.Document;
import tn.mnlr.vripper.exception.HostException;
import tn.mnlr.vripper.exception.HtmlProcessorException;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
@Service
@Slf4j
public class HostService {
private final ConnectionManager cm;
private final HtmlProcessorService htmlProcessorService;
@Autowired
public HostService(ConnectionManager cm, HtmlProcessorService htmlProcessorService) {
this.cm = cm;
this.htmlProcessorService = htmlProcessorService;
}
@Getter
public static class Response {
private final Document document;
private final Header[] headers;
protected Response(Document document, Header[] headers) {
this.document = document;
this.headers = headers;
}
}
@Getter
public static class NameUrl {
private String name;
private String url;
public NameUrl(String name, String url) {
this.name = name;
this.url = url;
}
}
public Response getResponse(final String url, final HttpClientContext context) throws HostException {
String basePage;
HttpClient client = cm.getClient().build();
HttpGet httpGet = cm.buildHttpGet(url, context);
Header[] headers;
log.debug(String.format("Requesting %s", url));
try (CloseableHttpResponse response = (CloseableHttpResponse) client.execute(httpGet, context)) {
if (response.getStatusLine().getStatusCode() / 100 != 2) {
throw new HostException(String.format("Unexpected response code: %d", response.getStatusLine().getStatusCode()));
}
headers = response.getAllHeaders();
basePage = EntityUtils.toString(response.getEntity());
log.debug(String.format("%s response: %n%s", url, basePage));
EntityUtils.consumeQuietly(response.getEntity());
} catch (IOException e) {
throw new HostException(e);
}
try {
log.debug(String.format("Cleaning %s response", url));
return new Response(htmlProcessorService.clean(basePage), headers);
} catch (HtmlProcessorException e) {
throw new HostException(e);
}
}
public String appendUri(String uri, String appendQuery) throws URISyntaxException {
URI oldUri = new URI(uri);
String newQuery = oldUri.getQuery();
if (newQuery == null) {
newQuery = appendQuery;
} else {
newQuery += "&" + appendQuery;
}
return new URI(oldUri.getScheme(), oldUri.getAuthority(),
oldUri.getPath(), newQuery, oldUri.getFragment()).toString();
}
public String getDefaultImageName(final String imgUrl) {
String imageTitle = imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
log.debug(String.format("Extracting name from url %s: %s", imgUrl, imageTitle));
return imgUrl;
}
}
@@ -1,27 +0,0 @@
package tn.mnlr.vripper.services;
import org.springframework.stereotype.Service;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
@Service
public class MutexService {
private final Map<String, ReentrantLock> postLock = new ConcurrentHashMap<>();
public synchronized void createPostLock(String postId) {
if (!postLock.containsKey(postId)) {
postLock.put(postId, new ReentrantLock());
}
}
public void removePostLock(String postId) {
postLock.remove(postId);
}
public ReentrantLock getPostLock(String postId) {
return postLock.get(postId);
}
}
@@ -13,90 +13,92 @@ import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.locks.ReentrantLock;
import java.util.Objects;
import java.util.stream.Collectors;
@Service
@Slf4j
public class PathService {
public static final int MAX_ATTEMPTS = 24;
private final AppSettingsService appSettingsService;
private final DataService dataService;
private final MutexService mutexService;
private final CommonExecutor commonExecutor;
@Autowired
public PathService(AppSettingsService appSettingsService, DataService dataService, MutexService mutexService, CommonExecutor commonExecutor) {
public PathService(AppSettingsService appSettingsService, DataService dataService, CommonExecutor commonExecutor) {
this.appSettingsService = appSettingsService;
this.dataService = dataService;
this.mutexService = mutexService;
this.commonExecutor = commonExecutor;
}
public final File getDownloadDestinationFolder(Post post) {
return _getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), post.getPostFolderName());
return _getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), post.getPostFolderName(), post.getPostId());
}
private File _getDownloadDestinationFolder(@NonNull String forum, @NonNull String threadTitle, @NonNull String title) {
private File _getRootFolder(@NonNull String forum, @NonNull String threadTitle) {
File sourceFolder = appSettingsService.getSettings().getSubLocation() ? new File(appSettingsService.getSettings().getDownloadPath(), sanitize(forum)) : new File(appSettingsService.getSettings().getDownloadPath());
sourceFolder = appSettingsService.getSettings().getThreadSubLocation() ? new File(sourceFolder, threadTitle) : sourceFolder;
return appSettingsService.getSettings().getThreadSubLocation() ? new File(sourceFolder, threadTitle) : sourceFolder;
}
private File _getDownloadDestinationFolder(@NonNull String forum, @NonNull String threadTitle, @NonNull String title, @NonNull String postId) {
File sourceFolder = _getRootFolder(forum, threadTitle);
return new File(sourceFolder, title);
}
private File _createDownloadDestinationFolder(@NonNull String forum, @NonNull String threadTitle, @NonNull String title, @NonNull String postId) {
File sourceFolder = _getRootFolder(forum, threadTitle);
return new File(sourceFolder, appSettingsService.getSettings().getAppendPostId() ? title + "_" + postId : title);
}
public final void createDefaultPostFolder(Post post) {
File sourceFolder = _getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(post.getTitle()));
File sourceFolder = _createDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(post.getTitle()), post.getPostId());
File destFolder = makeDirs(sourceFolder);
post.setPostFolderName(destFolder.getName());
dataService.updatePostFolderName(post.getPostFolderName(), post.getId());
}
public final void rename(@NonNull String postId, @NonNull String altName) {
Post post = dataService.findPostByPostId(postId).orElseThrow();
commonExecutor.getGeneralExecutor().submit(() -> {
if (altName.equals(post.getTitle())) {
return;
}
post.setTitle(altName);
dataService.updatePostTitle(post.getTitle(), post.getId());
if (post.getPostFolderName() == null) {
return;
}
File newDestFolder = makeDirs(_getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(altName), postId));
File currentDesFolder = getDownloadDestinationFolder(post);
post.setPostFolderName(newDestFolder.getName());
dataService.updatePostFolderName(post.getPostFolderName(), post.getId());
ReentrantLock postLock = mutexService.getPostLock(postId);
if (postLock != null) {
postLock.lock();
List<File> files = Arrays.stream(Objects.requireNonNull(currentDesFolder.listFiles())).filter(e -> !e.getName().endsWith(".tmp")).collect(Collectors.toList());
for (File f : files) {
try {
Files.move(f.toPath(), Paths.get(newDestFolder.toString(), f.toPath().getFileName().toString()), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.error(String.format("Failed to move files from %s to %s", currentDesFolder.toString(), newDestFolder.toString()), e);
return;
}
}
try {
Optional<Post> _post = dataService.findPostByPostId(postId);
if (_post.isEmpty()) {
return;
}
Post post = _post.get();
if (altName.equals(post.getTitle())) {
return;
}
post.setTitle(altName);
dataService.updatePostTitle(post.getTitle(), post.getId());
if (post.getPostFolderName() == null) {
return;
}
File newDestFolder = makeDirs(_getDownloadDestinationFolder(post.getForum(), post.getThreadTitle(), sanitize(altName)));
File currentDesFolder = getDownloadDestinationFolder(post);
post.setPostFolderName(newDestFolder.getName());
dataService.updatePostFolderName(post.getPostFolderName(), post.getId());
List<File> files = Optional.ofNullable(currentDesFolder.listFiles()).stream().flatMap(Arrays::stream).filter(e -> !e.getName().endsWith(".tmp")).collect(Collectors.toList());
for (File f : files) {
try {
Files.move(f.toPath(), Paths.get(newDestFolder.toString(), f.toPath().getFileName().toString()), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
log.error(String.format("Failed to move files from %s to %s", currentDesFolder.toString(), newDestFolder.toString()), e);
return;
}
}
int attempts = 0;
while (currentDesFolder.exists() && attempts <= MAX_ATTEMPTS) {
attempts++;
if (!currentDesFolder.delete()) {
log.warn(String.format("Failed to remove %s", currentDesFolder.toString()));
}
} finally {
if (postLock != null) {
postLock.unlock();
try {
Thread.sleep(5_000);
} catch (InterruptedException ignored) {
}
}
if (attempts > MAX_ATTEMPTS) {
log.error(String.format("Failed to rename post %s", postId));
}
});
}
@@ -49,7 +49,7 @@ public class VRThreadParser {
try {
URIBuilder uriBuilder = new URIBuilder(VR_API);
uriBuilder.setParameter("t", queued.getThreadId());
httpGet = cm.buildHttpGet(uriBuilder.build());
httpGet = cm.buildHttpGet(uriBuilder.build(), null);
} catch (URISyntaxException e) {
throw new PostParseException(e);
}
@@ -85,7 +85,7 @@ public class VipergirlsAuthService {
return;
}
HttpPost postAuth = cm.buildHttpPost("https://vipergirls.to/login.php?do=login");
HttpPost postAuth = cm.buildHttpPost("https://vipergirls.to/login.php?do=login", null);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("vb_login_username", username));
@@ -161,7 +161,7 @@ public class VipergirlsAuthService {
private void postThanks(Post post) throws VripperException {
HttpPost postThanks = cm.buildHttpPost("https://vipergirls.to/post_thanks.php");
HttpPost postThanks = cm.buildHttpPost("https://vipergirls.to/post_thanks.php", null);
List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("do", "post_thanks_add"));
params.add(new BasicNameValuePair("using_ajax", "1"));
@@ -99,7 +99,7 @@ public class MetadataCache {
}
private Metadata fetchMetadata(Key key) {
HttpGet httpGet = cm.buildHttpGet(key.getUrl());
HttpGet httpGet = cm.buildHttpGet(key.getUrl(), null);
Metadata metadata = new Metadata();
Failsafe.with(VripperApplication.retryPolicy)
.onFailure(e -> {
@@ -11,6 +11,7 @@ import tn.mnlr.vripper.q.PendingQ;
import tn.mnlr.vripper.services.AppSettingsService;
import tn.mnlr.vripper.services.CommonExecutor;
import tn.mnlr.vripper.services.DataService;
import tn.mnlr.vripper.services.VipergirlsAuthService;
import java.util.Map;
import java.util.Set;
@@ -26,13 +27,15 @@ public class PostService {
private final DataService dataService;
private final CommonExecutor commonExecutor;
private final Map<String, Future<?>> fetchingMetadata = new ConcurrentHashMap<>();
private final VipergirlsAuthService vipergirlsAuthService;
@Autowired
public PostService(AppSettingsService appSettingsService, PendingQ pendingQ, DataService dataService, DataService dataService1, CommonExecutor commonExecutor) {
public PostService(AppSettingsService appSettingsService, PendingQ pendingQ, DataService dataService, CommonExecutor commonExecutor, VipergirlsAuthService vipergirlsAuthService) {
this.appSettingsService = appSettingsService;
this.pendingQ = pendingQ;
this.dataService = dataService1;
this.dataService = dataService;
this.commonExecutor = commonExecutor;
this.vipergirlsAuthService = vipergirlsAuthService;
}
public void addPost(String postId, String threadId) throws PostParseException {
@@ -71,6 +74,9 @@ public class PostService {
post.setStatus(Status.STOPPED);
log.debug("Auto start downloads option is disabled");
}
if (!appSettingsService.getSettings().getLeaveThanksOnStart()) {
vipergirlsAuthService.leaveThanks(post);
}
dataService.updatePostStatus(post.getStatus(), post.getId());
}
@@ -44,7 +44,7 @@ public class VRPostParser {
try {
URIBuilder uriBuilder = new URIBuilder(VR_API);
uriBuilder.setParameter("p", postId);
httpGet = cm.buildHttpGet(uriBuilder.build());
httpGet = cm.buildHttpGet(uriBuilder.build(), null);
} catch (URISyntaxException e) {
throw new PostParseException(e);
}
@@ -22,13 +22,15 @@ public class AppDataController {
private final GlobalStateService globalStateService;
private final DownloadSpeedService downloadSpeedService;
private final DataService dataService;
private final PathService pathService;
@Autowired
public AppDataController(VipergirlsAuthService vipergirlsAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService) {
public AppDataController(VipergirlsAuthService vipergirlsAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService, PathService pathService) {
this.vipergirlsAuthService = vipergirlsAuthService;
this.globalStateService = globalStateService;
this.downloadSpeedService = downloadSpeedService;
this.dataService = dataService;
this.pathService = pathService;
}
@Getter
@@ -27,16 +27,18 @@ public class WebSocketBroadcast {
private final GlobalStateService globalStateService;
private final DownloadSpeedService downloadSpeedService;
private final DataService dataService;
private final PathService pathService;
private final List<Disposable> disposables = new ArrayList<>();
@Autowired
public WebSocketBroadcast(SimpMessagingTemplate template, VipergirlsAuthService vipergirlsAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService) {
public WebSocketBroadcast(SimpMessagingTemplate template, VipergirlsAuthService vipergirlsAuthService, GlobalStateService globalStateService, DownloadSpeedService downloadSpeedService, DataService dataService, PathService pathService) {
this.template = template;
this.vipergirlsAuthService = vipergirlsAuthService;
this.globalStateService = globalStateService;
this.downloadSpeedService = downloadSpeedService;
this.dataService = dataService;
this.pathService = pathService;
}
@PostConstruct
@@ -1 +0,0 @@
base.dir=${user.home}
@@ -1 +0,0 @@
base.dir=${user.dir}
@@ -2,15 +2,15 @@ logging.level.org.springframework.web=INFO
logging.level.root=INFO
logging.level.org.apache.http=INFO
logging.level.org.springframework.web.socket.config.WebSocketMessageBrokerStats=ERROR
logging.file.name=${base.dir}/.vripper/vripper.log
logging.file.name=${base.dir}/${base.dir.name}/vripper.log
server.port=${vripper.server.port:8080}
management.endpoints.web.exposure.include=shutdown
management.endpoint.shutdown.enabled=true
server.error.include-message=always
spring.liquibase.change-log=classpath:db/changelog/db.changelog-master.xml
spring.datasource.url=jdbc:hsqldb:file:${base.dir}/.vripper/db/xparty
spring.datasource.url=jdbc:hsqldb:file:${base.dir}/${base.dir.name}/db/xparty;hsqldb.lock_file=false
spring.datasource.username=SA
spring.datasource.password=lEtmEIn
spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver
spring.profiles.active=portable
#spring.profiles.active=installer
base.dir=${user.dir}
base.dir.name=${vripper.base.dir.name:vripper}
@@ -164,4 +164,9 @@
initiallyDeferred="false" onDelete="NO ACTION" onUpdate="NO ACTION"
referencedColumnNames="ID" referencedTableName="POST"/>
</changeSet>
<changeSet id="1600798657000-01" author="sysgen">
<createIndex tableName="POST" indexName="POST_UQ_POST_ID_IDX">
<column name="POST_ID"/>
</createIndex>
</changeSet>
</databaseChangeLog>
+615 -584
View File
File diff suppressed because it is too large Load Diff
+25 -25
View File
@@ -1,6 +1,6 @@
{
"name": "vripper-ui",
"version": "3.0.0",
"version": "3.0.9",
"scripts": {
"ng": "ng",
"start": "ng serve",
@@ -13,46 +13,46 @@
},
"private": true,
"dependencies": {
"@angular/animations": "10.0.2",
"@angular/cdk": "10.0.1",
"@angular/common": "10.0.2",
"@angular/compiler": "10.0.2",
"@angular/core": "10.0.2",
"@angular/animations": "10.0.9",
"@angular/cdk": "10.1.3",
"@angular/common": "10.0.9",
"@angular/compiler": "10.0.9",
"@angular/core": "10.0.9",
"@angular/flex-layout": "10.0.0-beta.32",
"@angular/forms": "10.0.2",
"@angular/material": "10.0.1",
"@angular/platform-browser": "10.0.2",
"@angular/platform-browser-dynamic": "10.0.2",
"@angular/router": "10.0.2",
"@angular/forms": "10.0.9",
"@angular/material": "10.1.3",
"@angular/platform-browser": "10.0.9",
"@angular/platform-browser-dynamic": "10.0.9",
"@angular/router": "10.0.9",
"@stomp/rx-stomp": "^0.3.5",
"ag-grid-angular": "23.2.1",
"ag-grid-community": "23.2.1",
"core-js": "3.6.5",
"ngx-electron": "2.2.0",
"rxjs": "6.5.5",
"tslib": "^2.0.0",
"rxjs": "6.6.2",
"tslib": "^2.0.1",
"zone.js": "0.10.3"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.1000.0",
"@angular/cli": "10.0.0",
"@angular/compiler-cli": "10.0.2",
"@angular/language-service": "10.0.2",
"@types/jasmine": "3.5.11",
"@angular-devkit/build-angular": "^0.1000.6",
"@angular/cli": "10.0.6",
"@angular/compiler-cli": "10.0.9",
"@angular/language-service": "10.0.9",
"@types/jasmine": "3.5.12",
"@types/jasminewd2": "2.0.8",
"@types/node": "12.12.21",
"codelyzer": "5.2.2",
"electron": "9.1.0",
"jasmine-core": "~3.5.0",
"codelyzer": "6.0.0",
"electron": "9.2.0",
"jasmine-core": "~3.6.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma": "~5.1.1",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~3.3.0",
"karma-jasmine": "~4.0.1",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "8.10.2",
"tslint": "~6.1.0",
"typescript": "3.9.5"
"tslint": "~6.1.3",
"typescript": "3.9.7"
}
}
+1 -1
View File
@@ -5,7 +5,7 @@
<parent>
<groupId>tn.mnlr</groupId>
<artifactId>vripper</artifactId>
<version>3.0.0</version>
<version>3.0.9</version>
</parent>
<artifactId>vripper-ui</artifactId>
<name>vripper-ui</name>
+1 -1
View File
@@ -38,7 +38,7 @@ export class ClipboardService {
_init(settings: Settings) {
if (!this.electronService.isElectronApp) {
console.log('Clipboard deactive, not an electron app');
console.log('Clipboard deactivated, not an electron app');
return;
}
if (this.interval != null) {
@@ -1,3 +1,4 @@
export class GlobalState {
constructor(public running: number, public queued: number, public remaining: number, public error: number) {}
constructor(public running: number, public remaining: number, public error: number) {
}
}
@@ -9,6 +9,5 @@ export interface Settings {
vThanks: boolean;
desktopClipboard: boolean;
viewPhotos: boolean;
notification: boolean;
resolveTitle: boolean;
}
@@ -1,10 +1,9 @@
import {LinkCollectorService} from './../link-collector.service';
import {LinkCollectorService} from '../link-collector.service';
import {UrlGrabRendererComponent} from './renderer/url-renderer.component';
import {GrabQueueDataSource} from './grab-queue.datasource';
import {ChangeDetectionStrategy, Component, NgZone, OnInit} from '@angular/core';
import {GridOptions} from 'ag-grid-community';
import {WsConnectionService} from '../ws-connection.service';
import {NotificationService} from '../notification.service';
@Component({
selector: 'app-grab-queue',
@@ -16,8 +15,7 @@ export class GrabQueueComponent implements OnInit {
constructor(
private wsConnection: WsConnectionService,
private zone: NgZone,
private linkCollectorService: LinkCollectorService,
private notificationService: NotificationService) {
private linkCollectorService: LinkCollectorService) {
this.gridOptions = <GridOptions>{
columnDefs: [
{
@@ -40,7 +38,7 @@ export class GrabQueueComponent implements OnInit {
getRowNodeId: data => data['threadId'],
onGridReady: () => {
this.gridOptions.api.sizeColumnsToFit();
this.dataSource = new GrabQueueDataSource(this.wsConnection, this.gridOptions, this.zone, this.notificationService);
this.dataSource = new GrabQueueDataSource(this.wsConnection, this.gridOptions, this.zone);
this.dataSource.connect();
},
onGridSizeChanged: () => this.gridOptions.api.sizeColumnsToFit(),
@@ -1,7 +1,6 @@
import {GrabQueueState} from '../domain/grab-queue.model';
import {Subscription} from 'rxjs';
import {WsConnectionService} from '../ws-connection.service';
import {NotificationService} from '../notification.service';
import {GridOptions, RowNode} from 'ag-grid-community';
import {NgZone} from '@angular/core';
@@ -9,8 +8,7 @@ export class GrabQueueDataSource {
constructor(
private ws: WsConnectionService,
private gridOptions: GridOptions,
private zone: NgZone,
private notificationService: NotificationService
private zone: NgZone
) {
}
@@ -30,13 +28,6 @@ export class GrabQueueDataSource {
}
});
this.gridOptions.api.applyTransaction({update: toUpdate, add: toAdd});
const count = this.gridOptions.api.getDisplayedRowCount();
if (count > 0 && toAdd.length > 0) {
this.notificationService.notifyFromGrabQueue(
'Link Collector',
`You have ${count} ${count > 1 ? 'threads' : 'thread'} waiting in the link collector`
);
}
});
}));
@@ -1,26 +0,0 @@
import { Injectable } from '@angular/core';
import { AppService } from './app.service';
@Injectable({
providedIn: 'root'
})
export class NotificationService {
constructor(private appService: AppService) {}
notifyFromGrabQueue(title: string, body: string) {
if (!this.appService.settings.notification) {
return;
}
if (!('Notification' in window)) {
return;
} else if (Notification.permission === 'granted') {
const notification = new Notification(title, { body: body, icon: 'assets/icon.png' });
} else if (Notification.permission !== 'denied') {
Notification.requestPermission().then(function(permission) {
if (permission === 'granted') {
const notification = new Notification(title, { body: body, icon: 'assets/icon.png' });
}
});
}
}
}
@@ -103,18 +103,13 @@
</section>
</form>
</mat-tab>
<mat-tab label="Desktop Integration">
<mat-tab label="Desktop Integration" *ngIf="electronService.isElectronApp">
<form [formGroup]="desktopSettingsForm" autocomplete="off">
<mat-checkbox *ngIf="electronService.isElectronApp" color="primary" formControlName="desktopClipboard"
name="desktopClipboard"
>Monitor Clipboard
</mat-checkbox
>
<mat-checkbox color="primary" formControlName="notification" name="notification"
>Enable system notifications
</mat-checkbox
>
</form>
</mat-tab>
</mat-tab-group>
@@ -46,8 +46,7 @@ export class SettingsComponent implements OnInit {
});
desktopSettingsForm = new FormGroup({
desktopClipboard: new FormControl(false),
notification: new FormControl(false)
desktopClipboard: new FormControl(false)
});
darkTheme = false;
@@ -4,7 +4,6 @@
<span *ngIf="downloadSpeed$ | async as speed">{{ speed.speed + '/s' }}</span>
<ng-container *ngIf="globalState$ | async as state">
<span>Downloading: {{ state!.running }}</span>
<span>Pending: {{ state!.queued }}</span>
<span>Remaining: {{ state!.remaining }}</span>
<span>Error: {{ state!.error }}</span>
</ng-container>
@@ -16,7 +16,7 @@ export class StatusBarComponent implements OnInit, OnDestroy {
}
downloadSpeed$: Subject<DownloadSpeed> = new BehaviorSubject(new DownloadSpeed('0 B'));
globalState$: Subject<GlobalState> = new BehaviorSubject(new GlobalState(0, 0, 0, 0));
globalState$: Subject<GlobalState> = new BehaviorSubject(new GlobalState(0, 0, 0));
selected$: Subject<number> = new BehaviorSubject(0);
subscriptions: Subscription[] = [];
@@ -2,5 +2,5 @@ export const environment = {
production: true,
localhost: `${window.location.protocol}//${window.location.host}`,
ws: `${window.location.protocol === 'http:' ? 'ws:' : 'wss:'}//${window.location.host}`,
version: '3.0.0'
version: '3.0.9'
};
+1 -1
View File
@@ -6,7 +6,7 @@ export const environment = {
production: false,
localhost: 'http://localhost:8080',
ws: 'ws://localhost:8080',
version: '3.0.0'
version: '3.0.9'
};
/*
+1 -1
View File
@@ -5,7 +5,7 @@
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"module": "esnext",
"module": "es2020",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,