From d30c4b606d0c0e581db4595a472413181814948e Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Mon, 19 Jun 2017 20:17:07 -0400 Subject: [PATCH 1/5] Removed broken json ripper --- .../ripme/ripper/rippers/ImgurRipper.java | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java index e59826cb..3c43bd29 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java @@ -241,43 +241,6 @@ public class ImgurRipper extends AlbumRipper { .get(); // Try to use embedded JSON to retrieve images - Pattern p = Pattern.compile("^.*Imgur\\.Album\\.getInstance\\((.*?)\\);.*$", Pattern.DOTALL); - Matcher m = p.matcher(doc.body().html()); - if (m.matches()) { - try { - JSONObject json = new JSONObject(m.group(1)); - JSONObject jsonAlbum = json.getJSONObject("album"); - ImgurAlbum imgurAlbum = new ImgurAlbum(url, jsonAlbum.getString("title_clean")); - JSONArray images = json.getJSONObject("images").getJSONArray("images"); - int imagesLength = images.length(); - for (int i = 0; i < imagesLength; i++) { - JSONObject image = images.getJSONObject(i); - String ext = image.getString("ext"); - if (ext.equals(".gif") && Utils.getConfigBoolean("prefer.mp4", false)) { - ext = ".mp4"; - } - URL imageURL = new URL( - // CDN url is provided elsewhere in the document - "http://i.imgur.com/" - + image.get("hash") - + ext); - String title = null, description = null; - if (image.has("title") && !image.isNull("title")) { - title = image.getString("title"); - } - if (image.has("description") && !image.isNull("description")) { - description = image.getString("description"); - } - ImgurImage imgurImage = new ImgurImage(imageURL, - title, - description); - imgurAlbum.addImage(imgurImage); - } - return imgurAlbum; - } catch (JSONException e) { - logger.debug("Error while parsing JSON at " + strUrl + ", continuing", e); - } - } p = Pattern.compile("^.*widgetFactory.mergeConfig\\('gallery', (.*?)\\);.*$", Pattern.DOTALL); m = p.matcher(doc.body().html()); if (m.matches()) { From 36c86462eadd8345f6a5612bb66b40c6424a653b Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 22 Jun 2017 09:37:55 -0400 Subject: [PATCH 2/5] Imgur ripper no longer adds Imgur: The most awesome images on the Internet to titles --- .../rarchives/ripme/ripper/rippers/ImgurRipper.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java index 3c43bd29..984b946e 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java @@ -108,6 +108,13 @@ public class ImgurRipper extends AlbumRipper { elems = albumDoc.select("meta[property=og:title]"); if (elems!=null) { title = elems.attr("content"); + logger.debug("[*] Title is " + title); + } + // This is here encase the album is unnamed, to prevent + // Imgur: The most awesome images on the Internet from being added onto the album name + if (title.contains("Imgur: The most awesome images on the Internet")) { + logger.debug("[*] Album is untitled or imgur is return no title"); + title = ""; } String albumTitle = "imgur_"; @@ -119,7 +126,7 @@ public class ImgurRipper extends AlbumRipper { */ albumTitle += gid; if (title != null) { - albumTitle += " (" + title + ")"; + albumTitle += "_" + title; } return albumTitle; @@ -241,8 +248,8 @@ public class ImgurRipper extends AlbumRipper { .get(); // Try to use embedded JSON to retrieve images - p = Pattern.compile("^.*widgetFactory.mergeConfig\\('gallery', (.*?)\\);.*$", Pattern.DOTALL); - m = p.matcher(doc.body().html()); + Pattern p = Pattern.compile("^.*widgetFactory.mergeConfig\\('gallery', (.*?)\\);.*$", Pattern.DOTALL); + Matcher m = p.matcher(doc.body().html()); if (m.matches()) { try { ImgurAlbum imgurAlbum = new ImgurAlbum(url); From 4ae28c3af3e35586d91c0dcbc06bbc107986becc Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 22 Jun 2017 09:48:17 -0400 Subject: [PATCH 3/5] Improved imgur title grabbing --- .../ripme/ripper/rippers/ImgurRipper.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java index 984b946e..4cfcb355 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java @@ -108,13 +108,25 @@ public class ImgurRipper extends AlbumRipper { elems = albumDoc.select("meta[property=og:title]"); if (elems!=null) { title = elems.attr("content"); - logger.debug("[*] Title is " + title); + logger.debug("Title is " + title); } // This is here encase the album is unnamed, to prevent // Imgur: The most awesome images on the Internet from being added onto the album name if (title.contains("Imgur: The most awesome images on the Internet")) { - logger.debug("[*] Album is untitled or imgur is return no title"); + logger.debug("Album is untitled or imgur is returning the default title"); + // We set the title to "" here because if it's found in the next few attempts it will be changed + // but if it's nto found there will be no reason to set it later title = ""; + logger.debug("Trying to use title tag to get title"); + elems = albumDoc.select("title"); + if (elems!=null) { + if (elems.text().contains("Imgur: The most awesome images on the Internet")) { + logger.debug("Was unable to get album title or album was untitled"); + } + else { + title = elems.text(); + } + } } String albumTitle = "imgur_"; From a0e3307ffba92f760098514a0073e676e0b49115 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 22 Jun 2017 14:04:53 -0400 Subject: [PATCH 4/5] Minor formating improvements --- .../java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java index 4cfcb355..dd9125cb 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java @@ -106,7 +106,7 @@ public class ImgurRipper extends AlbumRipper { String title = null; logger.info("Trying to get album title"); elems = albumDoc.select("meta[property=og:title]"); - if (elems!=null) { + if (elems != null) { title = elems.attr("content"); logger.debug("Title is " + title); } @@ -119,7 +119,7 @@ public class ImgurRipper extends AlbumRipper { title = ""; logger.debug("Trying to use title tag to get title"); elems = albumDoc.select("title"); - if (elems!=null) { + if (elems != null) { if (elems.text().contains("Imgur: The most awesome images on the Internet")) { logger.debug("Was unable to get album title or album was untitled"); } From d2a3a7a9b48cb4f9e830b5642a7c7fd97569df8f Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 22 Jun 2017 14:07:12 -0400 Subject: [PATCH 5/5] Made default imgur title a constant --- .../java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java index dd9125cb..0b7fd941 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/ImgurRipper.java @@ -104,6 +104,7 @@ public class ImgurRipper extends AlbumRipper { */ String title = null; + final String defaultTitle = "Imgur: The most awesome images on the Internet"; logger.info("Trying to get album title"); elems = albumDoc.select("meta[property=og:title]"); if (elems != null) { @@ -112,7 +113,7 @@ public class ImgurRipper extends AlbumRipper { } // This is here encase the album is unnamed, to prevent // Imgur: The most awesome images on the Internet from being added onto the album name - if (title.contains("Imgur: The most awesome images on the Internet")) { + if (title.contains(defaultTitle)) { logger.debug("Album is untitled or imgur is returning the default title"); // We set the title to "" here because if it's found in the next few attempts it will be changed // but if it's nto found there will be no reason to set it later @@ -120,7 +121,7 @@ public class ImgurRipper extends AlbumRipper { logger.debug("Trying to use title tag to get title"); elems = albumDoc.select("title"); if (elems != null) { - if (elems.text().contains("Imgur: The most awesome images on the Internet")) { + if (elems.text().contains(defaultTitle)) { logger.debug("Was unable to get album title or album was untitled"); } else {