Update to Java 8

* Changed the Maven target to 1.8
* Performed a preliminary cleanup using IntelliJ's Code Analysis (Only Java 7/8 updates and a few other entries in the Error and Warnings categories)
* Updated the readme to change the required Java version
This commit is contained in:
Julien Machiels 2017-10-24 16:33:28 +02:00
parent d4f83c0ae6
commit d043685d2e
94 changed files with 585 additions and 787 deletions

View File

@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/4pr0n/ripme.svg?branch=master)](https://travis-ci.org/4pr0n/ripme) [![Build Status](https://travis-ci.org/4pr0n/ripme.svg?branch=master)](https://travis-ci.org/4pr0n/ripme)
[![Join the chat at https://gitter.im/RipMeApp/Lobby](https://badges.gitter.im/RipMeApp/Lobby.svg)](https://gitter.im/RipMeApp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/RipMeApp/Lobby](https://badges.gitter.im/RipMeApp/Lobby.svg)](https://gitter.im/RipMeApp/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Album ripper for various websites. Runs on your computer. Requires Java 1.6 Album ripper for various websites. Runs on your computer. Requires Java 8.
![Screenshot](http://i.imgur.com/kWzhsIu.png) ![Screenshot](http://i.imgur.com/kWzhsIu.png)

View File

@ -84,8 +84,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version> <version>3.1</version>
<configuration> <configuration>
<source>1.6</source> <source>1.8</source>
<target>1.6</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -62,13 +62,13 @@ public class App {
} }
} }
public static void rip(URL url) throws Exception { private static void rip(URL url) throws Exception {
AbstractRipper ripper = AbstractRipper.getRipper(url); AbstractRipper ripper = AbstractRipper.getRipper(url);
ripper.setup(); ripper.setup();
ripper.rip(); ripper.rip();
} }
public static void handleArguments(String[] args) { private static void handleArguments(String[] args) {
CommandLine cl = getArgs(args); CommandLine cl = getArgs(args);
if (cl.hasOption('h')) { if (cl.hasOption('h')) {
HelpFormatter hf = new HelpFormatter(); HelpFormatter hf = new HelpFormatter();
@ -172,7 +172,7 @@ public class App {
} }
// this function will attempt to rip the provided url // this function will attempt to rip the provided url
public static void ripURL(String targetURL, boolean saveConfig) { private static void ripURL(String targetURL, boolean saveConfig) {
try { try {
URL url = new URL(targetURL); URL url = new URL(targetURL);
rip(url); rip(url);
@ -193,7 +193,7 @@ public class App {
} }
} }
public static Options getOptions() { private static Options getOptions() {
Options opts = new Options(); Options opts = new Options();
opts.addOption("h", "help", false, "Print the help"); opts.addOption("h", "help", false, "Print the help");
opts.addOption("u", "url", true, "URL of album to rip"); opts.addOption("u", "url", true, "URL of album to rip");
@ -211,11 +211,10 @@ public class App {
return opts; return opts;
} }
public static CommandLine getArgs(String[] args) { private static CommandLine getArgs(String[] args) {
BasicParser parser = new BasicParser(); BasicParser parser = new BasicParser();
try { try {
CommandLine cl = parser.parse(getOptions(), args, false); return parser.parse(getOptions(), args, false);
return cl;
} catch (ParseException e) { } catch (ParseException e) {
logger.error("[!] Error while parsing command-line arguments: " + Arrays.toString(args), e); logger.error("[!] Error while parsing command-line arguments: " + Arrays.toString(args), e);
System.exit(-1); System.exit(-1);
@ -244,12 +243,7 @@ public class App {
if (HISTORY.toList().size() == 0) { if (HISTORY.toList().size() == 0) {
// Loaded from config, still no entries. // Loaded from config, still no entries.
// Guess rip history based on rip folder // Guess rip history based on rip folder
String[] dirs = Utils.getWorkingDirectory().list(new FilenameFilter() { String[] dirs = Utils.getWorkingDirectory().list((dir, file) -> new File(dir.getAbsolutePath() + File.separator + file).isDirectory());
@Override
public boolean accept(File dir, String file) {
return new File(dir.getAbsolutePath() + File.separator + file).isDirectory();
}
});
for (String dir : dirs) { for (String dir : dirs) {
String url = RipUtils.urlFromDirectoryName(dir); String url = RipUtils.urlFromDirectoryName(dir);
if (url != null) { if (url != null) {

View File

@ -17,27 +17,27 @@ import com.rarchives.ripme.utils.Utils;
*/ */
public abstract class AbstractHTMLRipper extends AlbumRipper { public abstract class AbstractHTMLRipper extends AlbumRipper {
public AbstractHTMLRipper(URL url) throws IOException { protected AbstractHTMLRipper(URL url) throws IOException {
super(url); super(url);
} }
public abstract String getDomain(); protected abstract String getDomain();
public abstract String getHost(); public abstract String getHost();
public abstract Document getFirstPage() throws IOException; protected abstract Document getFirstPage() throws IOException;
public Document getNextPage(Document doc) throws IOException { public Document getNextPage(Document doc) throws IOException {
return null; return null;
} }
public abstract List<String> getURLsFromPage(Document page); protected abstract List<String> getURLsFromPage(Document page);
public List<String> getDescriptionsFromPage(Document doc) throws IOException { protected List<String> getDescriptionsFromPage(Document doc) throws IOException {
throw new IOException("getDescriptionsFromPage not implemented"); // Do I do this or make an abstract function? throw new IOException("getDescriptionsFromPage not implemented"); // Do I do this or make an abstract function?
} }
public abstract void downloadURL(URL url, int index); protected abstract void downloadURL(URL url, int index);
public DownloadThreadPool getThreadPool() { protected DownloadThreadPool getThreadPool() {
return null; return null;
} }
public boolean keepSortOrder() { protected boolean keepSortOrder() {
return true; return true;
} }
@ -50,13 +50,13 @@ public abstract class AbstractHTMLRipper extends AlbumRipper {
public URL sanitizeURL(URL url) throws MalformedURLException { public URL sanitizeURL(URL url) throws MalformedURLException {
return url; return url;
} }
public boolean hasDescriptionSupport() { protected boolean hasDescriptionSupport() {
return false; return false;
} }
public String[] getDescription(String url,Document page) throws IOException { protected String[] getDescription(String url, Document page) throws IOException {
throw new IOException("getDescription not implemented"); // Do I do this or make an abstract function? throw new IOException("getDescription not implemented"); // Do I do this or make an abstract function?
} }
public int descSleepTime() { protected int descSleepTime() {
return 100; return 100;
} }
@Override @Override
@ -140,7 +140,7 @@ public abstract class AbstractHTMLRipper extends AlbumRipper {
} }
waitForThreads(); waitForThreads();
} }
public String fileNameFromURL(URL url) { private String fileNameFromURL(URL url) {
String saveAs = url.toExternalForm(); String saveAs = url.toExternalForm();
if (saveAs.substring(saveAs.length() - 1) == "/") { saveAs = saveAs.substring(0,saveAs.length() - 1) ;} if (saveAs.substring(saveAs.length() - 1) == "/") { saveAs = saveAs.substring(0,saveAs.length() - 1) ;}
saveAs = saveAs.substring(saveAs.lastIndexOf('/')+1); saveAs = saveAs.substring(saveAs.lastIndexOf('/')+1);
@ -154,7 +154,7 @@ public abstract class AbstractHTMLRipper extends AlbumRipper {
String saveAs = fileNameFromURL(url); String saveAs = fileNameFromURL(url);
return saveText(url,subdirectory,text,index,saveAs); return saveText(url,subdirectory,text,index,saveAs);
} }
public boolean saveText(URL url, String subdirectory, String text, int index, String fileName) { private boolean saveText(URL url, String subdirectory, String text, int index, String fileName) {
// Not the best for some cases, like FurAffinity. Overridden there. // Not the best for some cases, like FurAffinity. Overridden there.
try { try {
stopCheck(); stopCheck();
@ -189,7 +189,7 @@ public abstract class AbstractHTMLRipper extends AlbumRipper {
} }
return true; return true;
} }
public String getPrefix(int index) { protected String getPrefix(int index) {
String prefix = ""; String prefix = "";
if (keepSortOrder() && Utils.getConfigBoolean("download.save_order", true)) { if (keepSortOrder() && Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index); prefix = String.format("%03d_", index);

View File

@ -15,24 +15,24 @@ import com.rarchives.ripme.utils.Utils;
*/ */
public abstract class AbstractJSONRipper extends AlbumRipper { public abstract class AbstractJSONRipper extends AlbumRipper {
public AbstractJSONRipper(URL url) throws IOException { protected AbstractJSONRipper(URL url) throws IOException {
super(url); super(url);
} }
public abstract String getDomain(); protected abstract String getDomain();
public abstract String getHost(); public abstract String getHost();
public abstract JSONObject getFirstPage() throws IOException; protected abstract JSONObject getFirstPage() throws IOException;
public JSONObject getNextPage(JSONObject doc) throws IOException { protected JSONObject getNextPage(JSONObject doc) throws IOException {
throw new IOException("getNextPage not implemented"); throw new IOException("getNextPage not implemented");
} }
public abstract List<String> getURLsFromJSON(JSONObject json); protected abstract List<String> getURLsFromJSON(JSONObject json);
public abstract void downloadURL(URL url, int index); protected abstract void downloadURL(URL url, int index);
public DownloadThreadPool getThreadPool() { private DownloadThreadPool getThreadPool() {
return null; return null;
} }
public boolean keepSortOrder() { protected boolean keepSortOrder() {
return true; return true;
} }
@ -96,7 +96,7 @@ public abstract class AbstractJSONRipper extends AlbumRipper {
waitForThreads(); waitForThreads();
} }
public String getPrefix(int index) { protected String getPrefix(int index) {
String prefix = ""; String prefix = "";
if (keepSortOrder() && Utils.getConfigBoolean("download.save_order", true)) { if (keepSortOrder() && Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index); prefix = String.format("%03d_", index);

View File

@ -32,10 +32,10 @@ public abstract class AbstractRipper
protected URL url; protected URL url;
protected File workingDir; protected File workingDir;
protected DownloadThreadPool threadPool; DownloadThreadPool threadPool;
protected RipStatusHandler observer = null; RipStatusHandler observer = null;
protected boolean completed = true; private boolean completed = true;
public abstract void rip() throws IOException; public abstract void rip() throws IOException;
public abstract String getHost(); public abstract String getHost();
@ -110,9 +110,9 @@ public abstract class AbstractRipper
* The cookies to send to the server while downloading this file. * The cookies to send to the server while downloading this file.
* @return * @return
*/ */
public abstract boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies); protected abstract boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String, String> cookies);
public boolean addURLToDownload(URL url, String prefix, String subdirectory, String referrer, Map<String,String> cookies) { protected boolean addURLToDownload(URL url, String prefix, String subdirectory, String referrer, Map<String, String> cookies) {
try { try {
stopCheck(); stopCheck();
} catch (IOException e) { } catch (IOException e) {
@ -159,7 +159,7 @@ public abstract class AbstractRipper
* Sub-directory of the working directory to save the images to. * Sub-directory of the working directory to save the images to.
* @return True on success, flase on failure. * @return True on success, flase on failure.
*/ */
public boolean addURLToDownload(URL url, String prefix, String subdirectory) { protected boolean addURLToDownload(URL url, String prefix, String subdirectory) {
return addURLToDownload(url, prefix, subdirectory, null, null); return addURLToDownload(url, prefix, subdirectory, null, null);
} }
@ -172,7 +172,7 @@ public abstract class AbstractRipper
* Text to append to saved filename. * Text to append to saved filename.
* @return True on success, flase on failure. * @return True on success, flase on failure.
*/ */
public boolean addURLToDownload(URL url, String prefix) { protected boolean addURLToDownload(URL url, String prefix) {
// Use empty subdirectory // Use empty subdirectory
return addURLToDownload(url, prefix, ""); return addURLToDownload(url, prefix, "");
} }
@ -223,14 +223,14 @@ public abstract class AbstractRipper
/** /**
* @return Number of files downloaded. * @return Number of files downloaded.
*/ */
public int getCount() { int getCount() {
return 1; return 1;
} }
/** /**
* Notifies observers and updates state if all files have been ripped. * Notifies observers and updates state if all files have been ripped.
*/ */
protected void checkIfComplete() { void checkIfComplete() {
if (observer == null) { if (observer == null) {
logger.debug("observer is null"); logger.debug("observer is null");
return; return;
@ -320,10 +320,10 @@ public abstract class AbstractRipper
* @throws Exception * @throws Exception
*/ */
public static List<Constructor<?>> getRipperConstructors(String pkg) throws Exception { public static List<Constructor<?>> getRipperConstructors(String pkg) throws Exception {
List<Constructor<?>> constructors = new ArrayList<Constructor<?>>(); List<Constructor<?>> constructors = new ArrayList<>();
for (Class<?> clazz : Utils.getClassesForPackage(pkg)) { for (Class<?> clazz : Utils.getClassesForPackage(pkg)) {
if (AbstractRipper.class.isAssignableFrom(clazz)) { if (AbstractRipper.class.isAssignableFrom(clazz)) {
constructors.add( (Constructor<?>) clazz.getConstructor(URL.class) ); constructors.add(clazz.getConstructor(URL.class));
} }
} }
return constructors; return constructors;
@ -355,10 +355,6 @@ public abstract class AbstractRipper
logger.error("Got exception while running ripper:", e); logger.error("Got exception while running ripper:", e);
waitForThreads(); waitForThreads();
sendUpdate(STATUS.RIP_ERRORED, "HTTP status code " + e.getStatusCode() + " for URL " + e.getUrl()); sendUpdate(STATUS.RIP_ERRORED, "HTTP status code " + e.getStatusCode() + " for URL " + e.getUrl());
} catch (IOException e) {
logger.error("Got exception while running ripper:", e);
waitForThreads();
sendUpdate(STATUS.RIP_ERRORED, e.getMessage());
} catch (Exception e) { } catch (Exception e) {
logger.error("Got exception while running ripper:", e); logger.error("Got exception while running ripper:", e);
waitForThreads(); waitForThreads();
@ -368,7 +364,7 @@ public abstract class AbstractRipper
} }
} }
public void cleanup() { private void cleanup() {
if (this.workingDir.list().length == 0) { if (this.workingDir.list().length == 0) {
// No files, delete the dir // No files, delete the dir
logger.info("Deleting empty directory " + this.workingDir); logger.info("Deleting empty directory " + this.workingDir);
@ -379,7 +375,7 @@ public abstract class AbstractRipper
} }
} }
public boolean sleep(int milliseconds) { protected boolean sleep(int milliseconds) {
try { try {
logger.debug("Sleeping " + milliseconds + "ms"); logger.debug("Sleeping " + milliseconds + "ms");
Thread.sleep(milliseconds); Thread.sleep(milliseconds);
@ -402,7 +398,7 @@ public abstract class AbstractRipper
logger.debug("THIS IS A TEST RIP"); logger.debug("THIS IS A TEST RIP");
thisIsATest = true; thisIsATest = true;
} }
public boolean isThisATest() { protected boolean isThisATest() {
return thisIsATest; return thisIsATest;
} }
} }

View File

@ -15,11 +15,11 @@ import com.rarchives.ripme.utils.Utils;
public abstract class AlbumRipper extends AbstractRipper { public abstract class AlbumRipper extends AbstractRipper {
protected Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<URL, File>()); private Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<URL, File>());
protected Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, File>()); private Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, File>());
protected Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<URL, String>()); private Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<URL, String>());
public AlbumRipper(URL url) throws IOException { protected AlbumRipper(URL url) throws IOException {
super(url); super(url);
} }
@ -29,7 +29,7 @@ public abstract class AlbumRipper extends AbstractRipper {
public abstract String getHost(); public abstract String getHost();
public abstract String getGID(URL url) throws MalformedURLException; public abstract String getGID(URL url) throws MalformedURLException;
public boolean allowDuplicates() { protected boolean allowDuplicates() {
return false; return false;
} }
@ -95,7 +95,7 @@ public abstract class AlbumRipper extends AbstractRipper {
* @return * @return
* True on success * True on success
*/ */
public boolean addURLToDownload(URL url) { protected boolean addURLToDownload(URL url) {
// Use empty prefix and empty subdirectory // Use empty prefix and empty subdirectory
return addURLToDownload(url, "", ""); return addURLToDownload(url, "", "");
} }

View File

@ -24,12 +24,12 @@ import com.rarchives.ripme.utils.Utils;
* Thread for downloading files. * Thread for downloading files.
* Includes retry logic, observer notifications, and other goodies. * Includes retry logic, observer notifications, and other goodies.
*/ */
public class DownloadFileThread extends Thread { class DownloadFileThread extends Thread {
private static final Logger logger = Logger.getLogger(DownloadFileThread.class); private static final Logger logger = Logger.getLogger(DownloadFileThread.class);
private String referrer = ""; private String referrer = "";
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
private URL url; private URL url;
private File saveAs; private File saveAs;

View File

@ -20,7 +20,7 @@ import com.rarchives.ripme.utils.Utils;
* Thread for downloading files. * Thread for downloading files.
* Includes retry logic, observer notifications, and other goodies. * Includes retry logic, observer notifications, and other goodies.
*/ */
public class DownloadVideoThread extends Thread { class DownloadVideoThread extends Thread {
private static final Logger logger = Logger.getLogger(DownloadVideoThread.class); private static final Logger logger = Logger.getLogger(DownloadVideoThread.class);

View File

@ -8,7 +8,7 @@ import java.net.URL;
* I have no idea why I made this interface. Everything is captured within the AbstractRipper. * I have no idea why I made this interface. Everything is captured within the AbstractRipper.
* Oh well, here's to encapsulation and abstraction! (raises glass) * Oh well, here's to encapsulation and abstraction! (raises glass)
*/ */
public interface RipperInterface { interface RipperInterface {
void rip() throws IOException; void rip() throws IOException;
boolean canRip(URL url); boolean canRip(URL url);
URL sanitizeURL(URL url) throws MalformedURLException; URL sanitizeURL(URL url) throws MalformedURLException;

View File

@ -16,7 +16,7 @@ public abstract class VideoRipper extends AbstractRipper {
private int bytesTotal = 1, private int bytesTotal = 1,
bytesCompleted = 1; bytesCompleted = 1;
public VideoRipper(URL url) throws IOException { protected VideoRipper(URL url) throws IOException {
super(url); super(url);
} }

View File

@ -23,7 +23,7 @@ import java.util.HashMap;
public class AerisdiesRipper extends AbstractHTMLRipper { public class AerisdiesRipper extends AbstractHTMLRipper {
private Document albumDoc = null; private Document albumDoc = null;
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
public AerisdiesRipper(URL url) throws IOException { public AerisdiesRipper(URL url) throws IOException {
@ -74,7 +74,7 @@ public class AerisdiesRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Elements albumElements = page.select("div.imgbox > a > img"); Elements albumElements = page.select("div.imgbox > a > img");
for (Element imageBox : albumElements) { for (Element imageBox : albumElements) {
String imageUrl = imageBox.attr("src"); String imageUrl = imageBox.attr("src");

View File

@ -66,7 +66,7 @@ public class BcfakesRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("div.ngg-gallery-thumbnail > a > img")) { for (Element thumb : doc.select("div.ngg-gallery-thumbnail > a > img")) {
String imageURL = thumb.attr("src"); String imageURL = thumb.attr("src");
imageURL = imageURL.replace("thumbs/thumbs_", ""); imageURL = imageURL.replace("thumbs/thumbs_", "");

View File

@ -33,7 +33,7 @@ public class ButttoucherRipper extends AbstractHTMLRipper {
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p; Matcher m; Pattern p; Matcher m;
p = Pattern.compile("^.*butttoucher.com/users/([a-zA-Z0-9_\\-]{1,}).*$"); p = Pattern.compile("^.*butttoucher.com/users/([a-zA-Z0-9_\\-]+).*$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
@ -51,7 +51,7 @@ public class ButttoucherRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> thumbs = new ArrayList<String>(); List<String> thumbs = new ArrayList<>();
for (Element thumb : page.select(".thumb img")) { for (Element thumb : page.select(".thumb img")) {
if (!thumb.hasAttr("src")) { if (!thumb.hasAttr("src")) {
continue; continue;

View File

@ -71,7 +71,7 @@ public class CfakeRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Element el : doc.select("table.display > tbody > tr > td > table > tbody > tr > td > a")) { for (Element el : doc.select("table.display > tbody > tr > td > table > tbody > tr > td > a")) {
if (el.attr("href").contains("upload")) { if (el.attr("href").contains("upload")) {
return result; return result;

View File

@ -18,7 +18,7 @@ import com.rarchives.ripme.utils.Http;
import com.rarchives.ripme.utils.RipUtils; import com.rarchives.ripme.utils.RipUtils;
public class ChanRipper extends AbstractHTMLRipper { public class ChanRipper extends AbstractHTMLRipper {
public static List<ChanSite> explicit_domains = Arrays.asList( private static List<ChanSite> explicit_domains = Arrays.asList(
new ChanSite(Arrays.asList("boards.4chan.org"), Arrays.asList("4cdn.org", "is.4chan.org", "is2.4chan.org")), new ChanSite(Arrays.asList("boards.4chan.org"), Arrays.asList("4cdn.org", "is.4chan.org", "is2.4chan.org")),
new ChanSite(Arrays.asList("archive.moe"), Arrays.asList("data.archive.moe")), new ChanSite(Arrays.asList("archive.moe"), Arrays.asList("data.archive.moe")),
new ChanSite(Arrays.asList("4archive.org"), Arrays.asList("imgur.com")), new ChanSite(Arrays.asList("4archive.org"), Arrays.asList("imgur.com")),
@ -26,15 +26,15 @@ public class ChanRipper extends AbstractHTMLRipper {
new ChanSite(Arrays.asList("fgts.jp"), Arrays.asList("dat.fgtsi.org")) new ChanSite(Arrays.asList("fgts.jp"), Arrays.asList("dat.fgtsi.org"))
); );
public static List<String> url_piece_blacklist = Arrays.asList( private static List<String> url_piece_blacklist = Arrays.asList(
"=http", "=http",
"http://imgops.com/", "http://imgops.com/",
"iqdb.org", "iqdb.org",
"saucenao.com" "saucenao.com"
); );
public ChanSite chanSite; private ChanSite chanSite;
public Boolean generalChanSite = true; private Boolean generalChanSite = true;
public ChanRipper(URL url) throws IOException { public ChanRipper(URL url) throws IOException {
super(url); super(url);
@ -143,7 +143,7 @@ public class ChanRipper extends AbstractHTMLRipper {
} }
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Pattern p; Matcher m; Pattern p; Matcher m;
for (Element link : page.select("a")) { for (Element link : page.select("a")) {
if (!link.hasAttr("href")) { if (!link.hasAttr("href")) {

View File

@ -21,7 +21,7 @@ import com.rarchives.ripme.utils.Http;
public class CheebyRipper extends AbstractHTMLRipper { public class CheebyRipper extends AbstractHTMLRipper {
private int offset = 0; private int offset = 0;
private Map<String, Integer> albumSets = new HashMap<String, Integer>(); private Map<String, Integer> albumSets = new HashMap<>();
public CheebyRipper(URL url) throws IOException { public CheebyRipper(URL url) throws IOException {
super(url); super(url);
@ -81,8 +81,8 @@ public class CheebyRipper extends AbstractHTMLRipper {
return null; return null;
} }
public List<Image> getImagesFromPage(Document page) { private List<Image> getImagesFromPage(Document page) {
List<Image> imageURLs = new ArrayList<Image>(); List<Image> imageURLs = new ArrayList<>();
for (Element image : page.select("div.i a img")) { for (Element image : page.select("div.i a img")) {
// Get image URL // Get image URL
String imageURL = image.attr("src"); String imageURL = image.attr("src");
@ -171,7 +171,7 @@ public class CheebyRipper extends AbstractHTMLRipper {
private class Image { private class Image {
String url, prefix; String url, prefix;
int index; int index;
public Image(String url, String prefix, int index) { Image(String url, String prefix, int index) {
this.url = url; this.url = url;
this.prefix = prefix; this.prefix = prefix;
this.index = index; this.index = index;

View File

@ -22,23 +22,21 @@ public class CheveretoRipper extends AbstractHTMLRipper {
super(url); super(url);
} }
public static List<String> explicit_domains_1 = Arrays.asList("hushpix.com", "tag-fox.com"); private static List<String> explicit_domains_1 = Arrays.asList("hushpix.com", "tag-fox.com");
@Override @Override
public String getHost() { public String getHost() {
String host = url.toExternalForm().split("/")[2]; return url.toExternalForm().split("/")[2];
return host;
} }
@Override @Override
public String getDomain() { public String getDomain() {
String host = url.toExternalForm().split("/")[2]; return url.toExternalForm().split("/")[2];
return host;
} }
@Override @Override
public boolean canRip(URL url) { public boolean canRip(URL url) {
String url_name = url.toExternalForm(); String url_name = url.toExternalForm();
if (explicit_domains_1.contains(url_name.split("/")[2]) == true) { if (explicit_domains_1.contains(url_name.split("/")[2])) {
Pattern pa = Pattern.compile("(?:https?://)?(?:www\\.)?[a-z1-9-]*\\.[a-z1-9]*/album/([a-zA-Z1-9]*)/?$"); Pattern pa = Pattern.compile("(?:https?://)?(?:www\\.)?[a-z1-9-]*\\.[a-z1-9]*/album/([a-zA-Z1-9]*)/?$");
Matcher ma = pa.matcher(url.toExternalForm()); Matcher ma = pa.matcher(url.toExternalForm());
if (ma.matches()) { if (ma.matches()) {
@ -103,7 +101,7 @@ public class CheveretoRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Element el : doc.select("a.image-container > img")) { for (Element el : doc.select("a.image-container > img")) {
String imageSource = el.attr("src"); String imageSource = el.attr("src");
// We remove the .md from images so we download the full size image // We remove the .md from images so we download the full size image

View File

@ -49,7 +49,7 @@ public class DatwinRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("img.attachment-thumbnail")) { for (Element thumb : doc.select("img.attachment-thumbnail")) {
String image = thumb.attr("src"); String image = thumb.attr("src");
image = image.replaceAll("-\\d{1,3}x\\d{1,3}", ""); image = image.replaceAll("-\\d{1,3}x\\d{1,3}", "");

View File

@ -14,6 +14,7 @@ import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.rarchives.ripme.ripper.AbstractRipper;
import org.jsoup.Connection.Method; import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response; import org.jsoup.Connection.Response;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
@ -32,8 +33,8 @@ public class DeviantartRipper extends AbstractHTMLRipper {
private static final int PAGE_SLEEP_TIME = 3000, private static final int PAGE_SLEEP_TIME = 3000,
IMAGE_SLEEP_TIME = 2000; IMAGE_SLEEP_TIME = 2000;
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
private Set<String> triedURLs = new HashSet<String>(); private Set<String> triedURLs = new HashSet<>();
public DeviantartRipper(URL url) throws IOException { public DeviantartRipper(URL url) throws IOException {
super(url); super(url);
@ -63,7 +64,7 @@ public class DeviantartRipper extends AbstractHTMLRipper {
u += "gallery/?"; u += "gallery/?";
} }
Pattern p = Pattern.compile("^https?://([a-zA-Z0-9\\-]{1,})\\.deviantart\\.com/favou?rites/([0-9]+)/*?$"); Pattern p = Pattern.compile("^https?://([a-zA-Z0-9\\-]+)\\.deviantart\\.com/favou?rites/([0-9]+)/*?$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) { if (!m.matches()) {
String subdir = "/"; String subdir = "/";
@ -88,18 +89,18 @@ public class DeviantartRipper extends AbstractHTMLRipper {
return m.group(1); return m.group(1);
} }
} }
p = Pattern.compile("^https?://([a-zA-Z0-9\\-]{1,})\\.deviantart\\.com/gallery/([0-9]{1,}).*$"); p = Pattern.compile("^https?://([a-zA-Z0-9\\-]+)\\.deviantart\\.com/gallery/([0-9]+).*$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
// Subgallery // Subgallery
return m.group(1) + "_" + m.group(2); return m.group(1) + "_" + m.group(2);
} }
p = Pattern.compile("^https?://([a-zA-Z0-9\\-]{1,})\\.deviantart\\.com/favou?rites/([0-9]+)/.*?$"); p = Pattern.compile("^https?://([a-zA-Z0-9\\-]+)\\.deviantart\\.com/favou?rites/([0-9]+)/.*?$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1) + "_faves_" + m.group(2); return m.group(1) + "_faves_" + m.group(2);
} }
p = Pattern.compile("^https?://([a-zA-Z0-9\\-]{1,})\\.deviantart\\.com/favou?rites/?$"); p = Pattern.compile("^https?://([a-zA-Z0-9\\-]+)\\.deviantart\\.com/favou?rites/?$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
// Subgallery // Subgallery
@ -121,14 +122,14 @@ public class DeviantartRipper extends AbstractHTMLRipper {
.cookies(cookies) .cookies(cookies)
.get(); .get();
} }
public String jsonToImage(Document page,String id) { private String jsonToImage(Document page, String id) {
Elements js = page.select("script[type=\"text/javascript\"]"); Elements js = page.select("script[type=\"text/javascript\"]");
for (Element tag : js) { for (Element tag : js) {
if (tag.html().contains("window.__pageload")) { if (tag.html().contains("window.__pageload")) {
try { try {
String script = tag.html(); String script = tag.html();
script = script.substring(script.indexOf("window.__pageload")); script = script.substring(script.indexOf("window.__pageload"));
if (script.indexOf(id) < 0) { if (!script.contains(id)) {
continue; continue;
} }
script = script.substring(script.indexOf(id)); script = script.substring(script.indexOf(id));
@ -144,7 +145,7 @@ public class DeviantartRipper extends AbstractHTMLRipper {
} }
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
// Iterate over all thumbnails // Iterate over all thumbnails
for (Element thumb : page.select("div.zones-container span.thumb")) { for (Element thumb : page.select("div.zones-container span.thumb")) {
@ -194,7 +195,7 @@ public class DeviantartRipper extends AbstractHTMLRipper {
} }
@Override @Override
public List<String> getDescriptionsFromPage(Document page) { public List<String> getDescriptionsFromPage(Document page) {
List<String> textURLs = new ArrayList<String>(); List<String> textURLs = new ArrayList<>();
// Iterate over all thumbnails // Iterate over all thumbnails
for (Element thumb : page.select("div.zones-container span.thumb")) { for (Element thumb : page.select("div.zones-container span.thumb")) {
logger.info(thumb.attr("href")); logger.info(thumb.attr("href"));
@ -257,9 +258,9 @@ public class DeviantartRipper extends AbstractHTMLRipper {
* @return Full-size image URL * @return Full-size image URL
* @throws Exception If it can't find the full-size URL * @throws Exception If it can't find the full-size URL
*/ */
public static String thumbToFull(String thumb, boolean throwException) throws Exception { private static String thumbToFull(String thumb, boolean throwException) throws Exception {
thumb = thumb.replace("http://th", "http://fc"); thumb = thumb.replace("http://th", "http://fc");
List<String> fields = new ArrayList<String>(Arrays.asList(thumb.split("/"))); List<String> fields = new ArrayList<>(Arrays.asList(thumb.split("/")));
fields.remove(4); fields.remove(4);
if (!fields.get(4).equals("f") && throwException) { if (!fields.get(4).equals("f") && throwException) {
// Not a full-size image // Not a full-size image
@ -339,7 +340,7 @@ public class DeviantartRipper extends AbstractHTMLRipper {
* @param page Page the thumbnail is retrieved from * @param page Page the thumbnail is retrieved from
* @return Highest-resolution version of the image based on thumbnail URL and the page. * @return Highest-resolution version of the image based on thumbnail URL and the page.
*/ */
public String smallToFull(String thumb, String page) { private String smallToFull(String thumb, String page) {
try { try {
// Fetch the image page // Fetch the image page
Response resp = Http.url(page) Response resp = Http.url(page)
@ -373,7 +374,7 @@ public class DeviantartRipper extends AbstractHTMLRipper {
} }
cookieString = cookieString.substring(0,cookieString.length() - 1); cookieString = cookieString.substring(0,cookieString.length() - 1);
con.setRequestProperty("Cookie",cookieString); con.setRequestProperty("Cookie",cookieString);
con.setRequestProperty("User-Agent",this.USER_AGENT); con.setRequestProperty("User-Agent", USER_AGENT);
con.setInstanceFollowRedirects(true); con.setInstanceFollowRedirects(true);
con.connect(); con.connect();
int code = con.getResponseCode(); int code = con.getResponseCode();
@ -406,7 +407,7 @@ public class DeviantartRipper extends AbstractHTMLRipper {
*/ */
private Map<String, String> loginToDeviantart() throws IOException { private Map<String, String> loginToDeviantart() throws IOException {
// Populate postData fields // Populate postData fields
Map<String,String> postData = new HashMap<String,String>(); Map<String,String> postData = new HashMap<>();
String username = Utils.getConfigString("deviantart.username", new String(Base64.decode("Z3JhYnB5"))); String username = Utils.getConfigString("deviantart.username", new String(Base64.decode("Z3JhYnB5")));
String password = Utils.getConfigString("deviantart.password", new String(Base64.decode("ZmFrZXJz"))); String password = Utils.getConfigString("deviantart.password", new String(Base64.decode("ZmFrZXJz")));
if (username == null || password == null) { if (username == null || password == null) {

View File

@ -72,7 +72,7 @@ public class DrawcrowdRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : page.select("div.item.asset img")) { for (Element thumb : page.select("div.item.asset img")) {
String image = thumb.attr("src"); String image = thumb.attr("src");
image = image image = image

View File

@ -18,11 +18,11 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
public class E621Ripper extends AbstractHTMLRipper { public class E621Ripper extends AbstractHTMLRipper {
public static final int POOL_IMAGES_PER_PAGE = 24; private static final int POOL_IMAGES_PER_PAGE = 24;
private DownloadThreadPool e621ThreadPool = new DownloadThreadPool("e621"); private DownloadThreadPool e621ThreadPool = new DownloadThreadPool("e621");
public E621Ripper(URL url) throws IOException { private E621Ripper(URL url) throws IOException {
super(url); super(url);
} }
@ -53,7 +53,7 @@ public class E621Ripper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
Elements elements = page.select("#post-list .thumb a,#pool-show .thumb a"); Elements elements = page.select("#post-list .thumb a,#pool-show .thumb a");
List<String> res = new ArrayList<String>(elements.size()); List<String> res = new ArrayList<>(elements.size());
if (page.getElementById("pool-show") != null) { if (page.getElementById("pool-show") != null) {
int index = 0; int index = 0;
@ -92,23 +92,21 @@ public class E621Ripper extends AbstractHTMLRipper {
@Override @Override
public void downloadURL(final URL url, int index) { public void downloadURL(final URL url, int index) {
e621ThreadPool.addThread(new Thread(new Runnable() { e621ThreadPool.addThread(new Thread(() -> {
public void run() { try {
try { Document page = Http.url(url).get();
Document page = Http.url(url).get(); Element e = page.getElementById("image");
Element e = page.getElementById("image");
if (e != null) { if (e != null) {
addURLToDownload(new URL(e.absUrl("src")), Utils.getConfigBoolean("download.save_order", true) ? url.getRef() + "-" : ""); addURLToDownload(new URL(e.absUrl("src")), Utils.getConfigBoolean("download.save_order", true) ? url.getRef() + "-" : "");
} else if ((e = page.select(".content object>param[name=\"movie\"]").first()) != null) { } else if ((e = page.select(".content object>param[name=\"movie\"]").first()) != null) {
addURLToDownload(new URL(e.absUrl("value")), Utils.getConfigBoolean("download.save_order", true) ? url.getRef() + "-" : ""); addURLToDownload(new URL(e.absUrl("value")), Utils.getConfigBoolean("download.save_order", true) ? url.getRef() + "-" : "");
} else { } else {
Logger.getLogger(E621Ripper.class.getName()).log(Level.WARNING, "Unsupported media type - please report to program author: " + url.toString()); Logger.getLogger(E621Ripper.class.getName()).log(Level.WARNING, "Unsupported media type - please report to program author: " + url.toString());
}
} catch (IOException ex) {
Logger.getLogger(E621Ripper.class.getName()).log(Level.SEVERE, null, ex);
} }
} catch (IOException ex) {
Logger.getLogger(E621Ripper.class.getName()).log(Level.SEVERE, null, ex);
} }
})); }));
} }

View File

@ -39,7 +39,7 @@ public class EHentaiRipper extends AbstractHTMLRipper {
// Current HTML document // Current HTML document
private Document albumDoc = null; private Document albumDoc = null;
private static final Map<String,String> cookies = new HashMap<String,String>(); private static final Map<String,String> cookies = new HashMap<>();
static { static {
cookies.put("nw", "1"); cookies.put("nw", "1");
cookies.put("tip", "1"); cookies.put("tip", "1");
@ -162,7 +162,7 @@ public class EHentaiRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Elements thumbs = page.select("#gdt > .gdtm a"); Elements thumbs = page.select("#gdt > .gdtm a");
// Iterate over images on page // Iterate over images on page
for (Element thumb : thumbs) { for (Element thumb : thumbs) {
@ -193,7 +193,7 @@ public class EHentaiRipper extends AbstractHTMLRipper {
private int index; private int index;
private File workingDir; private File workingDir;
public EHentaiImageThread(URL url, int index, File workingDir) { EHentaiImageThread(URL url, int index, File workingDir) {
super(); super();
this.url = url; this.url = url;
this.index = index; this.index = index;

View File

@ -23,10 +23,10 @@ import com.rarchives.ripme.utils.Http;
public class EightmusesRipper extends AbstractHTMLRipper { public class EightmusesRipper extends AbstractHTMLRipper {
private Document albumDoc = null; private Document albumDoc = null;
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
// TODO put up a wiki page on using maps to store titles // TODO put up a wiki page on using maps to store titles
// the map for storing the title of each album when downloading sub albums // the map for storing the title of each album when downloading sub albums
private Map<URL,String> urlTitles = new HashMap<URL,String>(); private Map<URL,String> urlTitles = new HashMap<>();
private Boolean rippingSubalbums = false; private Boolean rippingSubalbums = false;
@ -81,7 +81,7 @@ public class EightmusesRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
// get the first image link on the page and check if the last char in it is a number // get the first image link on the page and check if the last char in it is a number
// if it is a number then we're ripping a comic if not it's a subalbum // if it is a number then we're ripping a comic if not it's a subalbum
String firstImageLink = page.select("div.gallery > a.t-hover").first().attr("href"); String firstImageLink = page.select("div.gallery > a.t-hover").first().attr("href");
@ -136,7 +136,6 @@ public class EightmusesRipper extends AbstractHTMLRipper {
imageURLs.addAll(subalbumImages); imageURLs.addAll(subalbumImages);
} catch (IOException e) { } catch (IOException e) {
logger.warn("Error while loading subalbum " + subUrl, e); logger.warn("Error while loading subalbum " + subUrl, e);
continue;
} }
} }
} }
@ -182,8 +181,7 @@ public class EightmusesRipper extends AbstractHTMLRipper {
Element fullSizeImage = doc.select(".photo").first(); // Select the "photo" element from the page (there should only be 1) Element fullSizeImage = doc.select(".photo").first(); // Select the "photo" element from the page (there should only be 1)
// subdir is the sub dir the cdn has the image stored in // subdir is the sub dir the cdn has the image stored in
String subdir = doc.select("input#imageDir").first().attr("value"); String subdir = doc.select("input#imageDir").first().attr("value");
String path = "https://cdn.ampproject.org/i/s/www.8muses.com/" + subdir + "small/" + fullSizeImage.children().select("#imageName").attr("value"); // Append the path to the fullsize image file to the standard prefix return "https://cdn.ampproject.org/i/s/www.8muses.com/" + subdir + "small/" + fullSizeImage.children().select("#imageName").attr("value");
return path;
} }
@Override @Override

View File

@ -71,19 +71,13 @@ public class EroShareRipper extends AbstractHTMLRipper {
Pattern p_eroshare_profile = Pattern.compile("^https?://eroshare.com/u/([a-zA-Z0-9\\-_]+)/?$"); Pattern p_eroshare_profile = Pattern.compile("^https?://eroshare.com/u/([a-zA-Z0-9\\-_]+)/?$");
Matcher m_eroshare_profile = p_eroshare_profile.matcher(url.toExternalForm()); Matcher m_eroshare_profile = p_eroshare_profile.matcher(url.toExternalForm());
if (m_eroshare_profile.matches()) { return m_eroshare_profile.matches();
return true;
}
return false;
} }
public boolean is_profile(URL url) { private boolean is_profile(URL url) {
Pattern pa = Pattern.compile("^https?://eroshae.com/u/([a-zA-Z0-9\\-_]+)/?$"); Pattern pa = Pattern.compile("^https?://eroshae.com/u/([a-zA-Z0-9\\-_]+)/?$");
Matcher ma = pa.matcher(url.toExternalForm()); Matcher ma = pa.matcher(url.toExternalForm());
if (ma.matches()) { return ma.matches();
return true;
}
return false;
} }
@Override @Override
@ -103,7 +97,7 @@ public class EroShareRipper extends AbstractHTMLRipper {
@Override @Override
public String getAlbumTitle(URL url) throws MalformedURLException { public String getAlbumTitle(URL url) throws MalformedURLException {
if (is_profile(url) == false) { if (!is_profile(url)) {
try { try {
// Attempt to use album title as GID // Attempt to use album title as GID
Element titleElement = getFirstPage().select("meta[property=og:title]").first(); Element titleElement = getFirstPage().select("meta[property=og:title]").first();
@ -122,7 +116,7 @@ public class EroShareRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> URLs = new ArrayList<String>(); List<String> URLs = new ArrayList<>();
//Pictures //Pictures
Elements imgs = doc.getElementsByTag("img"); Elements imgs = doc.getElementsByTag("img");
for (Element img : imgs) { for (Element img : imgs) {
@ -172,9 +166,7 @@ public class EroShareRipper extends AbstractHTMLRipper {
.ignoreContentType() .ignoreContentType()
.response(); .response();
Document doc = resp.parse(); return resp.parse();
return doc;
} }
@Override @Override
@ -214,7 +206,7 @@ public class EroShareRipper extends AbstractHTMLRipper {
Document doc = resp.parse(); Document doc = resp.parse();
List<URL> URLs = new ArrayList<URL>(); List<URL> URLs = new ArrayList<>();
//Pictures //Pictures
Elements imgs = doc.getElementsByTag("img"); Elements imgs = doc.getElementsByTag("img");
for (Element img : imgs) { for (Element img : imgs) {

View File

@ -68,7 +68,7 @@ public class EromeRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> URLs = new ArrayList<String>(); List<String> URLs = new ArrayList<>();
//Pictures //Pictures
Elements imgs = doc.select("div.img > img.img-front"); Elements imgs = doc.select("div.img > img.img-front");
for (Element img : imgs) { for (Element img : imgs) {
@ -92,9 +92,7 @@ public class EromeRipper extends AbstractHTMLRipper {
.ignoreContentType() .ignoreContentType()
.response(); .response();
Document doc = resp.parse(); return resp.parse();
return doc;
} }
@Override @Override
@ -115,7 +113,7 @@ public class EromeRipper extends AbstractHTMLRipper {
Document doc = resp.parse(); Document doc = resp.parse();
List<URL> URLs = new ArrayList<URL>(); List<URL> URLs = new ArrayList<>();
//Pictures //Pictures
Elements imgs = doc.getElementsByTag("img"); Elements imgs = doc.getElementsByTag("img");
for (Element img : imgs) { for (Element img : imgs) {

View File

@ -80,7 +80,7 @@ public class FapprovedRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element image : page.select("div.actual-image img")) { for (Element image : page.select("div.actual-image img")) {
String imageURL = image.attr("src"); String imageURL = image.attr("src");
if (imageURL.startsWith("//")) { if (imageURL.startsWith("//")) {

View File

@ -80,7 +80,7 @@ public class FineboxRipper extends AlbumRipper {
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://(www\\.)?(v|f)inebox\\.co/u/([a-zA-Z0-9]{1,}).*$"); Pattern p = Pattern.compile("^https?://(www\\.)?([vf])inebox\\.co/u/([a-zA-Z0-9]+).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) { if (!m.matches()) {
throw new MalformedURLException("Expected format: http://"+DOMAIN+"/u/USERNAME"); throw new MalformedURLException("Expected format: http://"+DOMAIN+"/u/USERNAME");

View File

@ -256,7 +256,7 @@ public class FivehundredpxRipper extends AbstractJSONRipper {
@Override @Override
public List<String> getURLsFromJSON(JSONObject json) { public List<String> getURLsFromJSON(JSONObject json) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
JSONArray photos = json.getJSONArray("photos"); JSONArray photos = json.getJSONArray("photos");
for (int i = 0; i < photos.length(); i++) { for (int i = 0; i < photos.length(); i++) {
if (super.isStopped()) { if (super.isStopped()) {

View File

@ -28,9 +28,9 @@ import com.rarchives.ripme.utils.Utils;
public class FlickrRipper extends AbstractHTMLRipper { public class FlickrRipper extends AbstractHTMLRipper {
private int page = 1; private int page = 1;
private Set<String> attempted = new HashSet<String>(); private Set<String> attempted = new HashSet<>();
private Document albumDoc = null; private Document albumDoc = null;
private DownloadThreadPool flickrThreadPool; private final DownloadThreadPool flickrThreadPool;
@Override @Override
public DownloadThreadPool getThreadPool() { public DownloadThreadPool getThreadPool() {
return flickrThreadPool; return flickrThreadPool;
@ -162,7 +162,7 @@ public class FlickrRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : page.select("a[data-track=photo-click]")) { for (Element thumb : page.select("a[data-track=photo-click]")) {
/* TODO find a way to persist the image title /* TODO find a way to persist the image title
String imageTitle = null; String imageTitle = null;
@ -215,7 +215,7 @@ public class FlickrRipper extends AbstractHTMLRipper {
.method(Method.GET) .method(Method.GET)
.execute(); .execute();
Document doc = resp.parse(); Document doc = resp.parse();
Map<String,String> postData = new HashMap<String,String>(); Map<String,String> postData = new HashMap<>();
for (Element input : doc.select("input[type=hidden]")) { for (Element input : doc.select("input[type=hidden]")) {
postData.put(input.attr("name"), input.attr("value")); postData.put(input.attr("name"), input.attr("value"));
} }
@ -239,7 +239,7 @@ public class FlickrRipper extends AbstractHTMLRipper {
private URL url; private URL url;
private int index; private int index;
public FlickrImageThread(URL url, int index) { FlickrImageThread(URL url, int index) {
super(); super();
this.url = url; this.url = url;
this.index = index; this.index = index;
@ -252,7 +252,6 @@ public class FlickrRipper extends AbstractHTMLRipper {
Elements fullsizeImages = doc.select("div#allsizes-photo img"); Elements fullsizeImages = doc.select("div#allsizes-photo img");
if (fullsizeImages.size() == 0) { if (fullsizeImages.size() == 0) {
logger.error("Could not find flickr image at " + doc.location() + " - missing 'div#allsizes-photo img'"); logger.error("Could not find flickr image at " + doc.location() + " - missing 'div#allsizes-photo img'");
return;
} }
else { else {
String prefix = ""; String prefix = "";

View File

@ -28,8 +28,8 @@ import com.rarchives.ripme.utils.Http;
public class FuraffinityRipper extends AbstractHTMLRipper { public class FuraffinityRipper extends AbstractHTMLRipper {
static Map<String, String> cookies=null; private static Map<String, String> cookies=null;
static final String urlBase = "https://www.furaffinity.net"; private static final String urlBase = "https://www.furaffinity.net";
// Thread pool for finding direct image links from "image" pages (html) // Thread pool for finding direct image links from "image" pages (html)
private DownloadThreadPool furaffinityThreadPool private DownloadThreadPool furaffinityThreadPool
@ -75,7 +75,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
.response(); .response();
cookies = loginPage.cookies(); cookies = loginPage.cookies();
Map<String,String> formData = new HashMap<String,String>(); Map<String,String> formData = new HashMap<>();
formData.put("action", "login"); formData.put("action", "login");
formData.put("retard_protection", "1"); formData.put("retard_protection", "1");
formData.put("name", user); formData.put("name", user);
@ -112,7 +112,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> urls = new ArrayList<String>(); List<String> urls = new ArrayList<>();
Elements urlElements = page.select("figure.t-image > b > u > a"); Elements urlElements = page.select("figure.t-image > b > u > a");
for (Element e : urlElements) { for (Element e : urlElements) {
urls.add(urlBase + e.select("a").first().attr("href")); urls.add(urlBase + e.select("a").first().attr("href"));
@ -121,7 +121,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
} }
@Override @Override
public List<String> getDescriptionsFromPage(Document page) { public List<String> getDescriptionsFromPage(Document page) {
List<String> urls = new ArrayList<String>(); List<String> urls = new ArrayList<>();
Elements urlElements = page.select("figure.t-image > b > u > a"); Elements urlElements = page.select("figure.t-image > b > u > a");
for (Element e : urlElements) { for (Element e : urlElements) {
urls.add(urlBase + e.select("a").first().attr("href")); urls.add(urlBase + e.select("a").first().attr("href"));
@ -157,9 +157,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
ele.select("p").prepend("\\n\\n"); ele.select("p").prepend("\\n\\n");
logger.debug("Returning description at " + page); logger.debug("Returning description at " + page);
String tempPage = Jsoup.clean(ele.html().replaceAll("\\\\n", System.getProperty("line.separator")), "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false)); String tempPage = Jsoup.clean(ele.html().replaceAll("\\\\n", System.getProperty("line.separator")), "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false));
String title = documentz.select("meta[property=og:title]").attr("content"); return documentz.select("meta[property=og:title]").attr("content") + "\n" + tempPage; // Overridden saveText takes first line and makes it the file name.
String tempText = title;
return tempText + "\n" + tempPage; // Overridden saveText takes first line and makes it the file name.
} catch (IOException ioe) { } catch (IOException ioe) {
logger.info("Failed to get description " + page + " : '" + ioe.getMessage() + "'"); logger.info("Failed to get description " + page + " : '" + ioe.getMessage() + "'");
return null; return null;
@ -232,7 +230,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
private class FuraffinityDocumentThread extends Thread { private class FuraffinityDocumentThread extends Thread {
private URL url; private URL url;
public FuraffinityDocumentThread(URL url) { FuraffinityDocumentThread(URL url) {
super(); super();
this.url = url; this.url = url;
} }

View File

@ -60,7 +60,7 @@ public class FuskatorRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
String html = doc.html(); String html = doc.html();
// Get "baseUrl" // Get "baseUrl"
String baseUrl = Utils.between(html, "unescape('", "'").get(0); String baseUrl = Utils.between(html, "unescape('", "'").get(0);

View File

@ -22,7 +22,7 @@ import com.rarchives.ripme.utils.Http;
public class GifyoRipper extends AbstractHTMLRipper { public class GifyoRipper extends AbstractHTMLRipper {
private int page = 0; private int page = 0;
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
public GifyoRipper(URL url) throws IOException { public GifyoRipper(URL url) throws IOException {
super(url); super(url);
@ -70,7 +70,7 @@ public class GifyoRipper extends AbstractHTMLRipper {
@Override @Override
public Document getNextPage(Document doc) throws IOException { public Document getNextPage(Document doc) throws IOException {
page++; page++;
Map<String,String> postData = new HashMap<String,String>(); Map<String,String> postData = new HashMap<>();
postData.put("cmd", "refreshData"); postData.put("cmd", "refreshData");
postData.put("view", "gif"); postData.put("view", "gif");
postData.put("layout", "grid"); postData.put("layout", "grid");
@ -92,7 +92,7 @@ public class GifyoRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element image : doc.select("img.profile_gif")) { for (Element image : doc.select("img.profile_gif")) {
String imageUrl = image.attr("data-animated"); String imageUrl = image.attr("data-animated");
if (imageUrl.startsWith("//")) { if (imageUrl.startsWith("//")) {

View File

@ -50,7 +50,7 @@ public class GirlsOfDesireRipper extends AbstractHTMLRipper {
Pattern p; Pattern p;
Matcher m; Matcher m;
p = Pattern.compile("^www\\.girlsofdesire\\.org\\/galleries\\/([\\w\\d-]+)\\/$"); p = Pattern.compile("^www\\.girlsofdesire\\.org/galleries/([\\w\\d-]+)/$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
@ -72,7 +72,7 @@ public class GirlsOfDesireRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("td.vtop > a > img")) { for (Element thumb : doc.select("td.vtop > a > img")) {
String imgSrc = thumb.attr("src"); String imgSrc = thumb.attr("src");
imgSrc = imgSrc.replaceAll("_thumb\\.", "."); imgSrc = imgSrc.replaceAll("_thumb\\.", ".");

View File

@ -64,7 +64,7 @@ public class HentaiCafeRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
result.add(doc.select("div[id=page] > div.inner > a > img.open").attr("src")); result.add(doc.select("div[id=page] > div.inner > a > img.open").attr("src"));
return result; return result;
} }

View File

@ -20,7 +20,7 @@ import com.rarchives.ripme.utils.Http;
public class HentaifoundryRipper extends AbstractHTMLRipper { public class HentaifoundryRipper extends AbstractHTMLRipper {
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
public HentaifoundryRipper(URL url) throws IOException { public HentaifoundryRipper(URL url) throws IOException {
super(url); super(url);
} }
@ -84,7 +84,7 @@ public class HentaifoundryRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Pattern imgRegex = Pattern.compile(".*/user/([a-zA-Z0-9\\-_]+)/(\\d+)/.*"); Pattern imgRegex = Pattern.compile(".*/user/([a-zA-Z0-9\\-_]+)/(\\d+)/.*");
for (Element thumb : doc.select("div.thumb_square > a.thumbLink")) { for (Element thumb : doc.select("div.thumb_square > a.thumbLink")) {
if (isStopped()) { if (isStopped()) {
@ -115,7 +115,7 @@ public class HentaifoundryRipper extends AbstractHTMLRipper {
imagePage = null; imagePage = null;
} }
// This is here for when the image is resized to a thumbnail because ripme doesn't report a screensize // This is here for when the image is resized to a thumbnail because ripme doesn't report a screensize
if (imagePage.select("div.boxbody > img.center").attr("src").contains("thumbs.") == true) { if (imagePage.select("div.boxbody > img.center").attr("src").contains("thumbs.")) {
imageURLs.add("http:" + imagePage.select("div.boxbody > img.center").attr("onclick").replace("this.src=", "").replace("'", "").replace("; $(#resize_message).hide();", "")); imageURLs.add("http:" + imagePage.select("div.boxbody > img.center").attr("onclick").replace("this.src=", "").replace("'", "").replace("; $(#resize_message).hide();", ""));
} }
else { else {

View File

@ -31,7 +31,7 @@ public class ImagearnRipper extends AbstractHTMLRipper {
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^.*imagearn.com/{1,}gallery.php\\?id=([0-9]{1,}).*$"); Pattern p = Pattern.compile("^.*imagearn.com/+gallery.php\\?id=([0-9]+).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
@ -43,7 +43,7 @@ public class ImagearnRipper extends AbstractHTMLRipper {
} }
public URL sanitizeURL(URL url) throws MalformedURLException { public URL sanitizeURL(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^.*imagearn.com/{1,}image.php\\?id=[0-9]{1,}.*$"); Pattern p = Pattern.compile("^.*imagearn.com/+image.php\\?id=[0-9]+.*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
// URL points to imagearn *image*, not gallery // URL points to imagearn *image*, not gallery
@ -77,7 +77,7 @@ public class ImagearnRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("div#gallery > div > a")) { for (Element thumb : doc.select("div#gallery > div > a")) {
String imageURL = thumb.attr("href"); String imageURL = thumb.attr("href");
try { try {

View File

@ -81,7 +81,7 @@ public class ImagebamRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("div > a[target=_blank]:not(.footera)")) { for (Element thumb : doc.select("div > a[target=_blank]:not(.footera)")) {
imageURLs.add(thumb.attr("href")); imageURLs.add(thumb.attr("href"));
} }
@ -124,7 +124,7 @@ public class ImagebamRipper extends AbstractHTMLRipper {
private URL url; private URL url;
private int index; private int index;
public ImagebamImageThread(URL url, int index) { ImagebamImageThread(URL url, int index) {
super(); super();
this.url = url; this.url = url;
this.index = index; this.index = index;

View File

@ -120,7 +120,7 @@ public class ImagefapRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("#gallery img")) { for (Element thumb : doc.select("#gallery img")) {
if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) { if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) {
continue; continue;
@ -129,7 +129,7 @@ public class ImagefapRipper extends AbstractHTMLRipper {
image = image.replaceAll( image = image.replaceAll(
"http://x.*.fap.to/images/thumb/", "http://x.*.fap.to/images/thumb/",
"http://fap.to/images/full/"); "http://fap.to/images/full/");
image = image.replaceAll("w[0-9]{1,}-h[0-9]{1,}/", ""); image = image.replaceAll("w[0-9]+-h[0-9]+/", "");
imageURLs.add(image); imageURLs.add(image);
if (isThisATest()) { if (isThisATest()) {
break; break;

View File

@ -67,7 +67,7 @@ public class ImagestashRipper extends AbstractJSONRipper {
@Override @Override
public List<String> getURLsFromJSON(JSONObject json) { public List<String> getURLsFromJSON(JSONObject json) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
JSONArray images = json.getJSONArray("images"); JSONArray images = json.getJSONArray("images");
for (int i = 0; i < images.length(); i++) { for (int i = 0; i < images.length(); i++) {
JSONObject image = images.getJSONObject(i); JSONObject image = images.getJSONObject(i);

View File

@ -62,7 +62,7 @@ public class ImagevenueRipper extends AbstractHTMLRipper {
} }
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("a[target=_blank]")) { for (Element thumb : doc.select("a[target=_blank]")) {
imageURLs.add(thumb.attr("href")); imageURLs.add(thumb.attr("href"));
} }
@ -83,7 +83,7 @@ public class ImagevenueRipper extends AbstractHTMLRipper {
private URL url; private URL url;
private int index; private int index;
public ImagevenueImageThread(URL url, int index) { ImagevenueImageThread(URL url, int index) {
super(); super();
this.url = url; this.url = url;
this.index = index; this.index = index;

View File

@ -46,7 +46,7 @@ public class ImgboxRipper extends AbstractHTMLRipper {
} }
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("div.boxed-content > a > img")) { for (Element thumb : doc.select("div.boxed-content > a > img")) {
String image = thumb.attr("src") String image = thumb.attr("src")
.replaceAll("[-a-zA-Z0-9.]+s.imgbox.com", .replaceAll("[-a-zA-Z0-9.]+s.imgbox.com",

View File

@ -31,14 +31,15 @@ public class ImgurRipper extends AlbumRipper {
private Document albumDoc; private Document albumDoc;
static enum ALBUM_TYPE { enum ALBUM_TYPE {
ALBUM, ALBUM,
USER, USER,
USER_ALBUM, USER_ALBUM,
USER_IMAGES, USER_IMAGES,
SERIES_OF_IMAGES, SERIES_OF_IMAGES,
SUBREDDIT SUBREDDIT
}; }
private ALBUM_TYPE albumType; private ALBUM_TYPE albumType;
public ImgurRipper(URL url) throws IOException { public ImgurRipper(URL url) throws IOException {
@ -223,7 +224,7 @@ public class ImgurRipper extends AlbumRipper {
String[] imageIds = m.group(1).split(","); String[] imageIds = m.group(1).split(",");
for (String imageId : imageIds) { for (String imageId : imageIds) {
// TODO: Fetch image with ID imageId // TODO: Fetch image with ID imageId
logger.debug("Fetching image info for ID " + imageId);; logger.debug("Fetching image info for ID " + imageId);
try { try {
JSONObject json = Http.url("https://api.imgur.com/2/image/" + imageId + ".json").getJSON(); JSONObject json = Http.url("https://api.imgur.com/2/image/" + imageId + ".json").getJSON();
if (!json.has("image")) { if (!json.has("image")) {
@ -350,7 +351,6 @@ public class ImgurRipper extends AlbumRipper {
Thread.sleep(SLEEP_BETWEEN_ALBUMS * 1000); Thread.sleep(SLEEP_BETWEEN_ALBUMS * 1000);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error while ripping album: " + e.getMessage(), e); logger.error("Error while ripping album: " + e.getMessage(), e);
continue;
} }
} }
} }
@ -515,12 +515,12 @@ public class ImgurRipper extends AlbumRipper {
} }
public static class ImgurImage { public static class ImgurImage {
public String title = "", String title = "";
description = "", String description = "";
extension = ""; String extension = "";
public URL url = null; public URL url = null;
public ImgurImage(URL url) { ImgurImage(URL url) {
this.url = url; this.url = url;
String tempUrl = url.toExternalForm(); String tempUrl = url.toExternalForm();
this.extension = tempUrl.substring(tempUrl.lastIndexOf('.')); this.extension = tempUrl.substring(tempUrl.lastIndexOf('.'));
@ -528,7 +528,7 @@ public class ImgurRipper extends AlbumRipper {
this.extension = this.extension.substring(0, this.extension.indexOf("?")); this.extension = this.extension.substring(0, this.extension.indexOf("?"));
} }
} }
public ImgurImage(URL url, String title) { ImgurImage(URL url, String title) {
this(url); this(url);
this.title = title; this.title = title;
} }
@ -536,7 +536,7 @@ public class ImgurRipper extends AlbumRipper {
this(url, title); this(url, title);
this.description = description; this.description = description;
} }
public String getSaveAs() { String getSaveAs() {
String saveAs = this.title; String saveAs = this.title;
String u = url.toExternalForm(); String u = url.toExternalForm();
if (u.contains("?")) { if (u.contains("?")) {
@ -554,17 +554,17 @@ public class ImgurRipper extends AlbumRipper {
} }
public static class ImgurAlbum { public static class ImgurAlbum {
public String title = null; String title = null;
public URL url = null; public URL url = null;
public List<ImgurImage> images = new ArrayList<ImgurImage>(); public List<ImgurImage> images = new ArrayList<>();
public ImgurAlbum(URL url) { ImgurAlbum(URL url) {
this.url = url; this.url = url;
} }
public ImgurAlbum(URL url, String title) { public ImgurAlbum(URL url, String title) {
this(url); this(url);
this.title = title; this.title = title;
} }
public void addImage(ImgurImage image) { void addImage(ImgurImage image) {
images.add(image); images.add(image);
} }
} }

View File

@ -75,8 +75,7 @@ public class InstagramRipper extends AbstractJSONRipper {
String baseURL = "http://instagram.com/" + userID + "/media"; String baseURL = "http://instagram.com/" + userID + "/media";
try { try {
JSONObject result = Http.url(baseURL).getJSON(); return Http.url(baseURL).getJSON();
return result;
} catch (JSONException e) { } catch (JSONException e) {
throw new IOException("Could not get instagram user via: " + baseURL); throw new IOException("Could not get instagram user via: " + baseURL);
} }
@ -101,9 +100,7 @@ public class InstagramRipper extends AbstractJSONRipper {
logger.info("Loading " + baseURL); logger.info("Loading " + baseURL);
sleep(1000); sleep(1000);
JSONObject nextJSON = Http.url(baseURL).getJSON(); return Http.url(baseURL).getJSON();
return nextJSON;
} else { } else {
throw new IOException("No more images found"); throw new IOException("No more images found");
} }
@ -129,7 +126,7 @@ public class InstagramRipper extends AbstractJSONRipper {
// Instagram returns cropped images to unauthenticated applications to maintain legacy support. // Instagram returns cropped images to unauthenticated applications to maintain legacy support.
// To retrieve the uncropped image, remove this segment from the URL. // To retrieve the uncropped image, remove this segment from the URL.
// Segment format: cX.Y.W.H - eg: c0.134.1080.1080 // Segment format: cX.Y.W.H - eg: c0.134.1080.1080
imageURL = imageURL.replaceAll("\\/c\\d{1,4}\\.\\d{1,4}\\.\\d{1,4}\\.\\d{1,4}", ""); imageURL = imageURL.replaceAll("/c\\d{1,4}\\.\\d{1,4}\\.\\d{1,4}\\.\\d{1,4}", "");
imageURL = imageURL.replaceAll("\\?ig_cache_key.+$", ""); imageURL = imageURL.replaceAll("\\?ig_cache_key.+$", "");
return imageURL; return imageURL;
@ -154,7 +151,7 @@ public class InstagramRipper extends AbstractJSONRipper {
@Override @Override
public List<String> getURLsFromJSON(JSONObject json) { public List<String> getURLsFromJSON(JSONObject json) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
JSONArray datas = json.getJSONArray("items"); JSONArray datas = json.getJSONArray("items");
for (int i = 0; i < datas.length(); i++) { for (int i = 0; i < datas.length(); i++) {
JSONObject data = (JSONObject) datas.get(i); JSONObject data = (JSONObject) datas.get(i);

View File

@ -50,7 +50,7 @@ public class JagodibujaRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Element comicPageUrl : doc.select("div.gallery-icon > a")) { for (Element comicPageUrl : doc.select("div.gallery-icon > a")) {
try { try {
sleep(500); sleep(500);

View File

@ -51,7 +51,7 @@ public class LusciousRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> urls = new ArrayList<String>(); List<String> urls = new ArrayList<>();
Elements urlElements = page.select("img#single_picture"); Elements urlElements = page.select("img#single_picture");
for (Element e : urlElements) { for (Element e : urlElements) {
urls.add(e.attr("src")); urls.add(e.attr("src"));

View File

@ -25,7 +25,7 @@ import com.rarchives.ripme.utils.Http;
public class MediacrushRipper extends AbstractJSONRipper { public class MediacrushRipper extends AbstractJSONRipper {
/** Ordered list of preferred formats, sorted by preference (low-to-high) */ /** Ordered list of preferred formats, sorted by preference (low-to-high) */
private static final Map<String, Integer> PREFERRED_FORMATS = new HashMap<String,Integer>(); private static final Map<String, Integer> PREFERRED_FORMATS = new HashMap<>();
static { static {
PREFERRED_FORMATS.put("mp4", 0); PREFERRED_FORMATS.put("mp4", 0);
PREFERRED_FORMATS.put("wemb",1); PREFERRED_FORMATS.put("wemb",1);
@ -36,7 +36,7 @@ public class MediacrushRipper extends AbstractJSONRipper {
PREFERRED_FORMATS.put("png", 6); PREFERRED_FORMATS.put("png", 6);
PREFERRED_FORMATS.put("jpg", 7); PREFERRED_FORMATS.put("jpg", 7);
PREFERRED_FORMATS.put("jpeg",8); PREFERRED_FORMATS.put("jpeg",8);
}; }
public MediacrushRipper(URL url) throws IOException { public MediacrushRipper(URL url) throws IOException {
super(url); super(url);
@ -113,7 +113,7 @@ public class MediacrushRipper extends AbstractJSONRipper {
@Override @Override
public List<String> getURLsFromJSON(JSONObject json) { public List<String> getURLsFromJSON(JSONObject json) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
// Iterate over all files // Iterate over all files
JSONArray files = json.getJSONArray("files"); JSONArray files = json.getJSONArray("files");
for (int i = 0; i < files.length(); i++) { for (int i = 0; i < files.length(); i++) {

View File

@ -41,7 +41,7 @@ public class ModelmayhemRipper extends AlbumRipper {
@Override @Override
public void rip() throws IOException { public void rip() throws IOException {
Map<String,String> cookies = null, Map<String,String> cookies = null,
postData = new HashMap<String,String>(); postData = new HashMap<>();
String gid = getGID(this.url), String gid = getGID(this.url),
ref = "http://www.modelmayhem.com/" + gid; ref = "http://www.modelmayhem.com/" + gid;

View File

@ -126,7 +126,7 @@ public class MotherlessRipper extends AlbumRipper {
private URL url; private URL url;
private int index; private int index;
public MotherlessImageThread(URL url, int index) { MotherlessImageThread(URL url, int index) {
super(); super();
this.url = url; this.url = url;
this.index = index; this.index = index;
@ -142,7 +142,7 @@ public class MotherlessRipper extends AlbumRipper {
Document doc = Http.url(u) Document doc = Http.url(u)
.referrer(u) .referrer(u)
.get(); .get();
Pattern p = Pattern.compile("^.*__fileurl = '([^']{1,})';.*$", Pattern.DOTALL); Pattern p = Pattern.compile("^.*__fileurl = '([^']+)';.*$", Pattern.DOTALL);
Matcher m = p.matcher(doc.outerHtml()); Matcher m = p.matcher(doc.outerHtml());
if (m.matches()) { if (m.matches()) {
String file = m.group(1); String file = m.group(1);

View File

@ -15,7 +15,7 @@ import org.jsoup.select.Elements;
import java.util.Arrays; import java.util.Arrays;
public class MyhentaicomicsRipper extends AbstractHTMLRipper { public class MyhentaicomicsRipper extends AbstractHTMLRipper {
public static boolean isTag; private static boolean isTag;
public MyhentaicomicsRipper(URL url) throws IOException { public MyhentaicomicsRipper(URL url) throws IOException {
super(url); super(url);
@ -47,7 +47,7 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
return ma.group(1); return ma.group(1);
} }
Pattern pat = Pattern.compile("^https?://myhentaicomics.com/index.php/tag/([0-9]*)/?([a-zA-Z%0-9+\\?=:]*)?$"); Pattern pat = Pattern.compile("^https?://myhentaicomics.com/index.php/tag/([0-9]*)/?([a-zA-Z%0-9+?=:]*)?$");
Matcher mat = pat.matcher(url.toExternalForm()); Matcher mat = pat.matcher(url.toExternalForm());
if (mat.matches()) { if (mat.matches()) {
isTag = true; isTag = true;
@ -84,8 +84,8 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
} }
// This replaces getNextPage when downloading from searchs and tags // This replaces getNextPage when downloading from searchs and tags
public List<String> getNextAlbumPage(String pageUrl) { private List<String> getNextAlbumPage(String pageUrl) {
List<String> albumPagesList = new ArrayList<String>(); List<String> albumPagesList = new ArrayList<>();
int pageNumber = 1; int pageNumber = 1;
albumPagesList.add("http://myhentaicomics.com/index.php/" + pageUrl.split("\\?")[0] + "?page=" + Integer.toString(pageNumber)); albumPagesList.add("http://myhentaicomics.com/index.php/" + pageUrl.split("\\?")[0] + "?page=" + Integer.toString(pageNumber));
while (true) { while (true) {
@ -115,9 +115,9 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
return albumPagesList; return albumPagesList;
} }
public List<String> getAlbumsFromPage(String url) { private List<String> getAlbumsFromPage(String url) {
List<String> pagesToRip; List<String> pagesToRip;
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
logger.info("Running getAlbumsFromPage"); logger.info("Running getAlbumsFromPage");
Document doc; Document doc;
try { try {
@ -161,7 +161,7 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
url_string = url_string.replace("%28", "_"); url_string = url_string.replace("%28", "_");
url_string = url_string.replace("%29", "_"); url_string = url_string.replace("%29", "_");
url_string = url_string.replace("%2C", "_"); url_string = url_string.replace("%2C", "_");
if (isTag == true) { if (isTag) {
logger.info("Downloading from a tag or search"); logger.info("Downloading from a tag or search");
try { try {
sleep(500); sleep(500);
@ -180,11 +180,11 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
return result; return result;
} }
public List<String> getListOfPages(Document doc) { private List<String> getListOfPages(Document doc) {
List<String> pages = new ArrayList<String>(); List<String> pages = new ArrayList<>();
// Get the link from the last button // Get the link from the last button
String nextPageUrl = doc.select("a.ui-icon-right").last().attr("href"); String nextPageUrl = doc.select("a.ui-icon-right").last().attr("href");
Pattern pat = Pattern.compile("\\/index\\.php\\/tag\\/[0-9]*\\/[a-zA-Z0-9_\\-\\:+]*\\?page=(\\d+)"); Pattern pat = Pattern.compile("/index\\.php/tag/[0-9]*/[a-zA-Z0-9_\\-:+]*\\?page=(\\d+)");
Matcher mat = pat.matcher(nextPageUrl); Matcher mat = pat.matcher(nextPageUrl);
if (mat.matches()) { if (mat.matches()) {
logger.debug("Getting pages from a tag"); logger.debug("Getting pages from a tag");
@ -197,7 +197,7 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
pages.add(link); pages.add(link);
} }
} else { } else {
Pattern pa = Pattern.compile("\\/index\\.php\\/search\\?q=[a-zA-Z0-9_\\-\\:]*\\&page=(\\d+)"); Pattern pa = Pattern.compile("/index\\.php/search\\?q=[a-zA-Z0-9_\\-:]*&page=(\\d+)");
Matcher ma = pa.matcher(nextPageUrl); Matcher ma = pa.matcher(nextPageUrl);
if (ma.matches()) { if (ma.matches()) {
logger.debug("Getting pages from a search"); logger.debug("Getting pages from a search");
@ -217,7 +217,7 @@ public class MyhentaicomicsRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
// Checks if this is a comic page or a page of albums // Checks if this is a comic page or a page of albums
// If true the page is a page of albums // If true the page is a page of albums
if (doc.toString().contains("class=\"g-item g-album\"")) { if (doc.toString().contains("class=\"g-item g-album\"")) {

View File

@ -86,7 +86,7 @@ public class NatalieMuRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Pattern p; Matcher m; Pattern p; Matcher m;
//select all album thumbnails //select all album thumbnails
for (Element span : page.select(".NA_articleGallery span")) { for (Element span : page.select(".NA_articleGallery span")) {

View File

@ -75,7 +75,7 @@ public class NfsfwRipper extends AlbumRipper {
@Override @Override
public void rip() throws IOException { public void rip() throws IOException {
List<Pair> subAlbums = new ArrayList<Pair>(); List<Pair> subAlbums = new ArrayList<>();
int index = 0; int index = 0;
subAlbums.add(new Pair(this.url.toExternalForm(), "")); subAlbums.add(new Pair(this.url.toExternalForm(), ""));
while (subAlbums.size() > 0) { while (subAlbums.size() > 0) {
@ -153,7 +153,7 @@ public class NfsfwRipper extends AlbumRipper {
private String subdir; private String subdir;
private int index; private int index;
public NfsfwImageThread(URL url, String subdir, int index) { NfsfwImageThread(URL url, String subdir, int index) {
super(); super();
this.url = url; this.url = url;
this.subdir = subdir; this.subdir = subdir;
@ -187,8 +187,9 @@ public class NfsfwRipper extends AlbumRipper {
} }
private class Pair { private class Pair {
public String first, second; String first;
public Pair(String first, String second) { String second;
Pair(String first, String second) {
this.first = first; this.first = first;
this.second = second; this.second = second;
} }

View File

@ -87,7 +87,7 @@ public class NhentaiRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Elements thumbs = page.select(".gallerythumb"); Elements thumbs = page.select(".gallerythumb");
for (Element el : thumbs) { for (Element el : thumbs) {
String imageUrl = el.attr("href"); String imageUrl = el.attr("href");

View File

@ -55,7 +55,7 @@ public class NudeGalsRipper extends AbstractHTMLRipper {
Pattern p; Pattern p;
Matcher m; Matcher m;
p = Pattern.compile("^.*nude-gals\\.com\\/photoshoot\\.php\\?photoshoot_id=(\\d+)$"); p = Pattern.compile("^.*nude-gals\\.com/photoshoot\\.php\\?photoshoot_id=(\\d+)$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
@ -77,7 +77,7 @@ public class NudeGalsRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Elements thumbs = doc.select("#grid_container .grid > .grid_box"); Elements thumbs = doc.select("#grid_container .grid > .grid_box");
for (Element thumb : thumbs) { for (Element thumb : thumbs) {

View File

@ -27,7 +27,7 @@ public class PahealRipper extends AbstractHTMLRipper {
private static Map<String, String> getCookies() { private static Map<String, String> getCookies() {
if (cookies == null) { if (cookies == null) {
cookies = new HashMap<String, String>(1); cookies = new HashMap<>(1);
cookies.put("ui-tnc-agreed", "true"); cookies.put("ui-tnc-agreed", "true");
} }
return cookies; return cookies;
@ -66,7 +66,7 @@ public class PahealRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
Elements elements = page.select(".shm-thumb.thumb>a").not(".shm-thumb-link"); Elements elements = page.select(".shm-thumb.thumb>a").not(".shm-thumb-link");
List<String> res = new ArrayList<String>(elements.size()); List<String> res = new ArrayList<>(elements.size());
for (Element e : elements) { for (Element e : elements) {
res.add(e.absUrl("href")); res.add(e.absUrl("href"));
@ -92,9 +92,7 @@ public class PahealRipper extends AbstractHTMLRipper {
+ Utils.filesystemSafe(new URI(name).getPath()) + Utils.filesystemSafe(new URI(name).getPath())
+ ext); + ext);
addURLToDownload(url, outFile); addURLToDownload(url, outFile);
} catch (IOException ex) { } catch (IOException | URISyntaxException ex) {
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex);
} catch (URISyntaxException ex) {
Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(PahealRipper.class.getName()).log(Level.SEVERE, null, ex);
} }
} }

View File

@ -85,8 +85,8 @@ public class PhotobucketRipper extends AlbumRipper {
public void rip() throws IOException { public void rip() throws IOException {
List<String> subalbums = ripAlbumAndGetSubalbums(this.url.toExternalForm()); List<String> subalbums = ripAlbumAndGetSubalbums(this.url.toExternalForm());
List<String> subsToRip = new ArrayList<String>(), List<String> subsToRip = new ArrayList<>(),
rippedSubs = new ArrayList<String>(); rippedSubs = new ArrayList<>();
for (String sub : subalbums) { for (String sub : subalbums) {
subsToRip.add(sub); subsToRip.add(sub);
@ -117,7 +117,7 @@ public class PhotobucketRipper extends AlbumRipper {
waitForThreads(); waitForThreads();
} }
public List<String> ripAlbumAndGetSubalbums(String theUrl) throws IOException { private List<String> ripAlbumAndGetSubalbums(String theUrl) throws IOException {
int filesIndex = 0, int filesIndex = 0,
filesTotal = 0, filesTotal = 0,
pageIndex = 0; pageIndex = 0;
@ -145,7 +145,7 @@ public class PhotobucketRipper extends AlbumRipper {
} }
// Grab the JSON // Grab the JSON
Pattern p; Matcher m; Pattern p; Matcher m;
p = Pattern.compile("^.*collectionData: (\\{.*\\}).*$", Pattern.DOTALL); p = Pattern.compile("^.*collectionData: (\\{.*}).*$", Pattern.DOTALL);
m = p.matcher(data); m = p.matcher(data);
if (m.matches()) { if (m.matches()) {
jsonString = m.group(1); jsonString = m.group(1);
@ -176,12 +176,12 @@ public class PhotobucketRipper extends AlbumRipper {
if (url != null) { if (url != null) {
return getSubAlbums(url, currentAlbumPath); return getSubAlbums(url, currentAlbumPath);
} else { } else {
return new ArrayList<String>(); return new ArrayList<>();
} }
} }
private List<String> getSubAlbums(String url, String currentAlbumPath) { private List<String> getSubAlbums(String url, String currentAlbumPath) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
String subdomain = url.substring(url.indexOf("://")+3); String subdomain = url.substring(url.indexOf("://")+3);
subdomain = subdomain.substring(0, subdomain.indexOf(".")); subdomain = subdomain.substring(0, subdomain.indexOf("."));
String apiUrl = "http://" + subdomain + ".photobucket.com/component/Albums-SubalbumList" String apiUrl = "http://" + subdomain + ".photobucket.com/component/Albums-SubalbumList"

View File

@ -19,7 +19,7 @@ import com.rarchives.ripme.utils.Utils;
public class PornhubRipper extends AlbumRipper { public class PornhubRipper extends AlbumRipper {
// All sleep times are in milliseconds // All sleep times are in milliseconds
private static final int IMAGE_SLEEP_TIME = 1 * 1000; private static final int IMAGE_SLEEP_TIME = 1000;
private static final String DOMAIN = "pornhub.com", HOST = "Pornhub"; private static final String DOMAIN = "pornhub.com", HOST = "Pornhub";
@ -134,7 +134,7 @@ public class PornhubRipper extends AlbumRipper {
private URL url; private URL url;
private int index; private int index;
public PornhubImageThread(URL url, int index, File workingDir) { PornhubImageThread(URL url, int index, File workingDir) {
super(); super();
this.url = url; this.url = url;
this.index = index; this.index = index;

View File

@ -64,7 +64,7 @@ public class RajceRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Element el : page.select("a.photoThumb")) { for (Element el : page.select("a.photoThumb")) {
result.add(el.attr("href")); result.add(el.attr("href"));
} }

View File

@ -131,7 +131,7 @@ public class RedditRipper extends AlbumRipper {
Object jsonObj = new JSONTokener(jsonString).nextValue(); Object jsonObj = new JSONTokener(jsonString).nextValue();
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
if (jsonObj instanceof JSONObject) { if (jsonObj instanceof JSONObject) {
jsonArray.put( (JSONObject) jsonObj); jsonArray.put(jsonObj);
} else if (jsonObj instanceof JSONArray) { } else if (jsonObj instanceof JSONArray) {
jsonArray = (JSONArray) jsonObj; jsonArray = (JSONArray) jsonObj;
} else { } else {
@ -167,7 +167,7 @@ public class RedditRipper extends AlbumRipper {
} }
} }
public void handleBody(String body, String id) { private void handleBody(String body, String id) {
Pattern p = RipUtils.getURLRegex(); Pattern p = RipUtils.getURLRegex();
Matcher m = p.matcher(body); Matcher m = p.matcher(body);
while (m.find()) { while (m.find()) {
@ -179,7 +179,7 @@ public class RedditRipper extends AlbumRipper {
} }
} }
public void handleURL(String theUrl, String id) { private void handleURL(String theUrl, String id) {
URL originalURL; URL originalURL;
try { try {
originalURL = new URL(theUrl); originalURL = new URL(theUrl);
@ -220,21 +220,21 @@ public class RedditRipper extends AlbumRipper {
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
// User // User
Pattern p = Pattern.compile("^https?://[a-zA-Z0-9\\.]{0,4}reddit\\.com/(user|u)/([a-zA-Z0-9_\\-]{3,}).*$"); Pattern p = Pattern.compile("^https?://[a-zA-Z0-9.]{0,4}reddit\\.com/(user|u)/([a-zA-Z0-9_\\-]{3,}).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return "user_" + m.group(m.groupCount()); return "user_" + m.group(m.groupCount());
} }
// Post // Post
p = Pattern.compile("^https?://[a-zA-Z0-9\\.]{0,4}reddit\\.com/.*comments/([a-zA-Z0-9]{1,8}).*$"); p = Pattern.compile("^https?://[a-zA-Z0-9.]{0,4}reddit\\.com/.*comments/([a-zA-Z0-9]{1,8}).*$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return "post_" + m.group(m.groupCount()); return "post_" + m.group(m.groupCount());
} }
// Subreddit // Subreddit
p = Pattern.compile("^https?://[a-zA-Z0-9\\.]{0,4}reddit\\.com/r/([a-zA-Z0-9_]{1,}).*$"); p = Pattern.compile("^https?://[a-zA-Z0-9.]{0,4}reddit\\.com/r/([a-zA-Z0-9_]+).*$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return "sub_" + m.group(m.groupCount()); return "sub_" + m.group(m.groupCount());

View File

@ -21,7 +21,7 @@ import com.rarchives.ripme.utils.Http;
public class SankakuComplexRipper extends AbstractHTMLRipper { public class SankakuComplexRipper extends AbstractHTMLRipper {
private Document albumDoc = null; private Document albumDoc = null;
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
public SankakuComplexRipper(URL url) throws IOException { public SankakuComplexRipper(URL url) throws IOException {
super(url); super(url);
@ -65,7 +65,7 @@ public class SankakuComplexRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
// Image URLs are basically thumbnail URLs with a different domain, a simple // Image URLs are basically thumbnail URLs with a different domain, a simple
// path replacement, and a ?xxxxxx post ID at the end (obtainable from the href) // path replacement, and a ?xxxxxx post ID at the end (obtainable from the href)
for (Element thumbSpan : doc.select("div.content > div > span.thumb > a")) { for (Element thumbSpan : doc.select("div.content > div > span.thumb > a")) {
@ -77,7 +77,6 @@ public class SankakuComplexRipper extends AbstractHTMLRipper {
imageURLs.add("https:" + subPage.select("div[id=post-content] > a > img").attr("src")); imageURLs.add("https:" + subPage.select("div[id=post-content] > a > img").attr("src"));
} catch (IOException e) { } catch (IOException e) {
logger.warn("Error while loading page " + postLink, e); logger.warn("Error while loading page " + postLink, e);
continue;
} }
} }
return imageURLs; return imageURLs;
@ -96,7 +95,7 @@ public class SankakuComplexRipper extends AbstractHTMLRipper {
String nextPage = pagination.attr("abs:next-page-url"); String nextPage = pagination.attr("abs:next-page-url");
// Only logged in users can see past page 25 // Only logged in users can see past page 25
// Trying to rip page 26 will throw a no images found error // Trying to rip page 26 will throw a no images found error
if (nextPage.contains("page=26") == false) { if (!nextPage.contains("page=26")) {
logger.info("Getting next page: " + pagination.attr("abs:next-page-url")); logger.info("Getting next page: " + pagination.attr("abs:next-page-url"));
return Http.url(pagination.attr("abs:next-page-url")).cookies(cookies).get(); return Http.url(pagination.attr("abs:next-page-url")).cookies(cookies).get();
} }

View File

@ -48,7 +48,7 @@ public class ShesFreakyRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("a[data-lightbox=\"gallery\"]")) { for (Element thumb : doc.select("a[data-lightbox=\"gallery\"]")) {
String image = thumb.attr("href"); String image = thumb.attr("href");
imageURLs.add(image); imageURLs.add(image);

View File

@ -71,7 +71,7 @@ public class SinnercomicsRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Element el : doc.select("meta[property=og:image]")) { for (Element el : doc.select("meta[property=og:image]")) {
String imageSource = el.attr("content"); String imageSource = el.attr("content");
imageSource = imageSource.replace(" alt=", ""); imageSource = imageSource.replace(" alt=", "");

View File

@ -63,7 +63,7 @@ public class SupertangasRipper extends AlbumRipper {
} }
for (Element imageElement : images) { for (Element imageElement : images) {
String image = imageElement.attr("href"); String image = imageElement.attr("href");
image = image.replaceAll("\\/fotos\\/", "/fotos/images/"); image = image.replaceAll("/fotos/", "/fotos/images/");
addURLToDownload(new URL(image)); addURLToDownload(new URL(image));
} }
try { try {

View File

@ -18,19 +18,19 @@ import com.rarchives.ripme.utils.Http;
import com.rarchives.ripme.utils.Utils; import com.rarchives.ripme.utils.Utils;
class TapasticEpisode { class TapasticEpisode {
protected int index, id; int id;
protected String title, filename; String filename;
public TapasticEpisode(int index, int id, String title) { public TapasticEpisode(int index, int id, String title) {
this.index = index; int index1 = index;
this.id = id; this.id = id;
this.title = title; String title1 = title;
this.filename = Utils.filesystemSafe(title); this.filename = Utils.filesystemSafe(title);
} }
} }
public class TapasticRipper extends AbstractHTMLRipper { public class TapasticRipper extends AbstractHTMLRipper {
private List<TapasticEpisode> episodes=new ArrayList<TapasticEpisode>(); private List<TapasticEpisode> episodes= new ArrayList<>();
public TapasticRipper(URL url) throws IOException { public TapasticRipper(URL url) throws IOException {
super(url); super(url);
@ -53,7 +53,7 @@ public class TapasticRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> urls = new ArrayList<String>(); List<String> urls = new ArrayList<>();
String html = page.data(); String html = page.data();
if (!html.contains("episodeList : ")) { if (!html.contains("episodeList : ")) {
logger.error("No 'episodeList' found at " + this.url); logger.error("No 'episodeList' found at " + this.url);

View File

@ -23,7 +23,6 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
public class ThechiveRipper extends AbstractHTMLRipper { public class ThechiveRipper extends AbstractHTMLRipper {
public static boolean isTag;
public ThechiveRipper(URL url) throws IOException { public ThechiveRipper(URL url) throws IOException {
super(url); super(url);
@ -44,7 +43,7 @@ public class ThechiveRipper extends AbstractHTMLRipper {
Pattern p = Pattern.compile("^https?://thechive.com/[0-9]*/[0-9]*/[0-9]*/([a-zA-Z0-9_\\-]*)/?$"); Pattern p = Pattern.compile("^https?://thechive.com/[0-9]*/[0-9]*/[0-9]*/([a-zA-Z0-9_\\-]*)/?$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
isTag = false; boolean isTag = false;
return m.group(1); return m.group(1);
} }
throw new MalformedURLException("Expected thechive.com URL format: " + throw new MalformedURLException("Expected thechive.com URL format: " +
@ -59,7 +58,7 @@ public class ThechiveRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Element el : doc.select("img.attachment-gallery-item-full")) { for (Element el : doc.select("img.attachment-gallery-item-full")) {
String imageSource = el.attr("src"); String imageSource = el.attr("src");
// We replace thumbs with resizes so we can the full sized images // We replace thumbs with resizes so we can the full sized images

View File

@ -77,7 +77,7 @@ public class TumblrRipper extends AlbumRipper {
return url; return url;
} }
public boolean isTumblrURL(URL url) { private boolean isTumblrURL(URL url) {
String checkURL = "http://api.tumblr.com/v2/blog/"; String checkURL = "http://api.tumblr.com/v2/blog/";
checkURL += url.getHost(); checkURL += url.getHost();
checkURL += "/info?api_key=" + getApiKey(); checkURL += "/info?api_key=" + getApiKey();
@ -202,7 +202,6 @@ public class TumblrRipper extends AlbumRipper {
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("[!] Error while parsing photo in " + photo, e); logger.error("[!] Error while parsing photo in " + photo, e);
continue;
} }
} }
} else if (post.has("video_url")) { } else if (post.has("video_url")) {
@ -254,7 +253,7 @@ public class TumblrRipper extends AlbumRipper {
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
final String DOMAIN_REGEX = "^https?://([a-zA-Z0-9\\-\\.]+)"; final String DOMAIN_REGEX = "^https?://([a-zA-Z0-9\\-.]+)";
Pattern p; Pattern p;
Matcher m; Matcher m;

View File

@ -54,14 +54,14 @@ public class TwitterRipper extends AlbumRipper {
@Override @Override
public URL sanitizeURL(URL url) throws MalformedURLException { public URL sanitizeURL(URL url) throws MalformedURLException {
// https://twitter.com/search?q=from%3Apurrbunny%20filter%3Aimages&src=typd // https://twitter.com/search?q=from%3Apurrbunny%20filter%3Aimages&src=typd
Pattern p = Pattern.compile("^https?://(m\\.)?twitter\\.com/search\\?q=([a-zA-Z0-9%\\-_]{1,}).*$"); Pattern p = Pattern.compile("^https?://(m\\.)?twitter\\.com/search\\?q=([a-zA-Z0-9%\\-_]+).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
albumType = ALBUM_TYPE.SEARCH; albumType = ALBUM_TYPE.SEARCH;
searchText = m.group(2); searchText = m.group(2);
return url; return url;
} }
p = Pattern.compile("^https?://(m\\.)?twitter\\.com/([a-zA-Z0-9\\-_]{1,}).*$"); p = Pattern.compile("^https?://(m\\.)?twitter\\.com/([a-zA-Z0-9\\-_]+).*$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
albumType = ALBUM_TYPE.ACCOUNT; albumType = ALBUM_TYPE.ACCOUNT;
@ -83,7 +83,6 @@ public class TwitterRipper extends AlbumRipper {
try { try {
JSONObject json = new JSONObject(body); JSONObject json = new JSONObject(body);
accessToken = json.getString("access_token"); accessToken = json.getString("access_token");
return;
} catch (JSONException e) { } catch (JSONException e) {
// Fall through // Fall through
throw new IOException("Failure while parsing JSON: " + body, e); throw new IOException("Failure while parsing JSON: " + body, e);
@ -142,7 +141,7 @@ public class TwitterRipper extends AlbumRipper {
} }
private List<JSONObject> getTweets(String url) throws IOException { private List<JSONObject> getTweets(String url) throws IOException {
List<JSONObject> tweets = new ArrayList<JSONObject>(); List<JSONObject> tweets = new ArrayList<>();
logger.info(" Retrieving " + url); logger.info(" Retrieving " + url);
Document doc = Http.url(url) Document doc = Http.url(url)
.ignoreContentType() .ignoreContentType()
@ -283,7 +282,6 @@ public class TwitterRipper extends AlbumRipper {
if (c == '%') { if (c == '%') {
gid.append('_'); gid.append('_');
i += 2; i += 2;
continue;
// Ignore non-alphanumeric chars // Ignore non-alphanumeric chars
} else if ( } else if (
(c >= 'a' && c <= 'z') (c >= 'a' && c <= 'z')

View File

@ -22,7 +22,7 @@ import com.rarchives.ripme.utils.Http;
public class TwodgalleriesRipper extends AbstractHTMLRipper { public class TwodgalleriesRipper extends AbstractHTMLRipper {
private int offset = 0; private int offset = 0;
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
public TwodgalleriesRipper(URL url) throws IOException { public TwodgalleriesRipper(URL url) throws IOException {
super(url); super(url);
@ -90,7 +90,7 @@ public class TwodgalleriesRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
for (Element thumb : doc.select("div.hcaption > img")) { for (Element thumb : doc.select("div.hcaption > img")) {
String image = thumb.attr("src"); String image = thumb.attr("src");
image = image.replace("/200H/", "/"); image = image.replace("/200H/", "/");
@ -114,7 +114,7 @@ public class TwodgalleriesRipper extends AbstractHTMLRipper {
cookies = resp.cookies(); cookies = resp.cookies();
String ctoken = resp.parse().select("form > input[name=ctoken]").first().attr("value"); String ctoken = resp.parse().select("form > input[name=ctoken]").first().attr("value");
Map<String,String> postdata = new HashMap<String,String>(); Map<String,String> postdata = new HashMap<>();
postdata.put("user[login]", new String(Base64.decode("cmlwbWU="))); postdata.put("user[login]", new String(Base64.decode("cmlwbWU=")));
postdata.put("user[password]", new String(Base64.decode("cmlwcGVy"))); postdata.put("user[password]", new String(Base64.decode("cmlwcGVy")));
postdata.put("rememberme", "1"); postdata.put("rememberme", "1");

View File

@ -56,7 +56,7 @@ public class VidbleRipper extends AbstractHTMLRipper {
} }
private static List<String> getURLsFromPageStatic(Document doc) { private static List<String> getURLsFromPageStatic(Document doc) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
Elements els = doc.select("#ContentPlaceHolder1_divContent"); Elements els = doc.select("#ContentPlaceHolder1_divContent");
Elements imgs = els.select("img"); Elements imgs = els.select("img");
for (Element img : imgs) { for (Element img : imgs) {
@ -76,7 +76,7 @@ public class VidbleRipper extends AbstractHTMLRipper {
} }
public static List<URL> getURLsFromPage(URL url) throws IOException { public static List<URL> getURLsFromPage(URL url) throws IOException {
List<URL> urls = new ArrayList<URL>(); List<URL> urls = new ArrayList<>();
Document doc = Http.url(url).get(); Document doc = Http.url(url).get();
for (String stringURL : getURLsFromPageStatic(doc)) { for (String stringURL : getURLsFromPageStatic(doc)) {
urls.add(new URL(stringURL)); urls.add(new URL(stringURL));

View File

@ -84,7 +84,7 @@ public class VineRipper extends AlbumRipper {
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://(www\\.)?vine\\.co/u/([0-9]{1,}).*$"); Pattern p = Pattern.compile("^https?://(www\\.)?vine\\.co/u/([0-9]+).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) { if (!m.matches()) {
throw new MalformedURLException("Expected format: http://vine.co/u/######"); throw new MalformedURLException("Expected format: http://vine.co/u/######");

View File

@ -37,11 +37,7 @@ public class VkRipper extends AlbumRipper {
} }
// Ignore /video pages (but not /videos pages) // Ignore /video pages (but not /videos pages)
String u = url.toExternalForm(); String u = url.toExternalForm();
if (u.contains("/video") && !u.contains("videos")) { return !u.contains("/video") || u.contains("videos");
// Single video page
return false;
}
return true;
} }
@Override @Override
@ -62,7 +58,7 @@ public class VkRipper extends AlbumRipper {
private void ripVideos() throws IOException { private void ripVideos() throws IOException {
String oid = getGID(this.url).replace("videos", ""); String oid = getGID(this.url).replace("videos", "");
String u = "http://vk.com/al_video.php"; String u = "http://vk.com/al_video.php";
Map<String,String> postData = new HashMap<String,String>(); Map<String,String> postData = new HashMap<>();
postData.put("al", "1"); postData.put("al", "1");
postData.put("act", "load_videos_silent"); postData.put("act", "load_videos_silent");
postData.put("offset", "0"); postData.put("offset", "0");
@ -97,13 +93,13 @@ public class VkRipper extends AlbumRipper {
} }
private void ripImages() throws IOException { private void ripImages() throws IOException {
Map<String,String> photoIDsToURLs = new HashMap<String,String>(); Map<String,String> photoIDsToURLs = new HashMap<>();
int offset = 0; int offset = 0;
while (true) { while (true) {
logger.info(" Retrieving " + this.url); logger.info(" Retrieving " + this.url);
// al=1&offset=80&part=1 // al=1&offset=80&part=1
Map<String,String> postData = new HashMap<String,String>(); Map<String,String> postData = new HashMap<>();
postData.put("al", "1"); postData.put("al", "1");
postData.put("offset", Integer.toString(offset)); postData.put("offset", Integer.toString(offset));
postData.put("part", "1"); postData.put("part", "1");
@ -120,7 +116,7 @@ public class VkRipper extends AlbumRipper {
body = body.substring(body.indexOf("<div")); body = body.substring(body.indexOf("<div"));
doc = Jsoup.parseBodyFragment(body); doc = Jsoup.parseBodyFragment(body);
List<Element> elements = doc.select("a"); List<Element> elements = doc.select("a");
Set<String> photoIDsToGet = new HashSet<String>(); Set<String> photoIDsToGet = new HashSet<>();
for (Element a : elements) { for (Element a : elements) {
if (!a.attr("onclick").contains("showPhoto('")) { if (!a.attr("onclick").contains("showPhoto('")) {
logger.error("a: " + a); logger.error("a: " + a);
@ -162,8 +158,8 @@ public class VkRipper extends AlbumRipper {
} }
private Map<String,String> getPhotoIDsToURLs(String photoID) throws IOException { private Map<String,String> getPhotoIDsToURLs(String photoID) throws IOException {
Map<String,String> photoIDsToURLs = new HashMap<String,String>(); Map<String,String> photoIDsToURLs = new HashMap<>();
Map<String,String> postData = new HashMap<String,String>(); Map<String,String> postData = new HashMap<>();
// act=show&al=1&list=album45506334_172415053&module=photos&photo=45506334_304658196 // act=show&al=1&list=album45506334_172415053&module=photos&photo=45506334_304658196
postData.put("list", getGID(this.url)); postData.put("list", getGID(this.url));
postData.put("act", "show"); postData.put("act", "show");
@ -202,7 +198,7 @@ public class VkRipper extends AlbumRipper {
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://(www\\.)?vk\\.com/(photos|album|videos)-?([a-zA-Z0-9_]{1,}).*$"); Pattern p = Pattern.compile("^https?://(www\\.)?vk\\.com/(photos|album|videos)-?([a-zA-Z0-9_]+).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (!m.matches()) { if (!m.matches()) {
throw new MalformedURLException("Expected format: http://vk.com/album#### or vk.com/photos####"); throw new MalformedURLException("Expected format: http://vk.com/album#### or vk.com/photos####");

View File

@ -16,7 +16,7 @@ import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
public class WordpressComicRipper extends AbstractHTMLRipper { public class WordpressComicRipper extends AbstractHTMLRipper {
String pageTitle = ""; private String pageTitle = "";
public WordpressComicRipper(URL url) throws IOException { public WordpressComicRipper(URL url) throws IOException {
super(url); super(url);
@ -34,7 +34,7 @@ public class WordpressComicRipper extends AbstractHTMLRipper {
// http://tnbtu.com/comic/01-00/ // http://tnbtu.com/comic/01-00/
// http://shipinbottle.pepsaga.com/?p=281 // http://shipinbottle.pepsaga.com/?p=281
public static List<String> explicit_domains = Arrays.asList( private static List<String> explicit_domains = Arrays.asList(
"www.totempole666.com", "www.totempole666.com",
"buttsmithy.com", "buttsmithy.com",
"themonsterunderthebed.net", "themonsterunderthebed.net",
@ -49,14 +49,12 @@ public class WordpressComicRipper extends AbstractHTMLRipper {
@Override @Override
public String getHost() { public String getHost() {
String host = url.toExternalForm().split("/")[2]; return url.toExternalForm().split("/")[2];
return host;
} }
@Override @Override
public String getDomain() { public String getDomain() {
String host = url.toExternalForm().split("/")[2]; return url.toExternalForm().split("/")[2];
return host;
} }
@Override @Override
@ -130,7 +128,7 @@ public class WordpressComicRipper extends AbstractHTMLRipper {
@Override @Override
public String getAlbumTitle(URL url) throws MalformedURLException { public String getAlbumTitle(URL url) throws MalformedURLException {
Pattern totempole666Pat = Pattern.compile("(?:https?://)?(?:www\\.)?totempole666.com\\/comic/([a-zA-Z0-9_-]*)/?$"); Pattern totempole666Pat = Pattern.compile("(?:https?://)?(?:www\\.)?totempole666.com/comic/([a-zA-Z0-9_-]*)/?$");
Matcher totempole666Mat = totempole666Pat.matcher(url.toExternalForm()); Matcher totempole666Mat = totempole666Pat.matcher(url.toExternalForm());
if (totempole666Mat.matches()) { if (totempole666Mat.matches()) {
return "totempole666.com" + "_" + "The_cummoner"; return "totempole666.com" + "_" + "The_cummoner";
@ -237,7 +235,7 @@ public class WordpressComicRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
if (getHost().contains("www.totempole666.com") if (getHost().contains("www.totempole666.com")
|| getHost().contains("buttsmithy.com") || getHost().contains("buttsmithy.com")
|| getHost().contains("themonsterunderthebed.net") || getHost().contains("themonsterunderthebed.net")

View File

@ -57,7 +57,7 @@ public class XbooruRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> res = new ArrayList<String>(100); List<String> res = new ArrayList<>(100);
for (Element e : page.getElementsByTag("post")) { for (Element e : page.getElementsByTag("post")) {
res.add(e.absUrl("file_url") + "#" + e.attr("id")); res.add(e.absUrl("file_url") + "#" + e.attr("id"));
} }
@ -71,7 +71,7 @@ public class XbooruRipper extends AbstractHTMLRipper {
private String getTerm(URL url) throws MalformedURLException { private String getTerm(URL url) throws MalformedURLException {
if (gidPattern == null) { if (gidPattern == null) {
gidPattern = Pattern.compile("^https?://(www\\.)?xbooru\\.com/(index.php)?.*([?&]tags=([a-zA-Z0-9$_.+!*'(),%-]+))(\\&|(#.*)?$)"); gidPattern = Pattern.compile("^https?://(www\\.)?xbooru\\.com/(index.php)?.*([?&]tags=([a-zA-Z0-9$_.+!*'(),%-]+))(&|(#.*)?$)");
} }
Matcher m = gidPattern.matcher(url.toExternalForm()); Matcher m = gidPattern.matcher(url.toExternalForm());

View File

@ -87,7 +87,7 @@ public class XhamsterRipper extends AlbumRipper {
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[wmde.]*xhamster\\.com/photos/gallery/.*?(\\d{1,})$"); Pattern p = Pattern.compile("^https?://[wmde.]*xhamster\\.com/photos/gallery/.*?(\\d+)$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);

View File

@ -20,7 +20,7 @@ import com.rarchives.ripme.utils.Http;
public class ZizkiRipper extends AbstractHTMLRipper { public class ZizkiRipper extends AbstractHTMLRipper {
private Document albumDoc = null; private Document albumDoc = null;
private Map<String,String> cookies = new HashMap<String,String>(); private Map<String,String> cookies = new HashMap<>();
public ZizkiRipper(URL url) throws IOException { public ZizkiRipper(URL url) throws IOException {
super(url); super(url);
@ -76,7 +76,7 @@ public class ZizkiRipper extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<>();
// Page contains images // Page contains images
logger.info("Look for images."); logger.info("Look for images.");
for (Element thumb : page.select("img")) { for (Element thumb : page.select("img")) {
@ -99,7 +99,6 @@ public class ZizkiRipper extends AbstractHTMLRipper {
src = thumb.attr("src"); src = thumb.attr("src");
logger.debug("Found url with " + src); logger.debug("Found url with " + src);
if (!src.contains("zizki.com")) { if (!src.contains("zizki.com")) {
continue;
} else { } else {
imageURLs.add(src.replace("/styles/medium/public/","/styles/large/public/")); imageURLs.add(src.replace("/styles/medium/public/","/styles/large/public/"));
} }

View File

@ -48,7 +48,7 @@ public class tamindirmp3 extends AbstractHTMLRipper {
@Override @Override
public List<String> getURLsFromPage(Document doc) { public List<String> getURLsFromPage(Document doc) {
List<String> music = new ArrayList<String>(); List<String> music = new ArrayList<>();
for (Element el : doc.select("mp3")) { for (Element el : doc.select("mp3")) {
music.add(el.attr("src")); music.add(el.attr("src"));
} }

View File

@ -12,7 +12,7 @@ import java.util.regex.Pattern;
import static com.rarchives.ripme.App.logger; import static com.rarchives.ripme.App.logger;
public class ClipboardUtils { class ClipboardUtils {
private static AutoripThread autoripThread = new AutoripThread(); private static AutoripThread autoripThread = new AutoripThread();
public static void setClipboardAutoRip(boolean enabled) { public static void setClipboardAutoRip(boolean enabled) {
@ -38,11 +38,7 @@ public class ClipboardUtils {
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
e.printStackTrace(); e.printStackTrace();
logger.error("Caught and recovered from IllegalStateException: " + e.getMessage()); logger.error("Caught and recovered from IllegalStateException: " + e.getMessage());
} catch (HeadlessException e) { } catch (HeadlessException | IOException | UnsupportedFlavorException e) {
e.printStackTrace();
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
return null; return null;
@ -50,8 +46,8 @@ public class ClipboardUtils {
} }
class AutoripThread extends Thread { class AutoripThread extends Thread {
protected volatile boolean isRunning = false; volatile boolean isRunning = false;
Set<String> rippedURLs = new HashSet<String>(); private Set<String> rippedURLs = new HashSet<>();
public void run() { public void run() {
isRunning = true; isRunning = true;
@ -61,11 +57,11 @@ class AutoripThread extends Thread {
String clipboard = ClipboardUtils.getClipboardString(); String clipboard = ClipboardUtils.getClipboardString();
if (clipboard != null) { if (clipboard != null) {
Pattern p = Pattern.compile( Pattern p = Pattern.compile(
"\\b(((ht|f)tp(s?)\\:\\/\\/|~\\/|\\/)|www.)" + "\\b(((ht|f)tp(s?)://|~/|/)|www.)" +
"(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" + "(\\w+:\\w+@)?(([-\\w]+\\.)+(com|org|net|gov" +
"|mil|biz|info|mobi|name|aero|jobs|museum" + "|mil|biz|info|mobi|name|aero|jobs|museum" +
"|travel|[a-z]{2}))(:[\\d]{1,5})?" + "|travel|[a-z]{2}))(:[\\d]{1,5})?" +
"(((\\/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|\\/)+|\\?|#)?" + "(((/([-\\w~!$+|.,=]|%[a-f\\d]{2})+)+|/)+|\\?|#)?" +
"((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + "((\\?([-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +
"([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" + "([-\\w~!$+|.,*:=]|%[a-f\\d]{2})*)" +
"(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" + "(&(?:[-\\w~!$+|.,*:]|%[a-f\\d{2}])+=?" +

View File

@ -30,7 +30,7 @@ public class ContextMenuMouseListener extends MouseAdapter {
private String savedString = ""; private String savedString = "";
private Actions lastActionSelected; private Actions lastActionSelected;
private enum Actions { UNDO, CUT, COPY, PASTE, SELECT_ALL }; private enum Actions { UNDO, CUT, COPY, PASTE, SELECT_ALL }
@SuppressWarnings("serial") @SuppressWarnings("serial")
public ContextMenuMouseListener() { public ContextMenuMouseListener() {

View File

@ -26,7 +26,7 @@ public class History {
}; };
public History() { public History() {
this.list = new ArrayList<HistoryEntry>(); this.list = new ArrayList<>();
} }
public void add(HistoryEntry entry) { public void add(HistoryEntry entry) {
@ -90,7 +90,7 @@ public class History {
throw new RuntimeException("Could not find URL " + url + " in History"); throw new RuntimeException("Could not find URL " + url + " in History");
} }
public void fromJSON(JSONArray jsonArray) { private void fromJSON(JSONArray jsonArray) {
JSONObject json; JSONObject json;
for (int i = 0; i < jsonArray.length(); i++) { for (int i = 0; i < jsonArray.length(); i++) {
json = jsonArray.getJSONObject(i); json = jsonArray.getJSONObject(i);
@ -99,15 +99,12 @@ public class History {
} }
public void fromFile(String filename) throws IOException { public void fromFile(String filename) throws IOException {
InputStream is = new FileInputStream(filename); try (InputStream is = new FileInputStream(filename)) {
try {
String jsonString = IOUtils.toString(is); String jsonString = IOUtils.toString(is);
JSONArray jsonArray = new JSONArray(jsonString); JSONArray jsonArray = new JSONArray(jsonString);
fromJSON(jsonArray); fromJSON(jsonArray);
} catch (JSONException e) { } catch (JSONException e) {
throw new IOException("Failed to load JSON file " + filename + ": " + e.getMessage(), e); throw new IOException("Failed to load JSON file " + filename + ": " + e.getMessage(), e);
} finally {
is.close();
} }
} }
@ -119,7 +116,7 @@ public class History {
} }
} }
public JSONArray toJSON() { private JSONArray toJSON() {
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
for (HistoryEntry entry : list) { for (HistoryEntry entry : list) {
jsonArray.put(entry.toJSON()); jsonArray.put(entry.toJSON());
@ -136,11 +133,8 @@ public class History {
} }
public void toFile(String filename) throws IOException { public void toFile(String filename) throws IOException {
OutputStream os = new FileOutputStream(filename); try (OutputStream os = new FileOutputStream(filename)) {
try {
IOUtils.write(toJSON().toString(2), os); IOUtils.write(toJSON().toString(2), os);
} finally {
os.close();
} }
} }
} }

View File

@ -10,17 +10,13 @@ import javax.swing.Action;
import javax.swing.JPopupMenu; import javax.swing.JPopupMenu;
import javax.swing.JTable; import javax.swing.JTable;
public class HistoryMenuMouseListener extends MouseAdapter { class HistoryMenuMouseListener extends MouseAdapter {
private JPopupMenu popup = new JPopupMenu(); private JPopupMenu popup = new JPopupMenu();
private Action checkAllAction,
uncheckAllAction,
checkSelected,
uncheckSelected;
private JTable tableComponent; private JTable tableComponent;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public HistoryMenuMouseListener() { public HistoryMenuMouseListener() {
checkAllAction = new AbstractAction("Check All") { Action checkAllAction = new AbstractAction("Check All") {
@Override @Override
public void actionPerformed(ActionEvent ae) { public void actionPerformed(ActionEvent ae) {
for (int row = 0; row < tableComponent.getRowCount(); row++) { for (int row = 0; row < tableComponent.getRowCount(); row++) {
@ -30,7 +26,7 @@ public class HistoryMenuMouseListener extends MouseAdapter {
}; };
popup.add(checkAllAction); popup.add(checkAllAction);
uncheckAllAction = new AbstractAction("Check None") { Action uncheckAllAction = new AbstractAction("Check None") {
@Override @Override
public void actionPerformed(ActionEvent ae) { public void actionPerformed(ActionEvent ae) {
for (int row = 0; row < tableComponent.getRowCount(); row++) { for (int row = 0; row < tableComponent.getRowCount(); row++) {
@ -42,7 +38,7 @@ public class HistoryMenuMouseListener extends MouseAdapter {
popup.addSeparator(); popup.addSeparator();
checkSelected = new AbstractAction("Check Selected") { Action checkSelected = new AbstractAction("Check Selected") {
@Override @Override
public void actionPerformed(ActionEvent ae) { public void actionPerformed(ActionEvent ae) {
for (int row : tableComponent.getSelectedRows()) { for (int row : tableComponent.getSelectedRows()) {
@ -52,7 +48,7 @@ public class HistoryMenuMouseListener extends MouseAdapter {
}; };
popup.add(checkSelected); popup.add(checkSelected);
uncheckSelected = new AbstractAction("Uncheck Selected") { Action uncheckSelected = new AbstractAction("Uncheck Selected") {
@Override @Override
public void actionPerformed(ActionEvent ae) { public void actionPerformed(ActionEvent ae) {
for (int row : tableComponent.getSelectedRows()) { for (int row : tableComponent.getSelectedRows()) {

View File

@ -103,7 +103,6 @@ public final class MainWindow implements Runnable, RipStatusHandler {
private static JButton optionLog; private static JButton optionLog;
private static JPanel logPanel; private static JPanel logPanel;
private static JTextPane logText; private static JTextPane logText;
private static JScrollPane logTextScroll;
// History // History
private static JButton optionHistory; private static JButton optionHistory;
@ -111,8 +110,6 @@ public final class MainWindow implements Runnable, RipStatusHandler {
private static JPanel historyPanel; private static JPanel historyPanel;
private static JTable historyTable; private static JTable historyTable;
private static AbstractTableModel historyTableModel; private static AbstractTableModel historyTableModel;
private static JScrollPane historyTableScrollPane;
private static JPanel historyButtonPanel;
private static JButton historyButtonRemove, private static JButton historyButtonRemove,
historyButtonClear, historyButtonClear,
historyButtonRerip; historyButtonRerip;
@ -120,9 +117,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
// Queue // Queue
public static JButton optionQueue; public static JButton optionQueue;
private static JPanel queuePanel; private static JPanel queuePanel;
private static JList queueList;
private static DefaultListModel queueListModel; private static DefaultListModel queueListModel;
private static JScrollPane queueListScroll;
// Configuration // Configuration
private static JButton optionConfiguration; private static JButton optionConfiguration;
@ -150,8 +145,6 @@ public final class MainWindow implements Runnable, RipStatusHandler {
private static TrayIcon trayIcon; private static TrayIcon trayIcon;
private static MenuItem trayMenuMain; private static MenuItem trayMenuMain;
private static MenuItem trayMenuAbout;
private static MenuItem trayMenuExit;
private static CheckboxMenuItem trayMenuAutorip; private static CheckboxMenuItem trayMenuAutorip;
private static Image mainIcon; private static Image mainIcon;
@ -168,12 +161,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
loadHistory(); loadHistory();
setupHandlers(); setupHandlers();
Thread shutdownThread = new Thread() { Thread shutdownThread = new Thread(() -> shutdownCleanup());
@Override
public void run() {
shutdownCleanup();
}
};
Runtime.getRuntime().addShutdownHook(shutdownThread); Runtime.getRuntime().addShutdownHook(shutdownThread);
if (Utils.getConfigBoolean("auto.update", true)) { if (Utils.getConfigBoolean("auto.update", true)) {
@ -185,16 +173,11 @@ public final class MainWindow implements Runnable, RipStatusHandler {
trayMenuAutorip.setState(autoripEnabled); trayMenuAutorip.setState(autoripEnabled);
} }
public void upgradeProgram() { private void upgradeProgram() {
if (!configurationPanel.isVisible()) { if (!configurationPanel.isVisible()) {
optionConfiguration.doClick(); optionConfiguration.doClick();
} }
Runnable r = new Runnable() { Runnable r = () -> UpdateUtils.updateProgram(configUpdateLabel);
@Override
public void run() {
UpdateUtils.updateProgram(configUpdateLabel);
}
};
new Thread(r).start(); new Thread(r).start();
} }
@ -204,7 +187,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
mainFrame.setVisible(true); mainFrame.setVisible(true);
} }
public void shutdownCleanup() { private void shutdownCleanup() {
Utils.setConfigBoolean("file.overwrite", configOverwriteCheckbox.isSelected()); Utils.setConfigBoolean("file.overwrite", configOverwriteCheckbox.isSelected());
Utils.setConfigInteger("threads.size", Integer.parseInt(configThreadsText.getText())); Utils.setConfigInteger("threads.size", Integer.parseInt(configThreadsText.getText()));
Utils.setConfigInteger("download.retries", Integer.parseInt(configRetriesText.getText())); Utils.setConfigInteger("download.retries", Integer.parseInt(configRetriesText.getText()));
@ -241,12 +224,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} }
private void pack() { private void pack() {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(() -> mainFrame.pack());
@Override
public void run() {
mainFrame.pack();
}
});
} }
private void createUI(Container pane) { private void createUI(Container pane) {
@ -263,13 +241,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
try { try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) {
logger.error("[!] Exception setting system theme:", e);
} catch (InstantiationException e) {
logger.error("[!] Exception setting system theme:", e);
} catch (IllegalAccessException e) {
logger.error("[!] Exception setting system theme:", e);
} catch (UnsupportedLookAndFeelException e) {
logger.error("[!] Exception setting system theme:", e); logger.error("[!] Exception setting system theme:", e);
} }
@ -282,7 +254,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
try { try {
Image stopIcon = ImageIO.read(getClass().getClassLoader().getResource("stop.png")); Image stopIcon = ImageIO.read(getClass().getClassLoader().getResource("stop.png"));
stopButton.setIcon(new ImageIcon(stopIcon)); stopButton.setIcon(new ImageIcon(stopIcon));
} catch (Exception e) { } } catch (Exception ignored) { }
JPanel ripPanel = new JPanel(new GridBagLayout()); JPanel ripPanel = new JPanel(new GridBagLayout());
ripPanel.setBorder(emptyBorder); ripPanel.setBorder(emptyBorder);
@ -333,7 +305,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
logPanel = new JPanel(new GridBagLayout()); logPanel = new JPanel(new GridBagLayout());
logPanel.setBorder(emptyBorder); logPanel.setBorder(emptyBorder);
logText = new JTextPaneNoWrap(); logText = new JTextPaneNoWrap();
logTextScroll = new JScrollPane(logText); JScrollPane logTextScroll = new JScrollPane(logText);
logPanel.setVisible(false); logPanel.setVisible(false);
logPanel.setPreferredSize(new Dimension(300, 250)); logPanel.setPreferredSize(new Dimension(300, 250));
logPanel.add(logTextScroll, gbc); logPanel.add(logTextScroll, gbc);
@ -349,7 +321,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
return HISTORY.getColumnName(col); return HISTORY.getColumnName(col);
} }
@Override @Override
public Class<? extends Object> getColumnClass(int c) { public Class<?> getColumnClass(int c) {
return getValueAt(0, c).getClass(); return getValueAt(0, c).getClass();
} }
@Override @Override
@ -394,7 +366,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} }
historyTable.getColumnModel().getColumn(i).setPreferredWidth(width); historyTable.getColumnModel().getColumn(i).setPreferredWidth(width);
} }
historyTableScrollPane = new JScrollPane(historyTable); JScrollPane historyTableScrollPane = new JScrollPane(historyTable);
historyButtonRemove = new JButton("Remove"); historyButtonRemove = new JButton("Remove");
historyButtonClear = new JButton("Clear"); historyButtonClear = new JButton("Clear");
historyButtonRerip = new JButton("Re-rip Checked"); historyButtonRerip = new JButton("Re-rip Checked");
@ -405,7 +377,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
gbc.ipady = 180; gbc.ipady = 180;
historyPanel.add(historyTablePanel, gbc); historyPanel.add(historyTablePanel, gbc);
gbc.ipady = 0; gbc.ipady = 0;
historyButtonPanel = new JPanel(new GridBagLayout()); JPanel historyButtonPanel = new JPanel(new GridBagLayout());
historyButtonPanel.setPreferredSize(new Dimension(300, 10)); historyButtonPanel.setPreferredSize(new Dimension(300, 10));
historyButtonPanel.setBorder(emptyBorder); historyButtonPanel.setBorder(emptyBorder);
gbc.gridx = 0; historyButtonPanel.add(historyButtonRemove, gbc); gbc.gridx = 0; historyButtonPanel.add(historyButtonRemove, gbc);
@ -419,10 +391,10 @@ public final class MainWindow implements Runnable, RipStatusHandler {
queuePanel.setVisible(false); queuePanel.setVisible(false);
queuePanel.setPreferredSize(new Dimension(300, 250)); queuePanel.setPreferredSize(new Dimension(300, 250));
queueListModel = new DefaultListModel(); queueListModel = new DefaultListModel();
queueList = new JList(queueListModel); JList queueList = new JList(queueListModel);
queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); queueList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
queueList.addMouseListener(new QueueMenuMouseListener()); queueList.addMouseListener(new QueueMenuMouseListener());
queueListScroll = new JScrollPane(queueList, JScrollPane queueListScroll = new JScrollPane(queueList,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
for (String item : Utils.getConfigList("queue")) { for (String item : Utils.getConfigList("queue")) {
@ -568,148 +540,113 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} }
} }
}); });
stopButton.addActionListener(new ActionListener() { stopButton.addActionListener(event -> {
@Override if (ripper != null) {
public void actionPerformed(ActionEvent event) { ripper.stop();
if (ripper != null) { isRipping = false;
ripper.stop(); stopButton.setEnabled(false);
isRipping = false; statusProgress.setValue(0);
stopButton.setEnabled(false); statusProgress.setVisible(false);
statusProgress.setValue(0);
statusProgress.setVisible(false);
pack();
statusProgress.setValue(0);
status("Ripping interrupted");
appendLog("Ripper interrupted", Color.RED);
}
}
});
optionLog.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
logPanel.setVisible(!logPanel.isVisible());
historyPanel.setVisible(false);
queuePanel.setVisible(false);
configurationPanel.setVisible(false);
optionLog.setFont(optionLog.getFont().deriveFont(Font.BOLD));
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
pack(); pack();
statusProgress.setValue(0);
status("Ripping interrupted");
appendLog("Ripper interrupted", Color.RED);
} }
}); });
optionHistory.addActionListener(new ActionListener() { optionLog.addActionListener(event -> {
@Override logPanel.setVisible(!logPanel.isVisible());
public void actionPerformed(ActionEvent event) { historyPanel.setVisible(false);
logPanel.setVisible(false); queuePanel.setVisible(false);
historyPanel.setVisible(!historyPanel.isVisible()); configurationPanel.setVisible(false);
queuePanel.setVisible(false); optionLog.setFont(optionLog.getFont().deriveFont(Font.BOLD));
configurationPanel.setVisible(false); optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionHistory.setFont(optionLog.getFont().deriveFont(Font.BOLD)); optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); pack();
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
pack();
}
}); });
optionQueue.addActionListener(new ActionListener() { optionHistory.addActionListener(event -> {
@Override logPanel.setVisible(false);
public void actionPerformed(ActionEvent event) { historyPanel.setVisible(!historyPanel.isVisible());
logPanel.setVisible(false); queuePanel.setVisible(false);
historyPanel.setVisible(false); configurationPanel.setVisible(false);
queuePanel.setVisible(!queuePanel.isVisible()); optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
configurationPanel.setVisible(false); optionHistory.setFont(optionLog.getFont().deriveFont(Font.BOLD));
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionQueue.setFont(optionLog.getFont().deriveFont(Font.BOLD)); pack();
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
pack();
}
}); });
optionConfiguration.addActionListener(new ActionListener() { optionQueue.addActionListener(event -> {
@Override logPanel.setVisible(false);
public void actionPerformed(ActionEvent event) { historyPanel.setVisible(false);
logPanel.setVisible(false); queuePanel.setVisible(!queuePanel.isVisible());
historyPanel.setVisible(false); configurationPanel.setVisible(false);
queuePanel.setVisible(false); optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
configurationPanel.setVisible(!configurationPanel.isVisible()); optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionQueue.setFont(optionLog.getFont().deriveFont(Font.BOLD));
optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN)); pack();
optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.BOLD));
pack();
}
}); });
historyButtonRemove.addActionListener(new ActionListener() { optionConfiguration.addActionListener(event -> {
@Override logPanel.setVisible(false);
public void actionPerformed(ActionEvent event) { historyPanel.setVisible(false);
int[] indices = historyTable.getSelectedRows(); queuePanel.setVisible(false);
for (int i = indices.length - 1; i >= 0; i--) { configurationPanel.setVisible(!configurationPanel.isVisible());
int modelIndex = historyTable.convertRowIndexToModel(indices[i]); optionLog.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
HISTORY.remove(modelIndex); optionHistory.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
} optionQueue.setFont(optionLog.getFont().deriveFont(Font.PLAIN));
try { optionConfiguration.setFont(optionLog.getFont().deriveFont(Font.BOLD));
historyTableModel.fireTableDataChanged(); pack();
} catch (Exception e) { }
saveHistory();
}
}); });
historyButtonClear.addActionListener(new ActionListener() { historyButtonRemove.addActionListener(event -> {
@Override int[] indices = historyTable.getSelectedRows();
public void actionPerformed(ActionEvent event) { for (int i = indices.length - 1; i >= 0; i--) {
HISTORY.clear(); int modelIndex = historyTable.convertRowIndexToModel(indices[i]);
try { HISTORY.remove(modelIndex);
historyTableModel.fireTableDataChanged();
} catch (Exception e) { }
saveHistory();
} }
try {
historyTableModel.fireTableDataChanged();
} catch (Exception e) { }
saveHistory();
});
historyButtonClear.addActionListener(event -> {
HISTORY.clear();
try {
historyTableModel.fireTableDataChanged();
} catch (Exception e) { }
saveHistory();
}); });
// Re-rip all history // Re-rip all history
historyButtonRerip.addActionListener(new ActionListener() { historyButtonRerip.addActionListener(event -> {
@Override if (HISTORY.isEmpty()) {
public void actionPerformed(ActionEvent event) { JOptionPane.showMessageDialog(null,
if (HISTORY.isEmpty()) { "There are no history entries to re-rip. Rip some albums first",
JOptionPane.showMessageDialog(null, "RipMe Error",
"There are no history entries to re-rip. Rip some albums first", JOptionPane.ERROR_MESSAGE);
"RipMe Error", return;
JOptionPane.ERROR_MESSAGE); }
return; int added = 0;
} for (HistoryEntry entry : HISTORY.toList()) {
int added = 0; if (entry.selected) {
for (HistoryEntry entry : HISTORY.toList()) { added++;
if (entry.selected) { queueListModel.addElement(entry.url);
added++;
queueListModel.addElement(entry.url);
}
}
if (added == 0) {
JOptionPane.showMessageDialog(null,
"No history entries have been 'Checked'\n" +
"Check an entry by clicking the checkbox to the right of the URL or Right-click a URL to check/uncheck all items",
"RipMe Error",
JOptionPane.ERROR_MESSAGE);
} }
} }
if (added == 0) {
JOptionPane.showMessageDialog(null,
"No history entries have been 'Checked'\n" +
"Check an entry by clicking the checkbox to the right of the URL or Right-click a URL to check/uncheck all items",
"RipMe Error",
JOptionPane.ERROR_MESSAGE);
}
}); });
configUpdateButton.addActionListener(new ActionListener() { configUpdateButton.addActionListener(arg0 -> {
@Override Thread t = new Thread(() -> UpdateUtils.updateProgram(configUpdateLabel));
public void actionPerformed(ActionEvent arg0) { t.start();
Thread t = new Thread() {
@Override
public void run() {
UpdateUtils.updateProgram(configUpdateLabel);
}
};
t.start();
}
}); });
configLogLevelCombobox.addActionListener(new ActionListener() { configLogLevelCombobox.addActionListener(arg0 -> {
@Override String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString();
public void actionPerformed(ActionEvent arg0) { setLogLevel(level);
String level = ((JComboBox) arg0.getSource()).getSelectedItem().toString();
setLogLevel(level);
}
}); });
configSaveDirLabel.addMouseListener(new MouseAdapter() { configSaveDirLabel.addMouseListener(new MouseAdapter() {
@Override @Override
@ -721,90 +658,56 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} catch (Exception e1) { } } catch (Exception e1) { }
} }
}); });
configSaveDirButton.addActionListener(new ActionListener() { configSaveDirButton.addActionListener(arg0 -> {
@Override UIManager.put("FileChooser.useSystemExtensionHiding", false);
public void actionPerformed(ActionEvent arg0) { JFileChooser jfc = new JFileChooser(Utils.getWorkingDirectory());
UIManager.put("FileChooser.useSystemExtensionHiding", false); jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
JFileChooser jfc = new JFileChooser(Utils.getWorkingDirectory()); int returnVal = jfc.showDialog(null, "select directory");
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (returnVal != JFileChooser.APPROVE_OPTION) {
int returnVal = jfc.showDialog(null, "select directory"); return;
if (returnVal != JFileChooser.APPROVE_OPTION) {
return;
}
File chosenFile = jfc.getSelectedFile();
String chosenPath = null;
try {
chosenPath = chosenFile.getCanonicalPath();
} catch (Exception e) {
logger.error("Error while getting selected path: ", e);
return;
}
configSaveDirLabel.setText(Utils.shortenPath(chosenPath));
Utils.setConfigString("rips.directory", chosenPath);
} }
File chosenFile = jfc.getSelectedFile();
String chosenPath = null;
try {
chosenPath = chosenFile.getCanonicalPath();
} catch (Exception e) {
logger.error("Error while getting selected path: ", e);
return;
}
configSaveDirLabel.setText(Utils.shortenPath(chosenPath));
Utils.setConfigString("rips.directory", chosenPath);
}); });
configOverwriteCheckbox.addActionListener(new ActionListener() { configOverwriteCheckbox.addActionListener(arg0 -> Utils.setConfigBoolean("file.overwrite", configOverwriteCheckbox.isSelected()));
@Override configSaveOrderCheckbox.addActionListener(arg0 -> Utils.setConfigBoolean("download.save_order", configSaveOrderCheckbox.isSelected()));
public void actionPerformed(ActionEvent arg0) { configSaveLogs.addActionListener(arg0 -> {
Utils.setConfigBoolean("file.overwrite", configOverwriteCheckbox.isSelected()); Utils.setConfigBoolean("log.save", configSaveLogs.isSelected());
} Utils.configureLogger();
}); });
configSaveOrderCheckbox.addActionListener(new ActionListener() { configSaveURLsOnly.addActionListener(arg0 -> {
@Override Utils.setConfigBoolean("urls_only.save", configSaveURLsOnly.isSelected());
public void actionPerformed(ActionEvent arg0) { Utils.configureLogger();
Utils.setConfigBoolean("download.save_order", configSaveOrderCheckbox.isSelected());
}
}); });
configSaveLogs.addActionListener(new ActionListener() { configSaveAlbumTitles.addActionListener(arg0 -> {
@Override Utils.setConfigBoolean("album_titles.save", configSaveAlbumTitles.isSelected());
public void actionPerformed(ActionEvent arg0) { Utils.configureLogger();
Utils.setConfigBoolean("log.save", configSaveLogs.isSelected());
Utils.configureLogger();
}
}); });
configSaveURLsOnly.addActionListener(new ActionListener() { configClipboardAutorip.addActionListener(arg0 -> {
@Override Utils.setConfigBoolean("clipboard.autorip", configClipboardAutorip.isSelected());
public void actionPerformed(ActionEvent arg0) { ClipboardUtils.setClipboardAutoRip(configClipboardAutorip.isSelected());
Utils.setConfigBoolean("urls_only.save", configSaveURLsOnly.isSelected()); trayMenuAutorip.setState(configClipboardAutorip.isSelected());
Utils.configureLogger(); Utils.configureLogger();
}
}); });
configSaveAlbumTitles.addActionListener(new ActionListener() { configSaveDescriptions.addActionListener(arg0 -> {
@Override Utils.setConfigBoolean("descriptions.save", configSaveDescriptions.isSelected());
public void actionPerformed(ActionEvent arg0) { Utils.configureLogger();
Utils.setConfigBoolean("album_titles.save", configSaveAlbumTitles.isSelected());
Utils.configureLogger();
}
}); });
configClipboardAutorip.addActionListener(new ActionListener() { configPreferMp4.addActionListener(arg0 -> {
@Override Utils.setConfigBoolean("prefer.mp4", configPreferMp4.isSelected());
public void actionPerformed(ActionEvent arg0) { Utils.configureLogger();
Utils.setConfigBoolean("clipboard.autorip", configClipboardAutorip.isSelected());
ClipboardUtils.setClipboardAutoRip(configClipboardAutorip.isSelected());
trayMenuAutorip.setState(configClipboardAutorip.isSelected());
Utils.configureLogger();
}
}); });
configSaveDescriptions.addActionListener(new ActionListener() { configWindowPosition.addActionListener(arg0 -> {
@Override Utils.setConfigBoolean("window.position", configWindowPosition.isSelected());
public void actionPerformed(ActionEvent arg0) { Utils.configureLogger();
Utils.setConfigBoolean("descriptions.save", configSaveDescriptions.isSelected());
Utils.configureLogger();
}
});
configPreferMp4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Utils.setConfigBoolean("prefer.mp4", configPreferMp4.isSelected());
Utils.configureLogger();
}
});
configWindowPosition.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Utils.setConfigBoolean("window.position", configWindowPosition.isSelected());
Utils.configureLogger();
}
}); });
queueListModel.addListDataListener(new ListDataListener() { queueListModel.addListDataListener(new ListDataListener() {
@Override @Override
@ -828,17 +731,19 @@ public final class MainWindow implements Runnable, RipStatusHandler {
private void setLogLevel(String level) { private void setLogLevel(String level) {
Level newLevel = Level.ERROR; Level newLevel = Level.ERROR;
level = level.substring(level.lastIndexOf(' ') + 1); level = level.substring(level.lastIndexOf(' ') + 1);
if (level.equals("Debug")) { switch (level) {
newLevel = Level.DEBUG; case "Debug":
} newLevel = Level.DEBUG;
else if (level.equals("Info")) { break;
newLevel = Level.INFO; case "Info":
} newLevel = Level.INFO;
else if (level.equals("Warn")) { break;
newLevel = Level.WARN; case "Warn":
} newLevel = Level.WARN;
else if (level.equals("Error")) { break;
newLevel = Level.ERROR; case "Error":
newLevel = Level.ERROR;
break;
} }
Logger.getRootLogger().setLevel(newLevel); Logger.getRootLogger().setLevel(newLevel);
logger.setLevel(newLevel); logger.setLevel(newLevel);
@ -865,82 +770,66 @@ public final class MainWindow implements Runnable, RipStatusHandler {
}); });
PopupMenu trayMenu = new PopupMenu(); PopupMenu trayMenu = new PopupMenu();
trayMenuMain = new MenuItem("Hide"); trayMenuMain = new MenuItem("Hide");
trayMenuMain.addActionListener(new ActionListener() { trayMenuMain.addActionListener(arg0 -> toggleTrayClick());
@Override MenuItem trayMenuAbout = new MenuItem("About " + mainFrame.getTitle());
public void actionPerformed(ActionEvent arg0) { trayMenuAbout.addActionListener(arg0 -> {
toggleTrayClick(); StringBuilder about = new StringBuilder();
} about.append("<html><h1>")
}); .append(mainFrame.getTitle())
trayMenuAbout = new MenuItem("About " + mainFrame.getTitle()); .append("</h1>");
trayMenuAbout.addActionListener(new ActionListener() { about.append("Download albums from various websites:");
@Override try {
public void actionPerformed(ActionEvent arg0) { List<String> rippers = Utils.getListOfAlbumRippers();
StringBuilder about = new StringBuilder(); about.append("<ul>");
about.append("<html><h1>") for (String ripper : rippers) {
.append(mainFrame.getTitle()) about.append("<li>");
.append("</h1>"); ripper = ripper.substring(ripper.lastIndexOf('.') + 1);
about.append("Download albums from various websites:"); if (ripper.contains("Ripper")) {
try { ripper = ripper.substring(0, ripper.indexOf("Ripper"));
List<String> rippers = Utils.getListOfAlbumRippers();
about.append("<ul>");
for (String ripper : rippers) {
about.append("<li>");
ripper = ripper.substring(ripper.lastIndexOf('.') + 1);
if (ripper.contains("Ripper")) {
ripper = ripper.substring(0, ripper.indexOf("Ripper"));
}
about.append(ripper);
about.append("</li>");
} }
about.append("</ul>"); about.append(ripper);
} catch (Exception e) { } about.append("</li>");
about.append("<br>And download videos from video sites:"); }
try { about.append("</ul>");
List<String> rippers = Utils.getListOfVideoRippers(); } catch (Exception e) { }
about.append("<ul>"); about.append("<br>And download videos from video sites:");
for (String ripper : rippers) { try {
about.append("<li>"); List<String> rippers = Utils.getListOfVideoRippers();
ripper = ripper.substring(ripper.lastIndexOf('.') + 1); about.append("<ul>");
if (ripper.contains("Ripper")) { for (String ripper : rippers) {
ripper = ripper.substring(0, ripper.indexOf("Ripper")); about.append("<li>");
} ripper = ripper.substring(ripper.lastIndexOf('.') + 1);
about.append(ripper); if (ripper.contains("Ripper")) {
about.append("</li>"); ripper = ripper.substring(0, ripper.indexOf("Ripper"));
} }
about.append("</ul>"); about.append(ripper);
} catch (Exception e) { } about.append("</li>");
}
about.append("</ul>");
} catch (Exception e) { }
about.append("Do you want to visit the project homepage on Github?"); about.append("Do you want to visit the project homepage on Github?");
about.append("</html>"); about.append("</html>");
int response = JOptionPane.showConfirmDialog(null, int response = JOptionPane.showConfirmDialog(null,
about.toString(), about.toString(),
mainFrame.getTitle(), mainFrame.getTitle(),
JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE, JOptionPane.PLAIN_MESSAGE,
new ImageIcon(mainIcon)); new ImageIcon(mainIcon));
if (response == JOptionPane.YES_OPTION) { if (response == JOptionPane.YES_OPTION) {
try { try {
Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme")); Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme"));
} catch (IOException e) { } catch (IOException e) {
logger.error("Exception while opening project home page", e); logger.error("Exception while opening project home page", e);
}
} }
} }
}); });
trayMenuExit = new MenuItem("Exit"); MenuItem trayMenuExit = new MenuItem("Exit");
trayMenuExit.addActionListener(new ActionListener() { trayMenuExit.addActionListener(arg0 -> System.exit(0));
@Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
trayMenuAutorip = new CheckboxMenuItem("Clipboard Autorip"); trayMenuAutorip = new CheckboxMenuItem("Clipboard Autorip");
trayMenuAutorip.addItemListener(new ItemListener() { trayMenuAutorip.addItemListener(arg0 -> {
@Override ClipboardUtils.setClipboardAutoRip(trayMenuAutorip.getState());
public void itemStateChanged(ItemEvent arg0) { configClipboardAutorip.setSelected(trayMenuAutorip.getState());
ClipboardUtils.setClipboardAutoRip(trayMenuAutorip.getState());
configClipboardAutorip.setSelected(trayMenuAutorip.getState());
}
}); });
trayMenu.add(trayMenuMain); trayMenu.add(trayMenuMain);
trayMenu.add(trayMenuAbout); trayMenu.add(trayMenuAbout);
@ -966,10 +855,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
mainFrame.setAlwaysOnTop(false); mainFrame.setAlwaysOnTop(false);
} }
}); });
} catch (IOException e) { } catch (IOException | AWTException e) {
//TODO implement proper stack trace handling this is really just intented as a placeholder until you implement proper error handling
e.printStackTrace();
} catch (AWTException e) {
//TODO implement proper stack trace handling this is really just intented as a placeholder until you implement proper error handling //TODO implement proper stack trace handling this is really just intented as a placeholder until you implement proper error handling
e.printStackTrace(); e.printStackTrace();
} }
@ -1027,12 +913,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
if (HISTORY.toList().size() == 0) { if (HISTORY.toList().size() == 0) {
// Loaded from config, still no entries. // Loaded from config, still no entries.
// Guess rip history based on rip folder // Guess rip history based on rip folder
String[] dirs = Utils.getWorkingDirectory().list(new FilenameFilter() { String[] dirs = Utils.getWorkingDirectory().list((dir, file) -> new File(dir.getAbsolutePath() + File.separator + file).isDirectory());
@Override
public boolean accept(File dir, String file) {
return new File(dir.getAbsolutePath() + File.separator + file).isDirectory();
}
});
for (String dir : dirs) { for (String dir : dirs) {
String url = RipUtils.urlFromDirectoryName(dir); String url = RipUtils.urlFromDirectoryName(dir);
if (url != null) { if (url != null) {
@ -1131,7 +1012,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
try { try {
mainFrame.setTitle("Ripping - RipMe v" + UpdateUtils.getThisJarVersion()); mainFrame.setTitle("Ripping - RipMe v" + UpdateUtils.getThisJarVersion());
status("Starting rip..."); status("Starting rip...");
ripper.setObserver((RipStatusHandler) this); ripper.setObserver(this);
Thread t = new Thread(ripper); Thread t = new Thread(ripper);
if (configShowPopup.isSelected() && if (configShowPopup.isSelected() &&
(!mainFrame.isVisible() || !mainFrame.isActive())) { (!mainFrame.isVisible() || !mainFrame.isActive())) {
@ -1170,7 +1051,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
private final AbstractRipper ripper; private final AbstractRipper ripper;
private final RipStatusMessage msg; private final RipStatusMessage msg;
public StatusEvent(AbstractRipper ripper, RipStatusMessage msg) { StatusEvent(AbstractRipper ripper, RipStatusMessage msg) {
this.ripper = ripper; this.ripper = ripper;
this.msg = msg; this.msg = msg;
} }
@ -1195,11 +1076,11 @@ public final class MainWindow implements Runnable, RipStatusHandler {
case LOADING_RESOURCE: case LOADING_RESOURCE:
case DOWNLOAD_STARTED: case DOWNLOAD_STARTED:
if (logger.isEnabledFor(Level.INFO)) { if (logger.isEnabledFor(Level.INFO)) {
appendLog( "Downloading " + (String) msg.getObject(), Color.BLACK); appendLog( "Downloading " + msg.getObject(), Color.BLACK);
} }
break; break;
case DOWNLOAD_COMPLETE: case DOWNLOAD_COMPLETE:
appendLog( "Downloaded " + (String) msg.getObject(), Color.GREEN); appendLog( "Downloaded " + msg.getObject(), Color.GREEN);
break; break;
case DOWNLOAD_ERRORED: case DOWNLOAD_ERRORED:
if (logger.isEnabledFor(Level.ERROR)) { if (logger.isEnabledFor(Level.ERROR)) {
@ -1219,7 +1100,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
statusProgress.setVisible(false); statusProgress.setVisible(false);
openButton.setVisible(false); openButton.setVisible(false);
pack(); pack();
statusWithColor("Error: " + (String) msg.getObject(), Color.RED); statusWithColor("Error: " + msg.getObject(), Color.RED);
break; break;
case RIP_COMPLETE: case RIP_COMPLETE:
@ -1260,14 +1141,11 @@ public final class MainWindow implements Runnable, RipStatusHandler {
} catch (Exception e) { } } catch (Exception e) { }
appendLog( "Rip complete, saved to " + f.getAbsolutePath(), Color.GREEN); appendLog( "Rip complete, saved to " + f.getAbsolutePath(), Color.GREEN);
openButton.setActionCommand(f.toString()); openButton.setActionCommand(f.toString());
openButton.addActionListener(new ActionListener() { openButton.addActionListener(event -> {
@Override try {
public void actionPerformed(ActionEvent event) { Desktop.getDesktop().open(new File(event.getActionCommand()));
try { } catch (Exception e) {
Desktop.getDesktop().open(new File(event.getActionCommand())); logger.error(e);
} catch (Exception e) {
logger.error(e);
}
} }
}); });
pack(); pack();
@ -1310,26 +1188,20 @@ public final class MainWindow implements Runnable, RipStatusHandler {
Utils.setConfigBoolean("window.position", false); Utils.setConfigBoolean("window.position", false);
} }
public static boolean hasWindowPositionBug() { private static boolean hasWindowPositionBug() {
String osName = System.getProperty("os.name"); String osName = System.getProperty("os.name");
if (osName != null) { // Java on Windows has a bug where if we try to manually set the position of the Window,
// Java on Windows has a bug where if we try to manually set the position of the Window, // javaw.exe will not close itself down when the application is closed.
// javaw.exe will not close itself down when the application is closed. // Therefore, even if isWindowPositioningEnabled, if we are on Windows, we ignore it.
// Therefore, even if isWindowPositioningEnabled, if we are on Windows, we ignore it. return osName == null || osName.startsWith("Windows");
return osName.startsWith("Windows");
} else {
// If we're unsure, since we know there might be a bug,
// better be safe and report that the bug exists.
return true;
}
} }
public static boolean isWindowPositioningEnabled() { private static boolean isWindowPositioningEnabled() {
boolean isEnabled = Utils.getConfigBoolean("window.position", true); boolean isEnabled = Utils.getConfigBoolean("window.position", true);
return isEnabled && !hasWindowPositionBug(); return isEnabled && !hasWindowPositionBug();
} }
public static void saveWindowPosition(Frame frame) { private static void saveWindowPosition(Frame frame) {
if (!isWindowPositioningEnabled()) { if (!isWindowPositioningEnabled()) {
return; return;
} }
@ -1357,7 +1229,7 @@ public final class MainWindow implements Runnable, RipStatusHandler {
logger.debug("Saved window position (x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ")"); logger.debug("Saved window position (x=" + x + ", y=" + y + ", w=" + w + ", h=" + h + ")");
} }
public static void restoreWindowPosition(Frame frame) { private static void restoreWindowPosition(Frame frame) {
if (!isWindowPositioningEnabled()) { if (!isWindowPositioningEnabled()) {
mainFrame.setLocationRelativeTo(null); // default to middle of screen mainFrame.setLocationRelativeTo(null); // default to middle of screen
return; return;

View File

@ -14,17 +14,15 @@ import javax.swing.JPopupMenu;
import com.rarchives.ripme.utils.Utils; import com.rarchives.ripme.utils.Utils;
public class QueueMenuMouseListener extends MouseAdapter { class QueueMenuMouseListener extends MouseAdapter {
private JPopupMenu popup = new JPopupMenu(); private JPopupMenu popup = new JPopupMenu();
private Action removeSelected,
clearQueue;
private JList queueList; private JList queueList;
private DefaultListModel queueListModel; private DefaultListModel queueListModel;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public QueueMenuMouseListener() { public QueueMenuMouseListener() {
removeSelected = new AbstractAction("Remove Selected") { Action removeSelected = new AbstractAction("Remove Selected") {
@Override @Override
public void actionPerformed(ActionEvent ae) { public void actionPerformed(ActionEvent ae) {
Object o = queueList.getSelectedValue(); Object o = queueList.getSelectedValue();
@ -37,7 +35,7 @@ public class QueueMenuMouseListener extends MouseAdapter {
}; };
popup.add(removeSelected); popup.add(removeSelected);
clearQueue = new AbstractAction("Remove All") { Action clearQueue = new AbstractAction("Remove All") {
@Override @Override
public void actionPerformed(ActionEvent ae) { public void actionPerformed(ActionEvent ae) {
queueListModel.removeAllElements(); queueListModel.removeAllElements();

View File

@ -27,7 +27,7 @@ public class UpdateUtils {
private static final String mainFileName = "ripme.jar"; private static final String mainFileName = "ripme.jar";
private static final String updateFileName = "ripme.jar.update"; private static final String updateFileName = "ripme.jar.update";
public static String getUpdateJarURL(String latestVersion) { private static String getUpdateJarURL(String latestVersion) {
return "https://github.com/" + REPO_NAME + "/releases/download/" + latestVersion + "/ripme.jar"; return "https://github.com/" + REPO_NAME + "/releases/download/" + latestVersion + "/ripme.jar";
} }
@ -98,7 +98,6 @@ public class UpdateUtils {
JOptionPane.ERROR_MESSAGE); JOptionPane.ERROR_MESSAGE);
configUpdateLabel.setText(""); configUpdateLabel.setText("");
logger.error("Error while updating: ", e); logger.error("Error while updating: ", e);
return;
} }
} else { } else {
logger.debug("This version (" + UpdateUtils.getThisJarVersion() + logger.debug("This version (" + UpdateUtils.getThisJarVersion() +
@ -193,18 +192,15 @@ public class UpdateUtils {
bw.close(); bw.close();
logger.info("Saved update script to " + batchFile); logger.info("Saved update script to " + batchFile);
// Run updater script on exit // Run updater script on exit
Runtime.getRuntime().addShutdownHook(new Thread() { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
@Override try {
public void run() { logger.info("Executing: " + batchFile);
try { Runtime.getRuntime().exec(batchExec);
logger.info("Executing: " + batchFile); } catch (IOException e) {
Runtime.getRuntime().exec(batchExec); //TODO implement proper stack trace handling this is really just intented as a placeholder until you implement proper error handling
} catch (IOException e) { e.printStackTrace();
//TODO implement proper stack trace handling this is really just intented as a placeholder until you implement proper error handling
e.printStackTrace();
}
} }
}); }));
logger.info("Exiting older version, should execute update script (" + batchFile + ") during exit"); logger.info("Exiting older version, should execute update script (" + batchFile + ") during exit");
System.exit(0); System.exit(0);
} }

View File

@ -8,7 +8,7 @@ import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
public class AES { class AES {
/** /**
* Hack to get JCE Unlimited Strenght so we can use weird AES encryption stuff. * Hack to get JCE Unlimited Strenght so we can use weird AES encryption stuff.

View File

@ -22,7 +22,7 @@ import com.rarchives.ripme.ripper.AbstractRipper;
*/ */
public class Http { public class Http {
public static final int TIMEOUT = Utils.getConfigInteger("page.timeout", 5 * 1000); private static final int TIMEOUT = Utils.getConfigInteger("page.timeout", 5 * 1000);
private static final Logger logger = Logger.getLogger(AbstractRipper.class); private static final Logger logger = Logger.getLogger(AbstractRipper.class);
private int retries; private int retries;
@ -34,7 +34,7 @@ public class Http {
this.url = url; this.url = url;
defaultSettings(); defaultSettings();
} }
public Http(URL url) { private Http(URL url) {
this.url = url.toExternalForm(); this.url = url.toExternalForm();
defaultSettings(); defaultSettings();
} }
@ -92,7 +92,7 @@ public class Http {
return this; return this;
} }
public Http data(String name, String value) { public Http data(String name, String value) {
Map<String,String> data = new HashMap<String,String>(); Map<String,String> data = new HashMap<>();
data.put(name, value); data.put(name, value);
return data(data); return data(data);
} }
@ -132,7 +132,6 @@ public class Http {
} catch (IOException e) { } catch (IOException e) {
logger.warn("Error while loading " + url, e); logger.warn("Error while loading " + url, e);
lastException = e; lastException = e;
continue;
} }
} }
throw new IOException("Failed to load " + url + " after " + this.retries + " attempts", lastException); throw new IOException("Failed to load " + url + " after " + this.retries + " attempts", lastException);

View File

@ -27,7 +27,7 @@ public class RipUtils {
private static final Logger logger = Logger.getLogger(RipUtils.class); private static final Logger logger = Logger.getLogger(RipUtils.class);
public static List<URL> getFilesFromURL(URL url) { public static List<URL> getFilesFromURL(URL url) {
List<URL> result = new ArrayList<URL>(); List<URL> result = new ArrayList<>();
logger.debug("Checking " + url); logger.debug("Checking " + url);
// Imgur album // Imgur album
@ -104,7 +104,7 @@ public class RipUtils {
} }
// Direct link to image // Direct link to image
p = Pattern.compile("(https?://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(/\\S*)\\.(jpg|jpeg|gif|png|mp4)(\\?.*)?)"); p = Pattern.compile("(https?://[a-zA-Z0-9\\-.]+\\.[a-zA-Z]{2,3}(/\\S*)\\.(jpg|jpeg|gif|png|mp4)(\\?.*)?)");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
try { try {
@ -145,7 +145,7 @@ public class RipUtils {
} }
public static Pattern getURLRegex() { public static Pattern getURLRegex() {
return Pattern.compile("(https?://[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,3}(/\\S*))"); return Pattern.compile("(https?://[a-zA-Z0-9\\-.]+\\.[a-zA-Z]{2,3}(/\\S*))");
} }
public static String urlFromDirectoryName(String dir) { public static String urlFromDirectoryName(String dir) {
@ -182,14 +182,16 @@ public class RipUtils {
} }
String url = null; String url = null;
String[] fields = dir.split("_"); String[] fields = dir.split("_");
if (fields[0].equals("sub")) { switch (fields[0]) {
url = "http://reddit.com/r/" + dir; case "sub":
} url = "http://reddit.com/r/" + dir;
else if (fields[0].equals("user")) { break;
url = "http://reddit.com/user/" + dir; case "user":
} url = "http://reddit.com/user/" + dir;
else if (fields[0].equals("post")) { break;
url = "http://reddit.com/comments/" + dir; case "post":
url = "http://reddit.com/comments/" + dir;
break;
} }
return url; return url;
} }

View File

@ -34,7 +34,7 @@ import com.rarchives.ripme.ripper.AbstractRipper;
* Common utility functions used in various places throughout the project. * Common utility functions used in various places throughout the project.
*/ */
public class Utils { public class Utils {
public static final String RIP_DIRECTORY = "rips"; private static final String RIP_DIRECTORY = "rips";
private static final String configFile = "rip.properties"; private static final String configFile = "rip.properties";
private static final String OS = System.getProperty("os.name").toLowerCase(); private static final String OS = System.getProperty("os.name").toLowerCase();
private static final Logger logger = Logger.getLogger(Utils.class); private static final Logger logger = Logger.getLogger(Utils.class);
@ -107,7 +107,7 @@ public class Utils {
return config.getBoolean(key, defaultValue); return config.getBoolean(key, defaultValue);
} }
public static List<String> getConfigList(String key) { public static List<String> getConfigList(String key) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (Object obj : config.getList(key, new ArrayList<String>())) { for (Object obj : config.getList(key, new ArrayList<String>())) {
if (obj instanceof String) { if (obj instanceof String) {
result.add( (String) obj); result.add( (String) obj);
@ -124,7 +124,7 @@ public class Utils {
} }
public static void setConfigList(String key, Enumeration<Object> enumeration) { public static void setConfigList(String key, Enumeration<Object> enumeration) {
config.clearProperty(key); config.clearProperty(key);
List<Object> list = new ArrayList<Object>(); List<Object> list = new ArrayList<>();
while (enumeration.hasMoreElements()) { while (enumeration.hasMoreElements()) {
list.add(enumeration.nextElement()); list.add(enumeration.nextElement());
} }
@ -246,7 +246,7 @@ public class Utils {
* List of classes within the package * List of classes within the package
*/ */
public static ArrayList<Class<?>> getClassesForPackage(String pkgname) { public static ArrayList<Class<?>> getClassesForPackage(String pkgname) {
ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); ArrayList<Class<?>> classes = new ArrayList<>();
String relPath = pkgname.replace('.', '/'); String relPath = pkgname.replace('.', '/');
URL resource = ClassLoader.getSystemClassLoader().getResource(relPath); URL resource = ClassLoader.getSystemClassLoader().getResource(relPath);
if (resource == null) { if (resource == null) {
@ -311,7 +311,7 @@ public class Utils {
return classes; return classes;
} }
public static final int SHORTENED_PATH_LENGTH = 12; private static final int SHORTENED_PATH_LENGTH = 12;
public static String shortenPath(String path) { public static String shortenPath(String path) {
return shortenPath(new File(path)); return shortenPath(new File(path));
} }
@ -347,14 +347,14 @@ public class Utils {
} }
public static List<String> getListOfAlbumRippers() throws Exception { public static List<String> getListOfAlbumRippers() throws Exception {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for (Constructor<?> ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers")) { for (Constructor<?> ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers")) {
list.add(ripper.getName()); list.add(ripper.getName());
} }
return list; return list;
} }
public static List<String> getListOfVideoRippers() throws Exception { public static List<String> getListOfVideoRippers() throws Exception {
List<String> list = new ArrayList<String>(); List<String> list = new ArrayList<>();
for (Constructor<?> ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers.video")) { for (Constructor<?> ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers.video")) {
list.add(ripper.getName()); list.add(ripper.getName());
} }
@ -365,12 +365,9 @@ public class Utils {
URL resource = ClassLoader.getSystemClassLoader().getResource(filename); URL resource = ClassLoader.getSystemClassLoader().getResource(filename);
try { try {
final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class)); final Clip clip = (Clip) AudioSystem.getLine(new Line.Info(Clip.class));
clip.addLineListener(new LineListener() { clip.addLineListener(event -> {
@Override if (event.getType() == LineEvent.Type.STOP) {
public void update(LineEvent event) { clip.close();
if (event.getType() == LineEvent.Type.STOP) {
clip.close();
}
} }
}); });
clip.open(AudioSystem.getAudioInputStream(resource)); clip.open(AudioSystem.getAudioInputStream(resource));
@ -412,7 +409,7 @@ public class Utils {
* @return List of all strings that are between 'start' and 'finish' * @return List of all strings that are between 'start' and 'finish'
*/ */
public static List<String> between(String fullText, String start, String finish) { public static List<String> between(String fullText, String start, String finish) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
int i, j; int i, j;
i = fullText.indexOf(start); i = fullText.indexOf(start);
while (i >= 0) { while (i >= 0) {
@ -435,7 +432,7 @@ public class Utils {
* @return The map of all query parameters * @return The map of all query parameters
*/ */
public static Map<String,String> parseUrlQuery(String query) { public static Map<String,String> parseUrlQuery(String query) {
Map<String,String> res = new HashMap<String, String>(); Map<String,String> res = new HashMap<>();
if (query.equals("")) { if (query.equals("")) {
return res; return res;

View File

@ -10,7 +10,7 @@ import com.rarchives.ripme.ripper.rippers.ChanRipper;
public class ChanRipperTest extends RippersTest { public class ChanRipperTest extends RippersTest {
public void testChanURLFailures() throws IOException { public void testChanURLFailures() throws IOException {
List<URL> failURLs = new ArrayList<URL>(); List<URL> failURLs = new ArrayList<>();
// URLs that should not work // URLs that should not work
for (URL url : failURLs) { for (URL url : failURLs) {
try { try {
@ -18,13 +18,12 @@ public class ChanRipperTest extends RippersTest {
fail("Instantiated ripper for URL that should not work: " + url); fail("Instantiated ripper for URL that should not work: " + url);
} catch (Exception e) { } catch (Exception e) {
// Expected // Expected
continue;
} }
} }
} }
public void testChanURLPasses() throws IOException { public void testChanURLPasses() throws IOException {
List<URL> passURLs = new ArrayList<URL>(); List<URL> passURLs = new ArrayList<>();
// URLs that should work // URLs that should work
passURLs.add(new URL("http://desuchan.net/v/res/7034.html")); passURLs.add(new URL("http://desuchan.net/v/res/7034.html"));
passURLs.add(new URL("http://boards.4chan.org/hr/thread/2214511")); passURLs.add(new URL("http://boards.4chan.org/hr/thread/2214511"));
@ -46,7 +45,7 @@ public class ChanRipperTest extends RippersTest {
} }
public void testChanRipper() throws IOException { public void testChanRipper() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
// URLs that should return more than 1 image // URLs that should return more than 1 image
//contentURLs.add(new URL("http://desuchan.net/v/res/7034.html")); //contentURLs.add(new URL("http://desuchan.net/v/res/7034.html"));
//contentURLs.add(new URL("http://boards.420chan.org/ana/res/75984.php")); //contentURLs.add(new URL("http://boards.420chan.org/ana/res/75984.php"));

View File

@ -10,7 +10,7 @@ import com.rarchives.ripme.ripper.rippers.ImagefapRipper;
public class ImagefapRipperTest extends RippersTest { public class ImagefapRipperTest extends RippersTest {
public void testImagefapAlbums() throws IOException { public void testImagefapAlbums() throws IOException {
Map<URL, String> testURLs = new HashMap<URL, String>(); Map<URL, String> testURLs = new HashMap<>();
// Album with specific title // Album with specific title
testURLs.put(new URL("http://www.imagefap.com/pictures/4649440/Frozen-%28Elsa-and-Anna%29?view=2"), testURLs.put(new URL("http://www.imagefap.com/pictures/4649440/Frozen-%28Elsa-and-Anna%29?view=2"),
"Frozen (Elsa and Anna)"); "Frozen (Elsa and Anna)");

View File

@ -16,7 +16,7 @@ import com.rarchives.ripme.utils.Utils;
public class ImgurRipperTest extends RippersTest { public class ImgurRipperTest extends RippersTest {
public void testImgurURLFailures() throws IOException { public void testImgurURLFailures() throws IOException {
List<URL> failURLs = new ArrayList<URL>(); List<URL> failURLs = new ArrayList<>();
// Imgur urls that should not work // Imgur urls that should not work
failURLs.add(new URL("http://imgur.com")); failURLs.add(new URL("http://imgur.com"));
failURLs.add(new URL("http://imgur.com/")); failURLs.add(new URL("http://imgur.com/"));
@ -31,13 +31,12 @@ public class ImgurRipperTest extends RippersTest {
fail("Instantiated ripper for URL that should not work: " + url); fail("Instantiated ripper for URL that should not work: " + url);
} catch (Exception e) { } catch (Exception e) {
// Expected // Expected
continue;
} }
} }
} }
public void testImgurAlbums() throws IOException { public void testImgurAlbums() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
// URLs that should return more than 1 image // URLs that should return more than 1 image
contentURLs.add(new URL("http://imgur.com/a/dS9OQ#0")); // Horizontal layout contentURLs.add(new URL("http://imgur.com/a/dS9OQ#0")); // Horizontal layout
contentURLs.add(new URL("http://imgur.com/a/YpsW9#0")); // Grid layout contentURLs.add(new URL("http://imgur.com/a/YpsW9#0")); // Grid layout

View File

@ -12,7 +12,7 @@ import com.rarchives.ripme.ripper.rippers.InstagramRipper;
public class InstagramRipperTest extends RippersTest { public class InstagramRipperTest extends RippersTest {
public void testInstagramGID() throws IOException { public void testInstagramGID() throws IOException {
Map<URL, String> testURLs = new HashMap<URL, String>(); Map<URL, String> testURLs = new HashMap<>();
testURLs.put(new URL("http://instagram.com/Test_User"), "Test_User"); testURLs.put(new URL("http://instagram.com/Test_User"), "Test_User");
testURLs.put(new URL("http://instagram.com/_test_user_"), "_test_user_"); testURLs.put(new URL("http://instagram.com/_test_user_"), "_test_user_");
testURLs.put(new URL("http://instagram.com/-test-user-"), "-test-user-"); testURLs.put(new URL("http://instagram.com/-test-user-"), "-test-user-");
@ -25,7 +25,7 @@ public class InstagramRipperTest extends RippersTest {
} }
public void testInstagramAlbums() throws IOException { public void testInstagramAlbums() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
contentURLs.add(new URL("http://instagram.com/anacheri")); contentURLs.add(new URL("http://instagram.com/anacheri"));
for (URL url : contentURLs) { for (URL url : contentURLs) {
InstagramRipper ripper = new InstagramRipper(url); InstagramRipper ripper = new InstagramRipper(url);

View File

@ -10,7 +10,7 @@ import com.rarchives.ripme.ripper.rippers.NatalieMuRipper;
public class NatalieMuRipperTest extends RippersTest { public class NatalieMuRipperTest extends RippersTest {
public void testNatalieMuURLFailures() throws IOException { public void testNatalieMuURLFailures() throws IOException {
List<URL> failURLs = new ArrayList<URL>(); List<URL> failURLs = new ArrayList<>();
// URLs that should not work // URLs that should not work
for (URL url : failURLs) { for (URL url : failURLs) {
try { try {
@ -18,13 +18,12 @@ public class NatalieMuRipperTest extends RippersTest {
fail("Instantiated ripper for URL that should not work: " + url); fail("Instantiated ripper for URL that should not work: " + url);
} catch (Exception e) { } catch (Exception e) {
// Expected // Expected
continue;
} }
} }
} }
public void testNatalieMuURLPasses() throws IOException { public void testNatalieMuURLPasses() throws IOException {
List<URL> passURLs = new ArrayList<URL>(); List<URL> passURLs = new ArrayList<>();
// URLs that should work // URLs that should work
passURLs.add(new URL("http://natalie.mu/music/news/140367")); passURLs.add(new URL("http://natalie.mu/music/news/140367"));
passURLs.add(new URL("http://cdn2.natalie.mu/music/news/140411")); passURLs.add(new URL("http://cdn2.natalie.mu/music/news/140411"));
@ -41,7 +40,7 @@ public class NatalieMuRipperTest extends RippersTest {
} }
public void testNatalieMuRipper() throws IOException { public void testNatalieMuRipper() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
// URLs that should return more than 1 image // URLs that should return more than 1 image
contentURLs.add(new URL("http://natalie.mu/music/news/140367")); contentURLs.add(new URL("http://natalie.mu/music/news/140367"));
contentURLs.add(new URL("http://cdn2.natalie.mu/music/news/140411")); contentURLs.add(new URL("http://cdn2.natalie.mu/music/news/140411"));

View File

@ -18,14 +18,9 @@ import com.rarchives.ripme.utils.Utils;
*/ */
public class RippersTest extends TestCase { public class RippersTest extends TestCase {
public final Logger logger = Logger.getLogger(RippersTest.class); private final Logger logger = Logger.getLogger(RippersTest.class);
/** Dummy test to make JUnit not complain */ void testRipper(AbstractRipper ripper) {
public void test() {
assert(true);
}
protected void testRipper(AbstractRipper ripper) {
try { try {
// Turn on Debug logging // Turn on Debug logging
((ConsoleAppender)Logger.getRootLogger().getAppender("stdout")).setThreshold(Level.DEBUG); ((ConsoleAppender)Logger.getRootLogger().getAppender("stdout")).setThreshold(Level.DEBUG);
@ -61,7 +56,7 @@ public class RippersTest extends TestCase {
"txt", "log", "php"}; "txt", "log", "php"};
/** Recursively deletes a directory */ /** Recursively deletes a directory */
protected void deleteDir(File dir) { void deleteDir(File dir) {
if (!dir.getName().contains("_")) { if (!dir.getName().contains("_")) {
// All ripped albums contain an underscore // All ripped albums contain an underscore
// Don't delete an album if it doesn't have an underscore // Don't delete an album if it doesn't have an underscore
@ -83,7 +78,7 @@ public class RippersTest extends TestCase {
} }
dir.delete(); dir.delete();
} }
protected void deleteSubdirs(File workingDir) { void deleteSubdirs(File workingDir) {
for (File f : workingDir.listFiles()) { for (File f : workingDir.listFiles()) {
if (f.isDirectory()) { if (f.isDirectory()) {
for (File sf : f.listFiles()) { for (File sf : f.listFiles()) {

View File

@ -36,7 +36,7 @@ public class VideoRippersTest extends RippersTest {
} }
public void testXvideosRipper() throws IOException { public void testXvideosRipper() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
contentURLs.add(new URL("https://www.xvideos.com/video19719109/ziggy_star_ultra_hard_anal_pounding")); contentURLs.add(new URL("https://www.xvideos.com/video19719109/ziggy_star_ultra_hard_anal_pounding"));
contentURLs.add(new URL("https://www.xvideos.com/video23515878/dee_s_pool_toys")); contentURLs.add(new URL("https://www.xvideos.com/video23515878/dee_s_pool_toys"));
for (URL url : contentURLs) { for (URL url : contentURLs) {
@ -46,7 +46,7 @@ public class VideoRippersTest extends RippersTest {
} }
public void testPornhubRipper() throws IOException { public void testPornhubRipper() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
contentURLs.add(new URL("http://www.pornhub.com/view_video.php?viewkey=993166542")); contentURLs.add(new URL("http://www.pornhub.com/view_video.php?viewkey=993166542"));
for (URL url : contentURLs) { for (URL url : contentURLs) {
PornhubRipper ripper = new PornhubRipper(url); PornhubRipper ripper = new PornhubRipper(url);
@ -55,7 +55,7 @@ public class VideoRippersTest extends RippersTest {
} }
public void testVineRipper() throws IOException { public void testVineRipper() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
contentURLs.add(new URL("https://vine.co/v/hiqQrP0eUZx")); contentURLs.add(new URL("https://vine.co/v/hiqQrP0eUZx"));
for (URL url : contentURLs) { for (URL url : contentURLs) {
VineRipper ripper = new VineRipper(url); VineRipper ripper = new VineRipper(url);
@ -64,7 +64,7 @@ public class VideoRippersTest extends RippersTest {
} }
public void testYoupornRipper() throws IOException { public void testYoupornRipper() throws IOException {
List<URL> contentURLs = new ArrayList<URL>(); List<URL> contentURLs = new ArrayList<>();
contentURLs.add(new URL("http://www.youporn.com/watch/7669155/mrs-li-amateur-69-orgasm/?from=categ")); contentURLs.add(new URL("http://www.youporn.com/watch/7669155/mrs-li-amateur-69-orgasm/?from=categ"));
for (URL url : contentURLs) { for (URL url : contentURLs) {
YoupornRipper ripper = new YoupornRipper(url); YoupornRipper ripper = new YoupornRipper(url);