mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-17 03:14:03 +02:00
Remove unsupported series of images for imgur ripper
This commit is contained in:
@@ -42,7 +42,6 @@ public class ImgurRipper extends AbstractHTMLRipper {
|
|||||||
USER_ALBUM,
|
USER_ALBUM,
|
||||||
USER_IMAGES,
|
USER_IMAGES,
|
||||||
SINGLE_IMAGE,
|
SINGLE_IMAGE,
|
||||||
SERIES_OF_IMAGES,
|
|
||||||
SUBREDDIT
|
SUBREDDIT
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,10 +181,6 @@ public class ImgurRipper extends AbstractHTMLRipper {
|
|||||||
// as it seems to cause the album to be downloaded to a subdir.
|
// as it seems to cause the album to be downloaded to a subdir.
|
||||||
ripAlbum(this.url);
|
ripAlbum(this.url);
|
||||||
break;
|
break;
|
||||||
case SERIES_OF_IMAGES:
|
|
||||||
LOGGER.info("Album type is SERIES_OF_IMAGES");
|
|
||||||
ripAlbum(this.url);
|
|
||||||
break;
|
|
||||||
case SINGLE_IMAGE:
|
case SINGLE_IMAGE:
|
||||||
LOGGER.info("Album type is SINGLE_IMAGE");
|
LOGGER.info("Album type is SINGLE_IMAGE");
|
||||||
ripSingleImage(this.url);
|
ripSingleImage(this.url);
|
||||||
@@ -250,39 +245,6 @@ public class ImgurRipper extends AbstractHTMLRipper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ImgurAlbum getImgurSeries(URL url) throws IOException {
|
|
||||||
Pattern p = Pattern.compile("^.*imgur\\.com/([a-zA-Z0-9,]*).*$");
|
|
||||||
Matcher m = p.matcher(url.toExternalForm());
|
|
||||||
ImgurAlbum album = new ImgurAlbum(url);
|
|
||||||
if (m.matches()) {
|
|
||||||
String[] imageIds = m.group(1).split(",");
|
|
||||||
for (String imageId : imageIds) {
|
|
||||||
// TODO: Fetch image with ID imageId
|
|
||||||
LOGGER.debug("Fetching image info for ID " + imageId);
|
|
||||||
try {
|
|
||||||
JSONObject json = Http.url("https://api.imgur.com/2/image/" + imageId + ".json").getJSON();
|
|
||||||
if (!json.has("image")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
JSONObject image = json.getJSONObject("image");
|
|
||||||
if (!image.has("links")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
JSONObject links = image.getJSONObject("links");
|
|
||||||
if (!links.has("original")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String original = links.getString("original");
|
|
||||||
ImgurImage theImage = new ImgurImage(new URI(original).toURL());
|
|
||||||
album.addImage(theImage);
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.error("Got exception while fetching imgur ID " + imageId, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return album;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ImgurAlbum getImgurAlbum(URL url) throws IOException, URISyntaxException {
|
public static ImgurAlbum getImgurAlbum(URL url) throws IOException, URISyntaxException {
|
||||||
String strUrl = url.toExternalForm();
|
String strUrl = url.toExternalForm();
|
||||||
if (!strUrl.contains(",")) {
|
if (!strUrl.contains(",")) {
|
||||||
@@ -563,17 +525,6 @@ public class ImgurRipper extends AbstractHTMLRipper {
|
|||||||
albumType = ALBUM_TYPE.SINGLE_IMAGE;
|
albumType = ALBUM_TYPE.SINGLE_IMAGE;
|
||||||
return m.group(m.groupCount());
|
return m.group(m.groupCount());
|
||||||
}
|
}
|
||||||
p = Pattern.compile("^https?://(i\\.|www\\.|m\\.)?imgur\\.com/([a-zA-Z0-9,]{5,}).*$");
|
|
||||||
m = p.matcher(url.toExternalForm());
|
|
||||||
if (m.matches()) {
|
|
||||||
// Series of imgur images
|
|
||||||
albumType = ALBUM_TYPE.SERIES_OF_IMAGES;
|
|
||||||
String gid = m.group(m.groupCount());
|
|
||||||
if (!gid.contains(",")) {
|
|
||||||
throw new MalformedURLException("Imgur image doesn't contain commas");
|
|
||||||
}
|
|
||||||
return gid.replaceAll(",", "-");
|
|
||||||
}
|
|
||||||
throw new MalformedURLException("Unsupported imgur URL format: " + url.toExternalForm());
|
throw new MalformedURLException("Unsupported imgur URL format: " + url.toExternalForm());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -46,19 +46,7 @@ public class RipUtils {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else if (url.getHost().endsWith("imgur.com") && url.toExternalForm().contains(",")) {
|
else if (url.getHost().endsWith("i.imgur.com") && url.toExternalForm().contains("gifv")) {
|
||||||
// Imgur image series.
|
|
||||||
try {
|
|
||||||
logger.debug("Fetching imgur series at " + url);
|
|
||||||
ImgurRipper.ImgurAlbum imgurAlbum = ImgurRipper.getImgurSeries(url);
|
|
||||||
for (ImgurRipper.ImgurImage imgurImage : imgurAlbum.images) {
|
|
||||||
logger.debug("Got imgur image: " + imgurImage.url);
|
|
||||||
result.add(imgurImage.url);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
logger.error("[!] Exception while loading album " + url, e);
|
|
||||||
}
|
|
||||||
} else if (url.getHost().endsWith("i.imgur.com") && url.toExternalForm().contains("gifv")) {
|
|
||||||
// links to imgur gifvs
|
// links to imgur gifvs
|
||||||
try {
|
try {
|
||||||
result.add(new URI(url.toExternalForm().replaceAll(".gifv", ".mp4")).toURL());
|
result.add(new URI(url.toExternalForm().replaceAll(".gifv", ".mp4")).toURL());
|
||||||
|
@@ -27,6 +27,8 @@ public class ImgurRipperTest extends RippersTest {
|
|||||||
failURLs.add(new URI("http://i.imgur.com/").toURL());
|
failURLs.add(new URI("http://i.imgur.com/").toURL());
|
||||||
failURLs.add(new URI("http://imgur.com/image.jpg").toURL());
|
failURLs.add(new URI("http://imgur.com/image.jpg").toURL());
|
||||||
failURLs.add(new URI("http://i.imgur.com/image.jpg").toURL());
|
failURLs.add(new URI("http://i.imgur.com/image.jpg").toURL());
|
||||||
|
// Imgur seems not to support URLs with lists of images anymore.
|
||||||
|
failURLs.add(new URI("http://imgur.com/758qD43,C6iVJex,bP7flAu,J3l85Ri,1U7fhu5,MbuAUCM,JF4vOXQ").toURL());
|
||||||
for (URL url : failURLs) {
|
for (URL url : failURLs) {
|
||||||
try {
|
try {
|
||||||
new ImgurRipper(url);
|
new ImgurRipper(url);
|
||||||
|
Reference in New Issue
Block a user