Skip to content

Commit 14afa96

Browse files
committed
8Muses support
1 parent 9576896 commit 14afa96

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.rarchives.ripme.ripper.rippers;
2+
3+
import java.io.IOException;
4+
import java.net.MalformedURLException;
5+
import java.net.URL;
6+
import java.util.regex.Matcher;
7+
import java.util.regex.Pattern;
8+
9+
import org.apache.log4j.Logger;
10+
import org.jsoup.Connection.Response;
11+
import org.jsoup.Jsoup;
12+
import org.jsoup.nodes.Document;
13+
import org.jsoup.nodes.Element;
14+
15+
import com.rarchives.ripme.ripper.AbstractRipper;
16+
17+
public class EightmusesRipper extends AbstractRipper {
18+
19+
private static final String DOMAIN = "8muses.com",
20+
HOST = "8muses";
21+
private static final Logger logger = Logger.getLogger(EightmusesRipper.class);
22+
23+
public EightmusesRipper(URL url) throws IOException {
24+
super(url);
25+
}
26+
27+
@Override
28+
public boolean canRip(URL url) {
29+
return url.getHost().endsWith(DOMAIN);
30+
}
31+
32+
@Override
33+
public URL sanitizeURL(URL url) throws MalformedURLException {
34+
return url;
35+
}
36+
37+
@Override
38+
public void rip() throws IOException {
39+
logger.info(" Retrieving " + this.url);
40+
Response resp = Jsoup.connect(this.url.toExternalForm())
41+
.userAgent(USER_AGENT)
42+
.execute();
43+
Document doc = resp.parse();
44+
int index = 0;
45+
for (Element thumb : doc.select("img")) {
46+
if (!thumb.hasAttr("data-cfsrc")) {
47+
continue;
48+
}
49+
String image = thumb.attr("data-cfsrc");
50+
if (image.contains("-cu_")) {
51+
image = image.replaceAll("-cu_[^.]+", "-me");
52+
}
53+
if (image.startsWith("//")) {
54+
image = "http:" + image;
55+
}
56+
//image = image.replace(" ", "%20");
57+
URL imageURL = new URL(image);
58+
index += 1;
59+
addURLToDownload(imageURL, String.format("%03d_", index));
60+
}
61+
waitForThreads();
62+
}
63+
64+
@Override
65+
public String getHost() {
66+
return HOST;
67+
}
68+
69+
@Override
70+
public String getGID(URL url) throws MalformedURLException {
71+
Pattern p = Pattern.compile("^https?://(www\\.)?8muses\\.com/index/category/([a-zA-Z0-9\\-_]+).*$");
72+
Matcher m = p.matcher(url.toExternalForm());
73+
if (!m.matches()) {
74+
throw new MalformedURLException("Expected URL format: http://www.8muses.com/index/category/albumname, got: " + url);
75+
}
76+
return m.group(m.groupCount());
77+
}
78+
79+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.rarchives.ripme.tst.ripper.rippers;
2+
3+
import java.io.IOException;
4+
import java.net.URL;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
import com.rarchives.ripme.ripper.rippers.EightmusesRipper;
9+
10+
public class EightmusesRipperTest extends RippersTest {
11+
12+
public void testEightmusesAlbums() throws IOException {
13+
if (!DOWNLOAD_CONTENT) {
14+
return;
15+
}
16+
List<URL> contentURLs = new ArrayList<URL>();
17+
18+
contentURLs.add(new URL("http://www.8muses.com/index/category/jab-hotassneighbor7"));
19+
20+
for (URL url : contentURLs) {
21+
try {
22+
EightmusesRipper ripper = new EightmusesRipper(url);
23+
ripper.rip();
24+
assert(ripper.getWorkingDir().listFiles().length > 1);
25+
deleteDir(ripper.getWorkingDir());
26+
} catch (Exception e) {
27+
e.printStackTrace();
28+
fail("Error while ripping URL " + url + ": " + e.getMessage());
29+
}
30+
}
31+
}
32+
33+
}

0 commit comments

Comments
 (0)