1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-29 00:29:55 +02:00

Fixed indentation.

This commit is contained in:
Tushar
2019-01-21 09:56:04 +05:30
parent 84a5206e06
commit 2797366319
2 changed files with 106 additions and 106 deletions

View File

@@ -17,106 +17,106 @@ import com.rarchives.ripme.ripper.DownloadThreadPool;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
public class LusciousRipper extends AbstractHTMLRipper { public class LusciousRipper extends AbstractHTMLRipper {
private static final int RETRY_COUNT = 5; // Keeping it high for read timeout exception. private static final int RETRY_COUNT = 5; // Keeping it high for read timeout exception.
private Pattern p = Pattern.compile("^https?://(?:members.)?luscious\\.net/albums/([-_.0-9a-zA-Z]+).*$"); private Pattern p = Pattern.compile("^https?://(?:members.)?luscious\\.net/albums/([-_.0-9a-zA-Z]+).*$");
private DownloadThreadPool lusciousThreadPool = new DownloadThreadPool("lusciousThreadPool"); private DownloadThreadPool lusciousThreadPool = new DownloadThreadPool("lusciousThreadPool");
public LusciousRipper(URL url) throws IOException { public LusciousRipper(URL url) throws IOException {
super(url); super(url);
} }
@Override @Override
public String getDomain() { public String getDomain() {
return "luscious.net"; return "luscious.net";
} }
@Override @Override
public String getHost() { public String getHost() {
return "luscious"; return "luscious";
} }
@Override @Override
public Document getFirstPage() throws IOException { public Document getFirstPage() throws IOException {
// "url" is an instance field of the superclass // "url" is an instance field of the superclass
Document page = Http.url(url).get(); Document page = Http.url(url).get();
LOGGER.info("First page is " + url); LOGGER.info("First page is " + url);
return page; return page;
} }
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> urls = new ArrayList<>(); List<String> urls = new ArrayList<>();
Elements urlElements = page.select("div.item.thumbnail.ic_container > a"); Elements urlElements = page.select("div.item.thumbnail.ic_container > a");
for (Element e : urlElements) { for (Element e : urlElements) {
urls.add(e.attr("abs:href")); urls.add(e.attr("abs:href"));
} }
return urls; return urls;
} }
@Override @Override
public Document getNextPage(Document doc) throws IOException { public Document getNextPage(Document doc) throws IOException {
// luscious sends xhr requests to nextPageUrl and appends new set of images to the current page while in browser. // luscious sends xhr requests to nextPageUrl and appends new set of images to the current page while in browser.
// Simply GET the nextPageUrl also works. Therefore, we do this... // Simply GET the nextPageUrl also works. Therefore, we do this...
Element nextPageElement = doc.select("div#next_page > div > a").first(); Element nextPageElement = doc.select("div#next_page > div > a").first();
if (nextPageElement == null) { if (nextPageElement == null) {
throw new IOException("No next page found."); throw new IOException("No next page found.");
} }
return Http.url(nextPageElement.attr("abs:href")).get(); return Http.url(nextPageElement.attr("abs:href")).get();
} }
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
} }
throw new MalformedURLException("Expected luscious.net URL format: " throw new MalformedURLException("Expected luscious.net URL format: "
+ "luscious.net/albums/albumname \n members.luscious.net/albums/albumname - got " + url + " instead."); + "luscious.net/albums/albumname \n members.luscious.net/albums/albumname - got " + url + " instead.");
} }
@Override @Override
public void downloadURL(URL url, int index) { public void downloadURL(URL url, int index) {
lusciousThreadPool.addThread(new LusciousDownloadThread(url, index)); lusciousThreadPool.addThread(new LusciousDownloadThread(url, index));
} }
@Override @Override
public DownloadThreadPool getThreadPool() { public DownloadThreadPool getThreadPool() {
return lusciousThreadPool; return lusciousThreadPool;
} }
public class LusciousDownloadThread extends Thread { public class LusciousDownloadThread extends Thread {
private URL url; private URL url;
private int index; private int index;
public LusciousDownloadThread(URL url, int index) { public LusciousDownloadThread(URL url, int index) {
this.url = url; this.url = url;
this.index = index; this.index = index;
} }
@Override @Override
public void run() { public void run() {
try { try {
Document page = Http.url(url).retries(RETRY_COUNT).get(); Document page = Http.url(url).retries(RETRY_COUNT).get();
String downloadUrl = page.select(".icon-download").attr("abs:href"); String downloadUrl = page.select(".icon-download").attr("abs:href");
if (downloadUrl.equals("")) { if (downloadUrl.equals("")) {
// This is here for pages with mp4s instead of images. // This is here for pages with mp4s instead of images.
downloadUrl = page.select("div > video > source").attr("src"); downloadUrl = page.select("div > video > source").attr("src");
if (!downloadUrl.equals("")) { if (!downloadUrl.equals("")) {
throw new IOException("Could not find download url for image or video."); throw new IOException("Could not find download url for image or video.");
} }
} }
//If a valid download url was found. //If a valid download url was found.
addURLToDownload(new URL(downloadUrl), getPrefix(index)); addURLToDownload(new URL(downloadUrl), getPrefix(index));
} catch (IOException e) { } catch (IOException e) {
LOGGER.error("Error downloadiong url " + url, e); LOGGER.error("Error downloadiong url " + url, e);
} }
} }
} }
} }

