async function retrieveChapterData(HTML, groupMeta, chapter){

    chapter = chapter.trim();
    const { content, title, hasRedirect } = groupMeta;
    const $ = cheerio.load(HTML);
    var paragraphs = [];
    var chaptertitle = ""

    // Check if it has multiple parts and redirection
    if(hasRedirect.parts){

        // Truncate to only get the chapter number
        chapter = /c[0-9]*/.exec(chapter)[0];
        chapter = chapter.replace("c","");

        if(title == "" || title == null){

            chaptertitle = `Chapter ${chapter}`;
        }

        let parts = $(hasRedirect.parts).get();

        parts = parts.map((p) => { return $(p).attr("href");});

        // Remove any undefined or null data
        parts = parts.filter((p) => { return p } );
        parts = parts.filter((p) => { return (p.indexOf(chapter)!=-1); });

        let paragraph = "";
        for(var p = 0; p<p.length; p++){
            
            try{

                HTML = await exports.retrieveHTML(parts[p], 3).catch((err)=>{
                    err.getError(err);
                    pretty.errPrint("Skipping chapter component...");
                    return null;
                });

                if(!HTML){
                    continue;
                }

                let $ = cheerio.load(HTML);

                if(p==0){

                    chaptertitle = $(title).text();
                }

                $(content).each((i,elem)=>{

                    paragraph = $(elem).text();

                    if(paragraph != null || paragrap != ""){
                        paragraphs = [...paragraphs, paragraph];
                    }

                });

            }
            catch(err){

                errDict.getError(20);
                paragraphs =  [...paragraphs, "An error occured in the retrieval of the chapter contents", err];
        
                return paragraphs;
            }

        }

        return { title: chaptertitle, content: paragraphs };

    }
    else{

        try{

            
            if(title == "" || title == null){

                // Truncate to only get the chapter number
                chapter = /c[0-9]*/.exec(chapter)[0];
                chapter = chapter.replace("c","");

                chaptertitle = `Chapter ${chapter}`;
            }
            else{

                chaptertitle = $(title).text();
            }

            $(content).each((i,elem)=>{
    
                let paragraph = $(elem).text();
    
                // Skip the paragraph if it is blank
                if(paragraph != null || paragraph != ""){
                    paragraphs = [...paragraphs, paragraph];
                }
    
            })
        }
        catch(err){
    
            errDict.getError(20);
            paragraphs =  [...paragraphs, "An error occured in the retrieval of the chapter contents", err];
    
            return paragraphs;
        }

        return { title: chaptertitle, content: paragraphs };
    }

}
/**
 * Retrieves the chapter content from the group translator's site.
 * 
 * @param {String} HTML This is the HTML body of the chapter in the group's website
 * @param {Object} groupMeta The meta data to be used for CSS scraping the chapter
 * @param {String} chapter This is the chapter string of the current iteration 
 * 
 * @returns An array of text elements that will represent each paragraph in the chapter
 */
Retrieves the chapter content from the group translator's site.

@param {String} HTML This is the HTML body of the chapter in the group's website
@param {Object} groupMeta The meta data to be used for CSS scraping the chapter
@param {String} chapter This is the chapter string of the current iteration

