Skip to content

Commit 0827cc7

Browse files
chiang-shshan
andauthored
Fix DribbbleRipper to get image URLs (#2158)
* Update parsing logic for the site's new layout * Enable test Co-authored-by: shan <[email protected]>
1 parent a17d185 commit 0827cc7

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

src/main/java/com/rarchives/ripme/ripper/rippers/DribbbleRipper.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,39 +55,40 @@ public Document getNextPage(Document doc) throws IOException {
5555
@Override
5656
public List<String> getURLsFromPage(Document doc) {
5757
List<String> imageURLs = new ArrayList<>();
58-
for (Element thumbLink : doc.select("a.dribbble-link")) {
59-
// Resolve the absolute shot page URL
60-
String shotPage = thumbLink.absUrl("href");
61-
if (shotPage.isEmpty()) {
62-
continue;
63-
}
64-
65-
// Fetch the shot page
66-
Document shotDoc;
67-
try {
68-
shotDoc = Http.url(shotPage).get();
69-
} catch (IOException e) {
70-
continue;
71-
}
72-
73-
// Grab the first <img> (the full-size image) on that page
74-
Element imageEl = shotDoc.selectFirst("div.shot-page-container img");
75-
if (imageEl == null) {
76-
continue;
77-
}
78-
79-
// Always use absUrl so you get a complete URI or an empty string
80-
String imageURL = imageEl.absUrl("src");
81-
if (imageURL.isEmpty()) {
82-
continue;
58+
for (Element thumb : doc.select("div.shot-thumbnail-base > figure > img")) {
59+
String srcset = thumb.attr("data-srcset");
60+
String imageURL = getLargestImageURL(srcset);
61+
if (imageURL != null) {
62+
imageURLs.add(imageURL);
8363
}
84-
85-
imageURLs.add(imageURL);
8664
}
8765
return imageURLs;
8866
}
8967
@Override
9068
public void downloadURL(URL url, int index) {
9169
addURLToDownload(url, getPrefix(index));
9270
}
71+
72+
private String getLargestImageURL(String srcset) {
73+
int maxWidth = 0;
74+
String largestURL = null;
75+
76+
String[] imageURLs = srcset.split(", ");
77+
for (String imageURL : imageURLs) {
78+
try {
79+
String[] parts = imageURL.trim().split(" ");
80+
String url = parts[0];
81+
String size = parts[1];
82+
int width = Integer.parseInt(size.replace("w", ""));
83+
84+
if (width > maxWidth) {
85+
maxWidth = width;
86+
largestURL = url;
87+
}
88+
} catch (ArrayIndexOutOfBoundsException | NumberFormatException e) {
89+
continue;
90+
}
91+
}
92+
return largestURL;
93+
}
9394
}

src/test/java/com/rarchives/ripme/tst/ripper/rippers/DribbbleRipperTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import java.net.URISyntaxException;
66

77
import com.rarchives.ripme.ripper.rippers.DribbbleRipper;
8-
import org.junit.jupiter.api.Disabled;
98
import org.junit.jupiter.api.Test;
109

1110
public class DribbbleRipperTest extends RippersTest {
1211
@Test
13-
@Disabled("test or ripper broken")
1412
public void testDribbbleRip() throws IOException, URISyntaxException {
1513
DribbbleRipper ripper = new DribbbleRipper(new URI("https://dribbble.com/typogriff").toURL());
1614
testRipper(ripper);

0 commit comments

Comments
 (0)