View File

@@ -6,30 +6,30 @@ import java.net.URL;
import com.rarchives.ripme.ripper.rippers.LusciousRipper; import com.rarchives.ripme.ripper.rippers.LusciousRipper;
public class LusciousRipperTest extends RippersTest { public class LusciousRipperTest extends RippersTest {
public void testPahealRipper() throws IOException { public void testPahealRipper() throws IOException {
// a photo set // a photo set
LusciousRipper ripper = new LusciousRipper( LusciousRipper ripper = new LusciousRipper(
new URL("https://luscious.net/albums/h-na-alice-wa-suki-desu-ka-do-you-like-alice-when_321609/")); new URL("https://luscious.net/albums/h-na-alice-wa-suki-desu-ka-do-you-like-alice-when_321609/"));
testRipper(ripper); testRipper(ripper);
} }
public void testGetGID() throws IOException { public void testGetGID() throws IOException {
URL url = new URL("https://luscious.net/albums/h-na-alice-wa-suki-desu-ka-do-you-like-alice-when_321609/"); URL url = new URL("https://luscious.net/albums/h-na-alice-wa-suki-desu-ka-do-you-like-alice-when_321609/");
LusciousRipper ripper = new LusciousRipper(url); LusciousRipper ripper = new LusciousRipper(url);
assertEquals("h-na-alice-wa-suki-desu-ka-do-you-like-alice-when_321609", ripper.getGID(url)); assertEquals("h-na-alice-wa-suki-desu-ka-do-you-like-alice-when_321609", ripper.getGID(url));
} }
public void testGetNextPage() throws IOException { public void testGetNextPage() throws IOException {
URL multiPageAlbumUrl = new URL("https://luscious.net/albums/women-of-color_58/"); URL multiPageAlbumUrl = new URL("https://luscious.net/albums/women-of-color_58/");
LusciousRipper multiPageRipper = new LusciousRipper(multiPageAlbumUrl); LusciousRipper multiPageRipper = new LusciousRipper(multiPageAlbumUrl);
assert (multiPageRipper.getNextPage(multiPageRipper.getFirstPage()) != null); assert (multiPageRipper.getNextPage(multiPageRipper.getFirstPage()) != null);
URL singlePageAlbumUrl = new URL("https://members.luscious.net/albums/bakaneko-navidarks_332097/"); URL singlePageAlbumUrl = new URL("https://members.luscious.net/albums/bakaneko-navidarks_332097/");
LusciousRipper singlePageRipper = new LusciousRipper(singlePageAlbumUrl); LusciousRipper singlePageRipper = new LusciousRipper(singlePageAlbumUrl);
try { try {
singlePageRipper.getNextPage(singlePageRipper.getFirstPage()); singlePageRipper.getNextPage(singlePageRipper.getFirstPage());
} catch (IOException e) { } catch (IOException e) {
assertEquals("No next page found.", e.getMessage()); assertEquals("No next page found.", e.getMessage());
} }
} }
} }