@returns An array of text elements that will represent each paragraph in the chapter
Retrieves the chapter content from the group translator ' s site . @param { String } HTML This is the HTML body of the chapter in the group ' s website @param { Object } groupMeta The meta data to be used for CSS scraping the chapter @param { String } chapter This is the chapter string of the current iteration @returns An array of text elements that will represent each paragraph in the chapter
async function retrieveChapterData(HTML, groupMeta, chapter){
    chapter = chapter.trim();
    const { content, title, hasRedirect } = groupMeta;
    const $ = cheerio.load(HTML);
    var paragraphs = [];
    var chaptertitle = ""
    if(hasRedirect.parts){
        chapter = /c[0-9]*/.exec(chapter)[0];
        chapter = chapter.replace("c","");
        if(title == "" || title == null){
            chaptertitle = `Chapter ${chapter}`;
        }
        let parts = $(hasRedirect.parts).get();
        parts = parts.map((p) => { return $(p).attr("href");});
        parts = parts.filter((p) => { return p } );
        parts = parts.filter((p) => { return (p.indexOf(chapter)!=-1); });
        let paragraph = "";
        for(var p = 0; p<p.length; p++){
            try{
                HTML = await exports.retrieveHTML(parts[p], 3).catch((err)=>{
                    err.getError(err);
                    pretty.errPrint("Skipping chapter component...");
                    return null;
                });
                if(!HTML){
                    continue;
                }
                let $ = cheerio.load(HTML);
                if(p==0){
                    chaptertitle = $(title).text();
                }
                $(content).each((i,elem)=>{
                    paragraph = $(elem).text();
                    if(paragraph != null || paragrap != ""){
                        paragraphs = [...paragraphs, paragraph];
                    }
                });
            }
            catch(err){
                errDict.getError(20);
                paragraphs =  [...paragraphs, "An error occured in the retrieval of the chapter contents", err];
                return paragraphs;
            }
        }
        return { title: chaptertitle, content: paragraphs };
    }
    else{
        try{
            if(title == "" || title == null){
                chapter = /c[0-9]*/.exec(chapter)[0];
                chapter = chapter.replace("c","");
                chaptertitle = `Chapter ${chapter}`;
            }
            else{
                chaptertitle = $(title).text();
            }
            $(content).each((i,elem)=>{
                let paragraph = $(elem).text();
                if(paragraph != null || paragraph != ""){
                    paragraphs = [...paragraphs, paragraph];
                }
            })
        }
        catch(err){
            errDict.getError(20);
            paragraphs =  [...paragraphs, "An error occured in the retrieval of the chapter contents", err];
            return paragraphs;
        }
        return { title: chaptertitle, content: paragraphs };
    }
}
async function retrieveChapterData ( HTML , groupMeta , chapter ) { chapter = chapter . trim ( ) ; const { content , title , hasRedirect } = groupMeta ; const $ = cheerio . load ( HTML ) ; var paragraphs = [ ] ; var chaptertitle = "" if ( hasRedirect . parts ) { chapter = / c[0-9]* / . exec ( chapter ) [ 0 ] ; chapter = chapter . replace ( "c" , "" ) ; if ( title == "" || title == null ) { chaptertitle = ` ${ chapter } ` ; } let parts = $ ( hasRedirect . parts ) . get ( ) ; parts = parts . map ( ( p ) => { return $ ( p ) . attr ( "href" ) ; } ) ; parts = parts . filter ( ( p ) => { return p } ) ; parts = parts . filter ( ( p ) => { return ( p . indexOf ( chapter ) != - 1 ) ; } ) ; let paragraph = "" ; for ( var p = 0 ; p < p . length ; p ++ ) { try { HTML = await exports . retrieveHTML ( parts [ p ] , 3 ) . catch ( ( err ) => { err . getError ( err ) ; pretty . errPrint ( "Skipping chapter component..." ) ; return null ; } ) ; if ( ! HTML ) { continue ; } let $ = cheerio . load ( HTML ) ; if ( p == 0 ) { chaptertitle = $ ( title ) . text ( ) ; } $ ( content ) . each ( ( i , elem ) => { paragraph = $ ( elem ) . text ( ) ; if ( paragraph != null || paragrap != "" ) { paragraphs = [ ... paragraphs , paragraph ] ; } } ) ; } catch ( err ) { errDict . getError ( 20 ) ; paragraphs = [ ... paragraphs , "An error occured in the retrieval of the chapter contents" , err ] ; return paragraphs ; } } return { title : chaptertitle , content : paragraphs } ; } else { try { if ( title == "" || title == null ) { chapter = / c[0-9]* / . exec ( chapter ) [ 0 ] ; chapter = chapter . replace ( "c" , "" ) ; chaptertitle = ` ${ chapter } ` ; } else { chaptertitle = $ ( title ) . text ( ) ; } $ ( content ) . each ( ( i , elem ) => { let paragraph = $ ( elem ) . text ( ) ; if ( paragraph != null || paragraph != "" ) { paragraphs = [ ... paragraphs , paragraph ] ; } } ) } catch ( err ) { errDict . getError ( 20 ) ; paragraphs = [ ... paragraphs , "An error occured in the retrieval of the chapter contents" , err ] ; return paragraphs ; } return { title : chaptertitle , content : paragraphs } ; } }
Retrieves the chapter content from the group translator's site.
Retrieves the chapter content from the group translator ' s site .
// Check if it has multiple parts and redirection // Truncate to only get the chapter number // Remove any undefined or null data // Truncate to only get the chapter number // Skip the paragraph if it is blank