src/Main/PixivAPI/Work.java
public void initialize() throws RuntimeException
    {
        Elements ele;
        String temp;
        Document page = getHTML(url);

        // Checks User ID is valid
        ele = page.getElementsByClass("error-title");
        if(ele.size() != 0)
        {
            throw new RuntimeException("Bad Work ID");
        }

        // Checks Session ID is valid
        ele = page.getElementsByClass("newindex-signup");
        if(ele.size() != 0)
        {
            throw new RuntimeException("Bad Session ID");
        }

        authorName = page.getElementsByClass("user-name").first().text();

        authorID =  page.getElementsByClass("user-name").attr("href").split("=")[1];

        caption = page.getElementsByClass("caption").first().text();

        date = page.getElementsMatchingOwnText("[1]?[0-9][/][1-3]?[0-9][/][0-9]{4}").first().text();

        //Find Type
        temp = page.getElementsByClass("thumbnail-container").first().child(0).className();
        switch(temp)
        {
            case "_work":
                type = WorkType.ILLUSTRATION;
                break;
            case "_work multiple":
                type = WorkType.MANGA;
                break;
            case "_work ugoku-illust":
                type = WorkType.UGOIRA;
                break;
            default:
                type = WorkType.UNKNOWN;
                System.err.println("Failed to parse work type.");
                break;
        }

        imageURL = new Vector<>();
        switch (type)
        {
            case ILLUSTRATION:
                imageURL.add(page.getElementsByClass("original-image").attr("data-src"));
                break;
            case MANGA:
                Document mangaPage = getHTML("https://www.pixiv.net/member_illust.php?mode=manga&illust_id=" + ID);
                ele = mangaPage.getElementsByAttribute("data-src");
                for(Element e: ele)
                {
                    imageURL.add(e.attr("data-src"));
                }
                break;
            case UGOIRA:
                 temp = page.html();
                Matcher m = Pattern.compile("IllustFullscreenData.+zip").matcher(temp);
                if(m.find())
                {
                    temp = m.group();
                    m = Pattern.compile("http.+zip").matcher(temp);
                    if(m.find())
                    {
                        temp = m.group();
                        m = Pattern.compile("\\\\").matcher(temp);
                        temp = m.replaceAll("");
                        imageURL.add(temp);
                    }
                    else
                    {
                        System.err.println("Error in reading ugoira url.");
                        imageURL = null;
                    }
                }
                else
                {
                    System.err.println("Error in reading ugoira url.");
                    imageURL = null;
                }
                break;
            default:
                break;
        }

        tags = new Vector<>();
        ele = page.getElementsByClass("text").select("a");
        for (Element e : ele)
        {
            tags.add(e.ownText());
        }

        title = page.getElementsByClass("title").get(1).text();

        views = Integer.parseInt(page.getElementsByClass("view-count").first().text());

        likes = Integer.parseInt(page.getElementsByClass("rated-count").first().text());

        initialized = true;
    }
/**
     * This function initialized fields and checks if the works ID and session are valid.
     * If they are not valid this function throws a runtime error which can be caught.
     *
     * Because this function makes a connection over the internet, it's very slow to finish, therefore
     * it should only be called if there is a request for data that needs that connection, or if an ID needs to be
     * validated.
     * @throws RuntimeException If this object's ID or session are invalid.
     */
This function initialized fields and checks if the works ID and session are valid.
If they are not valid this function throws a runtime error which can be caught.

