@@ -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}
0 commit comments