@@ -48,11 +48,25 @@ public static void main(String[] args) throws IOException, InterruptedException
48
48
StringBuilder builder =new StringBuilder ();
49
49
// Extract and print all matched URLs
50
50
while (matcher .find ()) {
51
- String fileName =matcher .group (3 ).substring (matcher .group (3 ).lastIndexOf ('/' ) +1 );
52
- ImageDownloader .downloadImage (matcher .group (1 ),
53
- file .getParent () +"/"
54
- +fileName );
55
- matcher .appendReplacement (builder ,fileName );
51
+ String group =matcher .group (3 );
52
+ int lasted =group ==null ? -1 :group .lastIndexOf ('/' );
53
+ if (lasted >0 && !group .contains (":" )) {
54
+ String fileName =group .substring (lasted +1 ).toLowerCase ();
55
+ if (fileName .endsWith (".png" ) ||fileName .endsWith (".jpg" )
56
+ ||fileName .endsWith (".gif" ) ||fileName .endsWith (".svg" )
57
+ ||matcher .group (1 ).contains ("assets." )) {
58
+ if (!fileName .contains ("." )) {
59
+ fileName =fileName +".png" ;
60
+ }
61
+ if (!Files .exists (Path .of (file .getParent () +"/"
62
+ +fileName ))) {
63
+ ImageDownloader .downloadImage (matcher .group (1 ),
64
+ file .getParent () +"/"
65
+ +fileName );
66
+ matcher .appendReplacement (builder ,fileName );
67
+ }
68
+ }
69
+ }
56
70
}
57
71
matcher .appendTail (builder );
58
72
Files .writeString (file .toPath (),builder .toString (),UTF_8 );