Skip to content

Commit 3deddf3

Browse files
committed
Seenive support
1 parent 2e1ee0f commit 3deddf3

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
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.json.JSONObject;
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+
import com.rarchives.ripme.ripper.DownloadThreadPool;
17+
18+
public class SeeniveRipper extends AbstractRipper {
19+
20+
private static final String DOMAIN = "seenive.com",
21+
HOST = "seenive";
22+
private static final Logger logger = Logger.getLogger(SeeniveRipper.class);
23+
private static final String USER_AGENT =
24+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0";
25+
26+
private DownloadThreadPool seeniveThreadPool;
27+
28+
public SeeniveRipper(URL url) throws IOException {
29+
super(url);
30+
seeniveThreadPool = new DownloadThreadPool();
31+
}
32+
33+
@Override
34+
public boolean canRip(URL url) {
35+
return url.getHost().endsWith(DOMAIN);
36+
}
37+
38+
@Override
39+
public URL sanitizeURL(URL url) throws MalformedURLException {
40+
return url;
41+
}
42+
43+
@Override
44+
public void rip() throws IOException {
45+
String baseURL = this.url.toExternalForm();
46+
logger.info("[ ] Retrieving " + baseURL);
47+
Document doc = Jsoup.connect(baseURL)
48+
.header("Referer", baseURL)
49+
.userAgent(USER_AGENT)
50+
.timeout(5000)
51+
.get();
52+
while (true) {
53+
String lastID = null;
54+
for (Element element : doc.select("a.facebox")) {
55+
String card = element.attr("href"); // "/v/<video_id>"
56+
URL videoURL = new URL("https://seenive.com" + card);
57+
SeeniveImageThread vit = new SeeniveImageThread(videoURL);
58+
seeniveThreadPool.addThread(vit);
59+
lastID = card.substring(card.lastIndexOf('/') + 1);
60+
}
61+
if (lastID == null) {
62+
break;
63+
}
64+
65+
try {
66+
Thread.sleep(1000);
67+
} catch (InterruptedException e) {
68+
logger.error("[!] Interrupted while waiting to load next page", e);
69+
break;
70+
}
71+
72+
logger.info("[ ] Retrieving " + baseURL + "/next/" + lastID);
73+
String jsonString = Jsoup.connect(baseURL + "/next/" + lastID)
74+
.header("Referer", baseURL)
75+
.userAgent(USER_AGENT)
76+
.ignoreContentType(true)
77+
.execute().body();
78+
JSONObject json = new JSONObject(jsonString);
79+
String html = json.getString("Html");
80+
if (html.equals("")) {
81+
break;
82+
}
83+
doc = Jsoup.parse(html);
84+
}
85+
seeniveThreadPool.waitForThreads();
86+
waitForThreads();
87+
}
88+
89+
@Override
90+
public String getHost() {
91+
return HOST;
92+
}
93+
94+
@Override
95+
public String getGID(URL url) throws MalformedURLException {
96+
Pattern p = Pattern.compile("^https?://(www\\.)?seenive\\.com/u/([a-zA-Z0-9]{1,}).*$");
97+
Matcher m = p.matcher(url.toExternalForm());
98+
if (!m.matches()) {
99+
throw new MalformedURLException("Expected format: https://seenive.com/u/USERID");
100+
}
101+
return m.group(m.groupCount());
102+
}
103+
104+
/**
105+
* Helper class to find and download images found on "image" pages
106+
*/
107+
private class SeeniveImageThread extends Thread {
108+
private URL url;
109+
110+
public SeeniveImageThread(URL url) {
111+
super();
112+
this.url = url;
113+
}
114+
115+
@Override
116+
public void run() {
117+
try {
118+
Document doc = Jsoup.connect(this.url.toExternalForm())
119+
.userAgent(USER_AGENT)
120+
.get();
121+
logger.info("[ ] Retreiving video page " + this.url);
122+
for (Element element : doc.select("source")) {
123+
String video = element.attr("src");
124+
synchronized (threadPool) {
125+
addURLToDownload(new URL(video));
126+
}
127+
break;
128+
}
129+
} catch (IOException e) {
130+
logger.error("[!] Exception while loading/parsing " + this.url, e);
131+
}
132+
}
133+
}
134+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.SeeniveRipper;
9+
10+
public class SeeniveRipperTest extends RippersTest {
11+
12+
public void testSeeniveAlbums() throws IOException {
13+
if (!DOWNLOAD_CONTENT) {
14+
return;
15+
}
16+
List<URL> contentURLs = new ArrayList<URL>();
17+
contentURLs.add(new URL("http://seenive.com/u/946491170220040192"));
18+
for (URL url : contentURLs) {
19+
try {
20+
SeeniveRipper ripper = new SeeniveRipper(url);
21+
ripper.rip();
22+
assert(ripper.getWorkingDir().listFiles().length > 1);
23+
deleteDir(ripper.getWorkingDir());
24+
} catch (Exception e) {
25+
e.printStackTrace();
26+
fail("Error while ripping URL " + url + ": " + e.getMessage());
27+
}
28+
}
29+
}
30+
31+
}

0 commit comments

Comments
 (0)