-
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
165 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
src/main/java/com/rarchives/ripme/ripper/rippers/SeeniveRipper.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,134 @@ | ||
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.json.JSONObject; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
|
||
import com.rarchives.ripme.ripper.AbstractRipper; | ||
import com.rarchives.ripme.ripper.DownloadThreadPool; | ||
|
||
public class SeeniveRipper extends AbstractRipper { | ||
|
||
private static final String DOMAIN = "seenive.com", | ||
HOST = "seenive"; | ||
private static final Logger logger = Logger.getLogger(SeeniveRipper.class); | ||
private static final String USER_AGENT = | ||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0"; | ||
|
||
private DownloadThreadPool seeniveThreadPool; | ||
|
||
public SeeniveRipper(URL url) throws IOException { | ||
super(url); | ||
seeniveThreadPool = new DownloadThreadPool(); | ||
} | ||
|
||
@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 { | ||
String baseURL = this.url.toExternalForm(); | ||
logger.info("[ ] Retrieving " + baseURL); | ||
Document doc = Jsoup.connect(baseURL) | ||
.header("Referer", baseURL) | ||
.userAgent(USER_AGENT) | ||
.timeout(5000) | ||
.get(); | ||
while (true) { | ||
String lastID = null; | ||
for (Element element : doc.select("a.facebox")) { | ||
String card = element.attr("href"); // "/v/<video_id>" | ||
URL videoURL = new URL("https://seenive.com" + card); | ||
SeeniveImageThread vit = new SeeniveImageThread(videoURL); | ||
seeniveThreadPool.addThread(vit); | ||
lastID = card.substring(card.lastIndexOf('/') + 1); | ||
} | ||
if (lastID == null) { | ||
break; | ||
} | ||
|
||
try { | ||
Thread.sleep(1000); | ||
} catch (InterruptedException e) { | ||
logger.error("[!] Interrupted while waiting to load next page", e); | ||
break; | ||
} | ||
|
||
logger.info("[ ] Retrieving " + baseURL + "/next/" + lastID); | ||
String jsonString = Jsoup.connect(baseURL + "/next/" + lastID) | ||
.header("Referer", baseURL) | ||
.userAgent(USER_AGENT) | ||
.ignoreContentType(true) | ||
.execute().body(); | ||
JSONObject json = new JSONObject(jsonString); | ||
String html = json.getString("Html"); | ||
if (html.equals("")) { | ||
break; | ||
} | ||
doc = Jsoup.parse(html); | ||
} | ||
seeniveThreadPool.waitForThreads(); | ||
waitForThreads(); | ||
} | ||
|
||
@Override | ||
public String getHost() { | ||
return HOST; | ||
} | ||
|
||
@Override | ||
public String getGID(URL url) throws MalformedURLException { | ||
Pattern p = Pattern.compile("^https?://(www\\.)?seenive\\.com/u/([a-zA-Z0-9]{1,}).*$"); | ||
Matcher m = p.matcher(url.toExternalForm()); | ||
if (!m.matches()) { | ||
throw new MalformedURLException("Expected format: https://seenive.com/u/USERID"); | ||
} | ||
return m.group(m.groupCount()); | ||
} | ||
|
||
/** | ||
* Helper class to find and download images found on "image" pages | ||
*/ | ||
private class SeeniveImageThread extends Thread { | ||
private URL url; | ||
|
||
public SeeniveImageThread(URL url) { | ||
super(); | ||
this.url = url; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
try { | ||
Document doc = Jsoup.connect(this.url.toExternalForm()) | ||
.userAgent(USER_AGENT) | ||
.get(); | ||
logger.info("[ ] Retreiving video page " + this.url); | ||
for (Element element : doc.select("source")) { | ||
String video = element.attr("src"); | ||
synchronized (threadPool) { | ||
addURLToDownload(new URL(video)); | ||
} | ||
break; | ||
} | ||
} catch (IOException e) { | ||
logger.error("[!] Exception while loading/parsing " + this.url, e); | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/java/com/rarchives/ripme/tst/ripper/rippers/SeeniveRipperTest.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,31 @@ | ||
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.SeeniveRipper; | ||
|
||
public class SeeniveRipperTest extends RippersTest { | ||
|
||
public void testSeeniveAlbums() throws IOException { | ||
if (!DOWNLOAD_CONTENT) { | ||
return; | ||
} | ||
List<URL> contentURLs = new ArrayList<URL>(); | ||
contentURLs.add(new URL("http://seenive.com/u/946491170220040192")); | ||
for (URL url : contentURLs) { | ||
try { | ||
SeeniveRipper ripper = new SeeniveRipper(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()); | ||
} | ||
} | ||
} | ||
|
||
} |