From de0dda0d9fb86125b4e761cd7f68ee38a421830b Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 1 Jul 2018 21:49:00 -0400 Subject: [PATCH 1/5] Added ripper for loveroms.com --- .../ripme/ripper/rippers/LoveromRipper.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java new file mode 100644 index 00000000..cfc264a9 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java @@ -0,0 +1,111 @@ +package com.rarchives.ripme.ripper.rippers; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import com.rarchives.ripme.utils.Utils; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.rarchives.ripme.ripper.AbstractHTMLRipper; +import com.rarchives.ripme.utils.Http; + +public class LoveromRipper extends AbstractHTMLRipper { + + public LoveromRipper(URL url) throws IOException { + super(url); + } + + private int bytesTotal = 1; + private int bytesCompleted = 1; + + @Override + public String getHost() { + return "loveroms"; + } + + @Override + public String getDomain() { + return "loveroms.com"; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("https://www.loveroms.com/download/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/\\d+"); + Matcher m = p.matcher(url.toExternalForm()); + if (!m.matches()) { + throw new MalformedURLException("Expected URL format: https://www.loveroms.com/download/CONSOLE/GAME, got: " + url); + } + return m.group(1) + "_" + m.group(2); + } + + @Override + public Document getFirstPage() throws IOException { + // "url" is an instance field of the superclass + return Http.url(url).get(); + } + + + @Override + public List getURLsFromPage(Document doc) { + List result = new ArrayList<>(); + String downloadLink = doc.select("a#download_link").attr("href"); + if (downloadLink != null && !downloadLink.isEmpty()) { + result.add(downloadLink); + } else { + for (Element el : doc.select("a.multi-file-btn")) { + result.add(el.attr("href")); + } + } + return result; + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index)); + } + + @Override + public String getStatusText() { + return String.valueOf(getCompletionPercentage()) + + "% - " + + Utils.bytesToHumanReadable(bytesCompleted) + + " / " + + Utils.bytesToHumanReadable(bytesTotal); + } + +// @Override +// public int getCompletionPercentage() { +// return (int) (100 * (bytesCompleted / (float) bytesTotal)); +// } +// +// @Override +// public void setBytesTotal(int bytes) { +// this.bytesTotal = bytes; +// } +// +// @Override +// public void setBytesCompleted(int bytes) { +// this.bytesCompleted = bytes; +// } + +// @Override +// public boolean useByteProgessBar() {return true;} +// +// @Override +// public boolean tryResumeDownload() {return true;} + + @Override + public String getPrefix(int index) { + String prefix = ""; + if (keepSortOrder() && Utils.getConfigBoolean("download.save_order", true)) { + prefix = String.format("%03d_", index); + } + return prefix; + } +} From 4b7bd12313467fafef8a225ba903a155afeefd5a Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 3 Jul 2018 03:52:53 -0400 Subject: [PATCH 2/5] Uncommented out some code --- .../ripme/ripper/rippers/LoveromRipper.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java index cfc264a9..88c9c0f5 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java @@ -79,26 +79,26 @@ public class LoveromRipper extends AbstractHTMLRipper { Utils.bytesToHumanReadable(bytesTotal); } -// @Override -// public int getCompletionPercentage() { -// return (int) (100 * (bytesCompleted / (float) bytesTotal)); -// } -// -// @Override -// public void setBytesTotal(int bytes) { -// this.bytesTotal = bytes; -// } -// -// @Override -// public void setBytesCompleted(int bytes) { -// this.bytesCompleted = bytes; -// } + @Override + public int getCompletionPercentage() { + return (int) (100 * (bytesCompleted / (float) bytesTotal)); + } -// @Override -// public boolean useByteProgessBar() {return true;} -// -// @Override -// public boolean tryResumeDownload() {return true;} + @Override + public void setBytesTotal(int bytes) { + this.bytesTotal = bytes; + } + + @Override + public void setBytesCompleted(int bytes) { + this.bytesCompleted = bytes; + } + + @Override + public boolean useByteProgessBar() {return true;} + + @Override + public boolean tryResumeDownload() {return true;} @Override public String getPrefix(int index) { From 13dd2694b45ec21ead0f2ed2e7a1878645a44cf3 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Mon, 9 Jul 2018 11:19:15 -0400 Subject: [PATCH 3/5] Fixed multipart file downloading --- .../com/rarchives/ripme/ripper/rippers/LoveromRipper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java index 88c9c0f5..bddecf64 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java @@ -23,6 +23,7 @@ public class LoveromRipper extends AbstractHTMLRipper { private int bytesTotal = 1; private int bytesCompleted = 1; + boolean multipart = false; @Override public String getHost() { @@ -58,6 +59,7 @@ public class LoveromRipper extends AbstractHTMLRipper { if (downloadLink != null && !downloadLink.isEmpty()) { result.add(downloadLink); } else { + multipart = true; for (Element el : doc.select("a.multi-file-btn")) { result.add(el.attr("href")); } @@ -72,6 +74,9 @@ public class LoveromRipper extends AbstractHTMLRipper { @Override public String getStatusText() { + if (multipart) { + return super.getStatusText(); + } return String.valueOf(getCompletionPercentage()) + "% - " + Utils.bytesToHumanReadable(bytesCompleted) + @@ -81,6 +86,9 @@ public class LoveromRipper extends AbstractHTMLRipper { @Override public int getCompletionPercentage() { + if (multipart) { + return super.getCompletionPercentage(); + } return (int) (100 * (bytesCompleted / (float) bytesTotal)); } From 67e2451744af30b3ec2c221a7239dfba12e5c606 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Tue, 10 Jul 2018 13:24:56 -0400 Subject: [PATCH 4/5] Now properly names multi-part files; Updated to work with recent changes to site --- .../rarchives/ripme/ripper/rippers/LoveromRipper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java index bddecf64..83af405f 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/LoveromRipper.java @@ -55,7 +55,7 @@ public class LoveromRipper extends AbstractHTMLRipper { @Override public List getURLsFromPage(Document doc) { List result = new ArrayList<>(); - String downloadLink = doc.select("a#download_link").attr("href"); + String downloadLink = doc.select("a#start_download_link").attr("href"); if (downloadLink != null && !downloadLink.isEmpty()) { result.add(downloadLink); } else { @@ -69,7 +69,11 @@ public class LoveromRipper extends AbstractHTMLRipper { @Override public void downloadURL(URL url, int index) { - addURLToDownload(url, getPrefix(index)); + if (multipart) { + addURLToDownload(url, "", "", "", null, null, getPrefix(index)); + } else { + addURLToDownload(url); + } } @Override @@ -112,7 +116,7 @@ public class LoveromRipper extends AbstractHTMLRipper { public String getPrefix(int index) { String prefix = ""; if (keepSortOrder() && Utils.getConfigBoolean("download.save_order", true)) { - prefix = String.format("%03d_", index); + prefix = String.format("7z.%03d", index); } return prefix; } From f7a1255bab7d2bbfc1225a461b598adf930b459d Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Wed, 11 Jul 2018 13:52:29 -0400 Subject: [PATCH 5/5] Added loverom unit test --- .../ripme/tst/ripper/rippers/LoveromRipperTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/test/java/com/rarchives/ripme/tst/ripper/rippers/LoveromRipperTest.java diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/LoveromRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/LoveromRipperTest.java new file mode 100644 index 00000000..377b2212 --- /dev/null +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/LoveromRipperTest.java @@ -0,0 +1,13 @@ +package com.rarchives.ripme.tst.ripper.rippers; + +import com.rarchives.ripme.ripper.rippers.LoveromRipper; + +import java.io.IOException; +import java.net.URL; + +public class LoveromRipperTest extends RippersTest{ + public void testRip() throws IOException { + LoveromRipper ripper = new LoveromRipper(new URL("https://www.loveroms.com/download/nintendo/adventures-of-tom-sawyer-u/107165")); + testRipper(ripper); + } +}