async-g-i-s
Advanced tools
Comparing version 1.4.0 to 1.5.0
@@ -5,2 +5,3 @@ interface Result { | ||
width: number; | ||
color: [number, number, number]; | ||
} | ||
@@ -10,5 +11,4 @@ | ||
query?: object = {}; | ||
filterOutDomains?: string[] = ['gstatic.com']; | ||
userAgent?: string = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36'; | ||
disableDoubleHTTP?: boolean = true; | ||
userAgent?: string = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'; | ||
newRegex?: boolean = true; | ||
} | ||
@@ -23,7 +23,6 @@ | ||
* @param {Object} options.query You can use custom query | ||
* @param {[String]} options.filterOutDomains Not looking for these domains | ||
* @param {String} options.userAgent User agent for request | ||
* @param {Boolean} options.disableDoubleHTTP Disable double http in url, slow, and safe | ||
* @param {Boolean} options.newRegex Better filtering, if you want to find everything, set as false | ||
* @returns {Promise<Result[]>} Array of results | ||
*/ | ||
export default async function gis(searchTerm: string, options?: Options): Promise<Result[]> | ||
export default async function gis(searchTerm: string, options?: Options): Promise<Result[]>; |
58
index.js
@@ -1,7 +0,5 @@ | ||
const { parse } = require('node-html-parser'); | ||
const fetch = global.fetch || require('node-fetch'); | ||
const LEGACY_REGEX = /\["(http.+?)",(\d+),(\d+)\]/g; | ||
const REGEX = /"(\bhttps?:\/\/[^"]+)",(\d+),(\d+)],null,\d+,"rgb\((\d+),(\d+),(\d+)\)"/g; | ||
const IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.svg']; | ||
const REGEX = /\["(http.+?)",(\d+),(\d+)\]/g; | ||
/** | ||
@@ -11,50 +9,34 @@ * | ||
* @async | ||
* @param {String} searchTerm Search term for search | ||
* @param {String} searchTerm Search term to search | ||
* @param {Object} options Options for search | ||
* @param {Object} options.query You can use custom query | ||
* @param {[String]} options.filterOutDomains Not looking for these domains | ||
* @param {String} options.userAgent User agent for request | ||
* @param {Boolean} options.disableDoubleHTTP Disable double http in url, slow, and safe | ||
* @param {Boolean} options.newRegex Better filtering, if you want to find everything, set as false | ||
* @returns {Promise<[{url: string, height: number, width: number }]>} Array of results | ||
*/ | ||
module.exports = async function gis(searchTerm, options = {}) { | ||
if (!searchTerm || typeof searchTerm !== 'string') | ||
throw new TypeError("searchTerm must be a string."); | ||
if (!searchTerm || typeof searchTerm !== 'string') throw new TypeError("searchTerm must be a string."); | ||
if (typeof options !== 'object') throw new TypeError("options argument must be an object."); | ||
if (typeof options !== 'object') | ||
throw new TypeError("options argument must be an object."); | ||
const { | ||
query = {}, | ||
filterOutDomains = ['gstatic.com'], | ||
userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36', | ||
disableDoubleHTTP = true | ||
} = options; | ||
userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36', | ||
newRegex = true | ||
} = options, | ||
body = await fetch(`http://www.google.com/search?${new URLSearchParams({ ...query, tbm: "isch", q: searchTerm })}`, { headers: { 'User-Agent': userAgent } }).then(res => res.text()), | ||
content = body.slice(body.lastIndexOf("ds:1"), body.lastIndexOf('sideChannel')), | ||
regex = newRegex ? REGEX : LEGACY_REGEX, | ||
results = []; | ||
const body = await fetch(`http://www.google.com/search?${new URLSearchParams({ ...query, tbm: "isch", q: searchTerm })}`, { | ||
headers: { | ||
'User-Agent': userAgent | ||
} | ||
}).then(res => res.text()); | ||
const content = parse(body).getElementsByTagName('script').filter( | ||
script => script.childNodes?.length && IMAGE_EXTENSIONS.some(a => script.childNodes[0].text.toLowerCase().includes(a)) | ||
) | ||
const results = []; | ||
let result; | ||
while ((result = REGEX.exec(content)) !== null) | ||
if (result.length > 3 && filterOutDomains.every(skipDomain => !result[1].includes(skipDomain))) | ||
results.push({ | ||
url: disableDoubleHTTP ? `http${result[1].split("http")[1]}` : result[1], | ||
height: +result[2], | ||
width: +result[3] | ||
}); | ||
while (result = regex.exec(content)) | ||
results.push({ | ||
url: result[1], | ||
height: +result[2], | ||
width: +result[3], | ||
color: result.slice(4, 7).map(Number) | ||
}); | ||
return results; | ||
} |
{ | ||
"name": "async-g-i-s", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Async Google Image Search", | ||
@@ -26,7 +26,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"node-fetch": "^2.6.7" | ||
}, | ||
"dependencies": { | ||
"node-html-parser": "^6.1.5" | ||
"node-fetch": "^2.6.12" | ||
} | ||
} |
@@ -36,50 +36,48 @@ # async-g-i-s | ||
{ | ||
url: 'https://m.media-amazon.com/images/M/MV5BMWQwM2M4NDMtOTI3Ni00NTMyLWI4YzktYTNkMjcyYmYzNzY4XkEyXkFqcGdeQXVyMTMyMTYxODIy._V1_.jpg', | ||
url: 'https://m.media-amazon.com/images/M/MV5BMWQwM2M4NDMtOTI3Ni00NTMyLWI4YzktYTNkMjcyYmYzNzY4XkEyXkFqcGdeQXVyMTMyMTYxODIy._V1_.jpg', | ||
height: 1477, | ||
width: 1034 | ||
width: 1034, | ||
color: [ 48, 48, 48 ] | ||
}, | ||
{ | ||
url: 'https://upload.wikimedia.org/wikipedia/tr/c/ca/AkifDizi.jpg', | ||
height: 350, | ||
width: 350, | ||
color: [ 16, 16, 16 ] | ||
}, | ||
{ | ||
url: 'https://upload.wikimedia.org/wikipedia/commons/7/7b/Mehmet_%C3%82kif_Ersoy.png', | ||
height: 1908, | ||
width: 1656 | ||
width: 1656, | ||
color: [ 192, 192, 192 ] | ||
}, | ||
{ | ||
url: 'https://m.media-amazon.com/images/M/MV5BNzNlNGQ0NDUtODE4Yy00OTNjLTkyYWYtZTJmNTQ4MDU4ODA4XkEyXkFqcGdeQXVyNTA0MDE0NjQ@._V1_.jpg', | ||
height: 2048, | ||
width: 1434 | ||
url: 'https://erdemyayinlari.com.tr/wp-content/uploads/2021/12/akif.png', | ||
height: 450, | ||
width: 300, | ||
color: [ 248, 248, 242 ] | ||
}, | ||
{ | ||
url: 'https://cdnuploads.aa.com.tr/uploads/Contents/2020/12/20/thumbs_b_c_ef4c27d49cbd1cfe2311ff4bc582514e.jpg', | ||
url: 'https://cdnuploads.aa.com.tr/uploads/Contents/2021/12/26/thumbs_b_c_8d154765bbfa0e823854bff84badecad.jpg?v\\u003d132249', | ||
height: 486, | ||
width: 864 | ||
width: 864, | ||
color: [ 152, 46, 56 ] | ||
}, | ||
{ | ||
url: 'https://img.kitapyurdu.com/v1/getImage/fn:11498652/wh:true/wi:800', | ||
height: 1345, | ||
width: 800 | ||
url: 'https://img.kitapyurdu.com/v1/getImage/fn:11653825/wh:true/wi:500', | ||
height: 779, | ||
width: 500, | ||
color: [ 2, 8, 8 ] | ||
}, | ||
{ | ||
url: 'https://i4.hurimg.com/i/hurriyet/75/1200x675/5aa587a218c77324cc5456b5.jpg', | ||
height: 675, | ||
width: 1200 | ||
url: 'https://img.a.transfermarkt.technology/portrait/big/526642-1629104912.jpg?lm\\u003d1', | ||
height: 390, | ||
width: 300, | ||
color: [ 24, 18, 11 ] | ||
}, | ||
{ | ||
url: 'https://cdnuploads.aa.com.tr/uploads/Contents/2021/10/17/thumbs_b_c_26c09ac1a20d0b12916c49936728eb22.jpg?v\\u003d124950', | ||
height: 486, | ||
width: 864 | ||
}, | ||
{ | ||
url: 'https://i.dha.com.tr/i/dha/75/0x0/6245a965470a9b4a8c336615.jpg', | ||
height: 450, | ||
width: 800 | ||
}, | ||
{ | ||
url: 'https://media-cdn.t24.com.tr/media/library/2021/09/1632461524964-thumbs-b-c-65-cf-0-ecf-0-d-4-c-3-d-9-e-9-d-2-e-56-a-3352-ac-244.jpg', | ||
height: 486, | ||
width: 864 | ||
}, | ||
{ | ||
url: 'https://img.piri.net/resim/imagecrop/2021/12/27/10/41/resized_0c8d4-430d41adakif.jpg', | ||
height: 1959, | ||
width: 1832 | ||
url: 'https://i.ytimg.com/vi/Ycm31r2SaPo/maxresdefault.jpg', | ||
height: 720, | ||
width: 1280, | ||
color: [ 50, 252, 172 ] | ||
} | ||
@@ -93,5 +91,5 @@ ] | ||
query: { safe: "on" }, | ||
filterOutDomains: [ 'm.media-amazon.com' ] | ||
userAgent: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)' | ||
}); | ||
``` | ||
Example, this will not fetch NSFW results. Also, it will filter out results from amazon. | ||
Example, this will not fetch NSFW results. And change user agent to Googlebot. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
6719
67
93
- Removednode-html-parser@^6.1.5
- Removedboolbase@1.0.0(transitive)
- Removedcss-select@5.1.0(transitive)
- Removedcss-what@6.1.0(transitive)
- Removeddom-serializer@2.0.0(transitive)
- Removeddomelementtype@2.3.0(transitive)
- Removeddomhandler@5.0.3(transitive)
- Removeddomutils@3.1.0(transitive)
- Removedentities@4.5.0(transitive)
- Removedhe@1.2.0(transitive)
- Removednode-html-parser@6.1.13(transitive)
- Removednth-check@2.1.1(transitive)