1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package Torello.HTML.Tools.NewsSite;

import static Torello.Java.C.BRED;
import static Torello.Java.C.RESET;
import static Torello.Java.C.YELLOW;

import Torello.HTML.HTMLNode;
import Torello.HTML.Links;

import Torello.Java.StrCmpr;
import Torello.HTML.NodeSearch.InnerTagFind;

import java.net.URL;
import java.util.Vector;
import java.io.IOException;

class GetImageLocations
{
    static boolean run(final RECORD r) throws IOException
    {
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // Retrieve the positions of the images
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        // The Vector-index location of all the images inside the article-body
        r.imagePosArr = InnerTagFind.all(r.article, "img", "src",
            (String src) -> ! StrCmpr.startsWithXOR_CI(src.trim(), "data:"));


        // A list of all the image-URL's that were extracted from the article-body
        // using the integer-array aquired in the previous line.

        r.imageURLs = Links.resolveSRCs(r.article, r.imagePosArr, r.url);

        if (r.skipArticlesWithoutPhotos && (r.imageURLs.size() == 0))
        {
            r.log.append(
                BRED + "\tArticle content contained 0 HTML IMG elements" + RESET +
                '\n'
            );

            r.ret
                .elementAt(r.outerCounter())
                .add(DownloadResult.NO_IMAGES_FOUND);

            return false;
        }

        r.log.append(
            "\tArticle contains (" + YELLOW + r.imageURLs.size() + RESET + ") " +
            "image TagNodes.\n"
        );

        return true;
    }
}