Because this function makes a connection over the internet, it's very slow to finish, therefore
it should only be called if there is a request for data that needs that connection, or if an ID needs to be
validated.
@throws RuntimeException If this object's ID or session are invalid.
This function initialized fields and checks if the works ID and session are valid . If they are not valid this function throws a runtime error which can be caught . Because this function makes a connection over the internet it ' s very slow to finish therefore it should only be called if there is a request for data that needs that connection or if an ID needs to be validated . @throws RuntimeException If this object ' s ID or session are invalid .
public void initialize() throws RuntimeException
    {
        Elements ele;
        String temp;
        Document page = getHTML(url);
        ele = page.getElementsByClass("error-title");
        if(ele.size() != 0)
        {
            throw new RuntimeException("Bad Work ID");
        }
        ele = page.getElementsByClass("newindex-signup");
        if(ele.size() != 0)
        {
            throw new RuntimeException("Bad Session ID");
        }
        authorName = page.getElementsByClass("user-name").first().text();
        authorID =  page.getElementsByClass("user-name").attr("href").split("=")[1];
        caption = page.getElementsByClass("caption").first().text();
        date = page.getElementsMatchingOwnText("[1]?[0-9][/][1-3]?[0-9][/][0-9]{4}").first().text();
        temp = page.getElementsByClass("thumbnail-container").first().child(0).className();
        switch(temp)
        {
            case "_work":
                type = WorkType.ILLUSTRATION;
                break;
            case "_work multiple":
                type = WorkType.MANGA;
                break;
            case "_work ugoku-illust":
                type = WorkType.UGOIRA;
                break;
            default:
                type = WorkType.UNKNOWN;
                System.err.println("Failed to parse work type.");
                break;
        }
        imageURL = new Vector<>();
        switch (type)
        {
            case ILLUSTRATION:
                imageURL.add(page.getElementsByClass("original-image").attr("data-src"));
                break;
            case MANGA:
                Document mangaPage = getHTML("https://www.pixiv.net/member_illust.php?mode=manga&illust_id=" + ID);
                ele = mangaPage.getElementsByAttribute("data-src");
                for(Element e: ele)
                {
                    imageURL.add(e.attr("data-src"));
                }
                break;
            case UGOIRA:
                 temp = page.html();
                Matcher m = Pattern.compile("IllustFullscreenData.+zip").matcher(temp);
                if(m.find())
                {
                    temp = m.group();
                    m = Pattern.compile("http.+zip").matcher(temp);
                    if(m.find())
                    {
                        temp = m.group();
                        m = Pattern.compile("\\\\").matcher(temp);
                        temp = m.replaceAll("");
                        imageURL.add(temp);
                    }
                    else
                    {
                        System.err.println("Error in reading ugoira url.");
                        imageURL = null;
                    }
                }
                else
                {
                    System.err.println("Error in reading ugoira url.");
                    imageURL = null;
                }
                break;
            default:
                break;
        }
        tags = new Vector<>();
        ele = page.getElementsByClass("text").select("a");
        for (Element e : ele)
        {
            tags.add(e.ownText());
        }
        title = page.getElementsByClass("title").get(1).text();
        views = Integer.parseInt(page.getElementsByClass("view-count").first().text());
        likes = Integer.parseInt(page.getElementsByClass("rated-count").first().text());
        initialized = true;
    }
public void initialize ( ) throws RuntimeException { Elements ele ; String temp ; Document page = getHTML ( url ) ; ele = page . getElementsByClass ( "error-title" ) ; if ( ele . size ( ) != 0 ) { throw new RuntimeException ( "Bad Work ID" ) ; } ele = page . getElementsByClass ( "newindex-signup" ) ; if ( ele . size ( ) != 0 ) { throw new RuntimeException ( "Bad Session ID" ) ; } authorName = page . getElementsByClass ( "user-name" ) . first ( ) . text ( ) ; authorID = page . getElementsByClass ( "user-name" ) . attr ( "href" ) . split ( "=" ) [ 1 ] ; caption = page . getElementsByClass ( "caption" ) . first ( ) . text ( ) ; date = page . getElementsMatchingOwnText ( "[1]?[0-9][/][1-3]?[0-9][/][0-9]{4}" ) . first ( ) . text ( ) ; temp = page . getElementsByClass ( "thumbnail-container" ) . first ( ) . child ( 0 ) . className ( ) ; switch ( temp ) { case "_work" : type = WorkType . ILLUSTRATION ; break ; case "_work multiple" : type = WorkType . MANGA ; break ; case "_work ugoku-illust" : type = WorkType . UGOIRA ; break ; default : type = WorkType . UNKNOWN ; System . err . println ( "Failed to parse work type." ) ; break ; } imageURL = new Vector < > ( ) ; switch ( type ) { case ILLUSTRATION : imageURL . add ( page . getElementsByClass ( "original-image" ) . attr ( "data-src" ) ) ; break ; case MANGA : Document mangaPage = getHTML ( "https://www.pixiv.net/member_illust.php?mode=manga&illust_id=" + ID ) ; ele = mangaPage . getElementsByAttribute ( "data-src" ) ; for ( Element e : ele ) { imageURL . add ( e . attr ( "data-src" ) ) ; } break ; case UGOIRA : temp = page . html ( ) ; Matcher m = Pattern . compile ( "IllustFullscreenData.+zip" ) . matcher ( temp ) ; if ( m . find ( ) ) { temp = m . group ( ) ; m = Pattern . compile ( "http.+zip" ) . matcher ( temp ) ; if ( m . find ( ) ) { temp = m . group ( ) ; m = Pattern . compile ( "\\\\" ) . matcher ( temp ) ; temp = m . replaceAll ( "" ) ; imageURL . add ( temp ) ; } else { System . err . println ( "Error in reading ugoira url." ) ; imageURL = null ; } } else { System . err . println ( "Error in reading ugoira url." ) ; imageURL = null ; } break ; default : break ; } tags = new Vector < > ( ) ; ele = page . getElementsByClass ( "text" ) . select ( "a" ) ; for ( Element e : ele ) { tags . add ( e . ownText ( ) ) ; } title = page . getElementsByClass ( "title" ) . get ( 1 ) . text ( ) ; views = Integer . parseInt ( page . getElementsByClass ( "view-count" ) . first ( ) . text ( ) ) ; likes = Integer . parseInt ( page . getElementsByClass ( "rated-count" ) . first ( ) . text ( ) ) ; initialized = true ; }
This function initialized fields and checks if the works ID and session are valid.
This function initialized fields and checks if the works ID and session are valid .
// Checks User ID is valid // Checks Session ID is valid //Find Type