Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ ripme.jar.update
ripme.jar
rip.properties
history.json
.idea/
*.iml
15 changes: 15 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@
<artifactId>httpmime</artifactId>
<version>4.3.3</version>
</dependency>
<dependency>
<groupId>net.java.dev.jets3t</groupId>
<artifactId>jets3t</artifactId>
<version>0.9.4</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-drive</artifactId>
<version>v2-rev197-1.21.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.19.0</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/rarchives/ripme/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ private static void loadHistory() {
// Loaded from config, still no entries.
// Guess rip history based on rip folder
String[] dirs = Utils.getWorkingDirectory().list(new FilenameFilter() {
@Override
public boolean accept(File dir, String file) {
return new File(dir.getAbsolutePath() + File.separator + file).isDirectory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.net.URL;
import java.util.List;

import com.rarchives.ripme.storage.AbstractStorage;
import org.jsoup.nodes.Document;

import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
Expand All @@ -17,8 +18,8 @@
*/
public abstract class AbstractHTMLRipper extends AlbumRipper {

public AbstractHTMLRipper(URL url) throws IOException {
super(url);
public AbstractHTMLRipper(URL url, AbstractStorage storage) throws IOException {
super(url, storage);
}

public abstract String getDomain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.URL;
import java.util.List;

import com.rarchives.ripme.storage.AbstractStorage;
import org.json.JSONObject;

import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
Expand All @@ -15,8 +16,8 @@
*/
public abstract class AbstractJSONRipper extends AlbumRipper {

public AbstractJSONRipper(URL url) throws IOException {
super(url);
public AbstractJSONRipper(URL url, AbstractStorage storage) throws IOException {
super(url, storage);
}

public abstract String getDomain();
Expand Down
64 changes: 37 additions & 27 deletions src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import java.util.Map;
import java.util.Observable;

import com.rarchives.ripme.storage.AbstractStorage;
import com.rarchives.ripme.storage.FilesystemStorage;
import com.rarchives.ripme.storage.GDriveStorage;
import com.rarchives.ripme.storage.Jets3tStorage;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.jsoup.HttpStatusException;
Expand All @@ -21,7 +25,7 @@
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Utils;

public abstract class AbstractRipper
public abstract class AbstractRipper
extends Observable
implements RipperInterface, Runnable {

Expand All @@ -32,8 +36,10 @@ public abstract class AbstractRipper

protected URL url;
protected File workingDir;
protected String globalPrefix;
protected DownloadThreadPool threadPool;
protected RipStatusHandler observer = null;
protected AbstractStorage storage;

protected boolean completed = true;

Expand Down Expand Up @@ -65,11 +71,12 @@ protected void stopCheck() throws IOException {
* @throws IOException
* If anything goes wrong.
*/
public AbstractRipper(URL url) throws IOException {
public AbstractRipper(URL url, AbstractStorage storage) throws IOException {
if (!canRip(url)) {
throw new MalformedURLException("Unable to rip url: " + url);
}
this.url = sanitizeURL(url);
this.storage = storage;
}

public void setup() throws IOException {
Expand All @@ -95,8 +102,8 @@ public void setObserver(RipStatusHandler obs) {
* @param saveAs
* Path of the local file to save the content to.
*/
public abstract boolean addURLToDownload(URL url, File saveAs);
public abstract boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies);
public abstract boolean addURLToDownloadFullPath(URL url, String saveAs);
public abstract boolean addURLToDownload(URL url, String saveAs, String referrer, Map<String,String> cookies);

public boolean addURLToDownload(URL url, String prefix, String subdirectory, String referrer, Map<String,String> cookies) {
try {
Expand All @@ -112,26 +119,15 @@ public boolean addURLToDownload(URL url, String prefix, String subdirectory, Str
if (saveAs.indexOf('#') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('#')); }
if (saveAs.indexOf('&') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('&')); }
if (saveAs.indexOf(':') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf(':')); }
File saveFileAs;
try {
if (!subdirectory.equals("")) {
subdirectory = File.separator + subdirectory;
}
saveFileAs = new File(
workingDir.getCanonicalPath()
+ subdirectory
+ File.separator
+ prefix
+ saveAs);
} catch (IOException e) {
logger.error("[!] Error creating save file path for URL '" + url + "':", e);
return false;
String saveFileAs;
if (!subdirectory.equals("")) {
prefix = subdirectory + File.separator + prefix;
}
logger.debug("Downloading " + url + " to " + saveFileAs);
if (!saveFileAs.getParentFile().exists()) {
logger.info("[+] Creating directory: " + Utils.removeCWD(saveFileAs.getParent()));
saveFileAs.getParentFile().mkdirs();
if (globalPrefix != null && !globalPrefix.equals("")) {
prefix = globalPrefix + File.separator + prefix;
}
saveFileAs = prefix + saveAs;
logger.debug("Downloading " + url + " to " + saveFileAs);
return addURLToDownload(url, saveFileAs, referrer, cookies);
}

Expand Down Expand Up @@ -188,7 +184,7 @@ public void retrievingSource(String url) {
* @param saveAs
* Where the downloaded file is stored.
*/
public abstract void downloadCompleted(URL url, File saveAs);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google RipMe github

public abstract void downloadCompleted(URL url, String saveAs);
/**
* Notifies observers that a file could not be downloaded (includes a reason).
* @param url
Expand All @@ -201,7 +197,7 @@ public void retrievingSource(String url) {
* @param url
* @param message
*/
public abstract void downloadExists(URL url, File file);
public abstract void downloadExists(URL url, String file);

/**
* @return Number of files downloaded.
Expand Down Expand Up @@ -274,9 +270,23 @@ public String getAlbumTitle(URL url) throws MalformedURLException {
* If no compatible rippers can be found.
*/
public static AbstractRipper getRipper(URL url) throws Exception {
AbstractStorage storage;
String storageModule = Utils.getConfigString("storage.module", "file");

if (storageModule.equals("file")) {
storage = new FilesystemStorage();
} else if (storageModule.equals("jets3t")) {
storage = new Jets3tStorage();
} else if (storageModule.equals("gdrive")) {
storage = new GDriveStorage();
} else {
throw new Exception("Storage module " + storageModule + " is invalid.");
}
storage.configure();

for (Constructor<?> constructor : getRipperConstructors("com.rarchives.ripme.ripper.rippers")) {
try {
AlbumRipper ripper = (AlbumRipper) constructor.newInstance(url);
AlbumRipper ripper = (AlbumRipper) constructor.newInstance(url, storage);
logger.debug("Found album ripper: " + ripper.getClass().getName());
return ripper;
} catch (Exception e) {
Expand All @@ -285,7 +295,7 @@ public static AbstractRipper getRipper(URL url) throws Exception {
}
for (Constructor<?> constructor : getRipperConstructors("com.rarchives.ripme.ripper.rippers.video")) {
try {
VideoRipper ripper = (VideoRipper) constructor.newInstance(url);
VideoRipper ripper = (VideoRipper) constructor.newInstance(url, storage);
logger.debug("Found video ripper: " + ripper.getClass().getName());
return ripper;
} catch (Exception e) {
Expand All @@ -304,7 +314,7 @@ public static List<Constructor<?>> getRipperConstructors(String pkg) throws Exce
List<Constructor<?>> constructors = new ArrayList<Constructor<?>>();
for (Class<?> clazz : Utils.getClassesForPackage(pkg)) {
if (AbstractRipper.class.isAssignableFrom(clazz)) {
constructors.add( (Constructor<?>) clazz.getConstructor(URL.class) );
constructors.add( (Constructor<?>) clazz.getConstructor(URL.class, AbstractStorage.class) );
}
}
return constructors;
Expand Down
24 changes: 13 additions & 11 deletions src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
import java.util.HashMap;
import java.util.Map;

import com.rarchives.ripme.storage.AbstractStorage;
import com.rarchives.ripme.ui.RipStatusMessage;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Utils;

public abstract class AlbumRipper extends AbstractRipper {

protected Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<URL, File>());
protected Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, File>());
protected Map<URL, String> itemsPending = Collections.synchronizedMap(new HashMap<URL, String>());
protected Map<URL, String> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, String>());
protected Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<URL, String>());

public AlbumRipper(URL url) throws IOException {
super(url);
public AlbumRipper(URL url, AbstractStorage storage) throws IOException {
super(url, storage);
}

public abstract boolean canRip(URL url);
Expand All @@ -38,7 +39,7 @@ public int getCount() {
return itemsCompleted.size() + itemsErrored.size();
}

public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<String,String> cookies) {
public boolean addURLToDownload(URL url, String saveAs, String referrer, Map<String,String> cookies) {
// Only download one file if this is a test.
if (super.isThisATest() &&
(itemsPending.size() > 0 || itemsCompleted.size() > 0 || itemsErrored.size() > 0)) {
Expand All @@ -62,15 +63,15 @@ public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<Strin
fw.write("\n");
fw.close();
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, urlFile);
itemsCompleted.put(url, new File(urlFile));
itemsCompleted.put(url, urlFile);
observer.update(this, msg);
} catch (IOException e) {
logger.error("Error while writing to " + urlFile, e);
}
}
else {
itemsPending.put(url, saveAs);
DownloadFileThread dft = new DownloadFileThread(url, saveAs, this);
DownloadFileThread dft = new DownloadFileThread(url, saveAs, storage, this);
if (referrer != null) {
dft.setReferrer(referrer);
}
Expand All @@ -83,7 +84,7 @@ public boolean addURLToDownload(URL url, File saveAs, String referrer, Map<Strin
}

@Override
public boolean addURLToDownload(URL url, File saveAs) {
public boolean addURLToDownloadFullPath(URL url, String saveAs) {
return addURLToDownload(url, saveAs, null, null);
}

Expand All @@ -101,7 +102,7 @@ public boolean addURLToDownload(URL url) {
}

@Override
public void downloadCompleted(URL url, File saveAs) {
public void downloadCompleted(URL url, String saveAs) {
if (observer == null) {
return;
}
Expand Down Expand Up @@ -131,14 +132,14 @@ public void downloadErrored(URL url, String reason) {
}

@Override
public void downloadExists(URL url, File file) {
public void downloadExists(URL url, String file) {
if (observer == null) {
return;
}

itemsPending.remove(url);
itemsCompleted.put(url, file);
observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " already saved as " + file.getAbsolutePath()));
observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " already saved as " + file));

checkIfComplete();
}
Expand Down Expand Up @@ -177,6 +178,7 @@ public void setWorkingDir(URL url) throws IOException {
}
logger.debug("Using album title '" + title + "'");
title = Utils.filesystemSafe(title);
globalPrefix = title;
path += title + File.separator;
this.workingDir = new File(path);
if (!this.workingDir.exists()) {
Expand Down
Loading