From aac4fa48f5c64eae335d41ab51928dfaab6764a2 Mon Sep 17 00:00:00 2001 From: rephormat Date: Mon, 2 Jul 2018 19:49:47 -0500 Subject: [PATCH] Use descriptive naming when Save album titles option is enabled. Format is xhamster__. --- .../ripme/ripper/rippers/XhamsterRipper.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/XhamsterRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/XhamsterRipper.java index 026a6a30..96f20ec3 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/XhamsterRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/XhamsterRipper.java @@ -100,4 +100,23 @@ public class XhamsterRipper extends AbstractHTMLRipper { public void downloadURL(URL url, int index) { addURLToDownload(url, getPrefix(index)); } + + @Override + public String getAlbumTitle(URL url) throws MalformedURLException { + try { + // Attempt to use album title and username as GID + Document doc = getFirstPage(); + Element user = doc.select("a.author").first(); + String username = user.text(); + String path = url.getPath(); + Pattern p = Pattern.compile("^/photos/gallery/(.*)$"); + Matcher m = p.matcher(path); + if (m.matches() && !username.isEmpty()) { + return getHost() + "_" + username + "_" + m.group(1); + } + } catch (IOException e) { + // Fall back to default album naming convention + } + return super.getAlbumTitle(url); + } } \ No newline at end of file