client.js
// It also takes into account whether the video is private or public
It also takes into account whether the video is private or public
It also takes into account whether the video is private or public
async function searchVideoByTitle({title, videoId, description, ip, cellName, isPublic, startRequest, searchOnlyId}={}) { 
    return new Promise((resolve, reject) => {
        https.get(ip + "results?search_query=" + title,
            { headers: { host: "www.youtube.com" } },
            (res) => {
                res.setEncoding("utf8")
                var data = ""
                res.on("data", function (chunk) {
                    data += chunk
                })
                res.on("end", function () {
                    let idFound = false
                    if (data.includes(videoId)) { 
                        idFound = true
                    }
                    if(searchOnlyId === true){
                        resolve([idFound, parseInt(performance.now() - startRequest)])
                    }
                    let ok = false
                    if(!isPublic && !idFound) ok = true
                    if(isPublic && idFound && data.includes(description)) ok = true
                    resolve([ok, parseInt(performance.now() - startRequest)])
                })
            }
        )
        .on("error", (error) => {
            reject(error.message)
        })
    })
        .then((data) => {
            if (data[0] === false) {
                let timeout
                if(searchOnlyId === true){
                    timeout = config.SEARCH_ID_TIMEOUT_IN_MILLISECONDS
                } else {
                    timeout = config.SEARCH_ID_AND_FEATURES_TIMEOUT_IN_MILLISECONDS
                }
                if (data[1] >= timeout) {
                    return data
                }
                return searchVideoByTitle({
                    title, 
                    videoId, 
                    description, 
                    ip, 
                    cellName, 
                    isPublic, 
                    startRequest,
                    searchOnlyId
                })
            } else {
                if (socketLocalhost !== null) {
                    console.log("send data to graphs\nCell name:", cellName, 
                        "\nDid it found the result:", data[0] === true, "\nTime from start to end of the request", data[1])
                    socketLocalhost.emit("update-graphs", cellName, data[0] === true, data[1])
                }
                return data
            }
        })
        .catch((err) => {
            console.error(err)
        })
}
async function searchVideoByTitle ( { title , videoId , description , ip , cellName , isPublic , startRequest , searchOnlyId } = { } ) { return new Promise ( ( resolve , reject ) => { https . get ( ip + "results?search_query=" + title , { headers : { host : "www.youtube.com" } } , ( res ) => { res . setEncoding ( "utf8" ) var data = "" res . on ( "data" , function ( chunk ) { data += chunk } ) res . on ( "end" , function ( ) { let idFound = false if ( data . includes ( videoId ) ) { idFound = true } if ( searchOnlyId === true ) { resolve ( [ idFound , parseInt ( performance . now ( ) - startRequest ) ] ) } let ok = false if ( ! isPublic && ! idFound ) ok = true if ( isPublic && idFound && data . includes ( description ) ) ok = true resolve ( [ ok , parseInt ( performance . now ( ) - startRequest ) ] ) } ) } ) . on ( "error" , ( error ) => { reject ( error . message ) } ) } ) . then ( ( data ) => { if ( data [ 0 ] === false ) { let timeout if ( searchOnlyId === true ) { timeout = config . SEARCH_ID_TIMEOUT_IN_MILLISECONDS } else { timeout = config . SEARCH_ID_AND_FEATURES_TIMEOUT_IN_MILLISECONDS } if ( data [ 1 ] >= timeout ) { return data } return searchVideoByTitle ( { title , videoId , description , ip , cellName , isPublic , startRequest , searchOnlyId } ) } else { if ( socketLocalhost !== null ) { console . log ( "send data to graphs\nCell name:" , cellName , "\nDid it found the result:" , data [ 0 ] === true , "\nTime from start to end of the request" , data [ 1 ] ) socketLocalhost . emit ( "update-graphs" , cellName , data [ 0 ] === true , data [ 1 ] ) } return data } } ) . catch ( ( err ) => { console . error ( err ) } ) }
It also takes into account whether the video is private or public
It also takes into account whether the video is private or public
// check if the id is inside the result found // exceeded the double of the average to find the id of the video // query name, cellName, result search, 