-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/main/java/com/rarchives/ripme/ripper/rippers/EightmusesRipper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package com.rarchives.ripme.ripper.rippers; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.apache.log4j.Logger; | ||
import org.jsoup.Connection.Response; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
|
||
import com.rarchives.ripme.ripper.AbstractRipper; | ||
|
||
public class EightmusesRipper extends AbstractRipper { | ||
|
||
private static final String DOMAIN = "8muses.com", | ||
HOST = "8muses"; | ||
private static final Logger logger = Logger.getLogger(EightmusesRipper.class); | ||
|
||
public EightmusesRipper(URL url) throws IOException { | ||
super(url); | ||
} | ||
|
||
@Override | ||
public boolean canRip(URL url) { | ||
return url.getHost().endsWith(DOMAIN); | ||
} | ||
|
||
@Override | ||
public URL sanitizeURL(URL url) throws MalformedURLException { | ||
return url; | ||
} | ||
|
||
@Override | ||
public void rip() throws IOException { | ||
logger.info(" Retrieving " + this.url); | ||
Response resp = Jsoup.connect(this.url.toExternalForm()) | ||
.userAgent(USER_AGENT) | ||
.execute(); | ||
Document doc = resp.parse(); | ||
int index = 0; | ||
for (Element thumb : doc.select("img")) { | ||
if (!thumb.hasAttr("data-cfsrc")) { | ||
continue; | ||
} | ||
String image = thumb.attr("data-cfsrc"); | ||
if (image.contains("-cu_")) { | ||
image = image.replaceAll("-cu_[^.]+", "-me"); | ||
} | ||
if (image.startsWith("//")) { | ||
image = "http:" + image; | ||
} | ||
//image = image.replace(" ", "%20"); | ||
URL imageURL = new URL(image); | ||
index += 1; | ||
addURLToDownload(imageURL, String.format("%03d_", index)); | ||
} | ||
waitForThreads(); | ||
} | ||
|
||
@Override | ||
public String getHost() { | ||
return HOST; | ||
} | ||
|
||
@Override | ||
public String getGID(URL url) throws MalformedURLException { | ||
Pattern p = Pattern.compile("^https?://(www\\.)?8muses\\.com/index/category/([a-zA-Z0-9\\-_]+).*$"); | ||
Matcher m = p.matcher(url.toExternalForm()); | ||
if (!m.matches()) { | ||
throw new MalformedURLException("Expected URL format: http://www.8muses.com/index/category/albumname, got: " + url); | ||
} | ||
return m.group(m.groupCount()); | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/test/java/com/rarchives/ripme/tst/ripper/rippers/EightmusesRipperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.rarchives.ripme.tst.ripper.rippers; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.rarchives.ripme.ripper.rippers.EightmusesRipper; | ||
|
||
public class EightmusesRipperTest extends RippersTest { | ||
|
||
public void testEightmusesAlbums() throws IOException { | ||
if (!DOWNLOAD_CONTENT) { | ||
return; | ||
} | ||
List<URL> contentURLs = new ArrayList<URL>(); | ||
|
||
contentURLs.add(new URL("http://www.8muses.com/index/category/jab-hotassneighbor7")); | ||
|
||
for (URL url : contentURLs) { | ||
try { | ||
EightmusesRipper ripper = new EightmusesRipper(url); | ||
ripper.rip(); | ||
assert(ripper.getWorkingDir().listFiles().length > 1); | ||
deleteDir(ripper.getWorkingDir()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
fail("Error while ripping URL " + url + ": " + e.getMessage()); | ||
} | ||
} | ||
} | ||
|
||
} |