google-img-scrap 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ### 1.0.7
4
+ - Readme update
5
+
3
6
  ### 1.0.6
4
7
  - Fixed types
5
8
  - Added ```limit``` to limit the size of the results
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Google-img-scrap v1.0.6
1
+ # Google-img-scrap v1.0.7
2
2
 
3
- Scrap images from google image with lot of tools and options.
3
+ Scrap images from google images with customs pre filled options
4
4
 
5
5
  ## Update
6
6
 
@@ -18,68 +18,93 @@ npm i google-img-scrap
18
18
 
19
19
  ## Import
20
20
 
21
- - NPM
22
-
23
21
  ```js
24
22
  const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
25
23
  ```
26
24
 
27
- - From GITHUB
28
-
29
- ```js
30
- const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('./src/google-img-scrap');
31
- ```
32
-
33
- ## Params
25
+ ## Query Params
34
26
 
35
27
  - "search" (String) what you want to search
36
28
  - "execute" (Function) allow you to execute a function to remove "gstatic.com" domains for example
37
- - "excludeWords" (Array of String) exclude some words from the search
38
- - "domains" (Array of String) filter by domains
39
- - "excludeDomains" (Array of String) exclude some domains
29
+ - "excludeWords" (String[]) exclude some words from the search
30
+ - "domains" (String[]) filter by domains
31
+ - "excludeDomains" (String[]) exclude some domains
40
32
  - "safeSearch" (Boolean) active safe search or not for nsfw for example
41
33
  - "custom" (String) add extra query
42
- - "urlMatch" (Array of Array) get image when an url match a string (example: "cdn") | ```example below```
43
- - "filterByTitles" (Array of Array) filter images by titles | ```example below```
34
+ - "urlMatch" (String[][]) get image when an url match a string (example: "cdn") | ```example below```
35
+ - "filterByTitles" (String[][]) filter images by titles | ```example below```
44
36
  - "query" (Object) set a query (can be [TYPE, DATE, COLOR, SIZE, LICENCE, EXTENSION]) (use GOOGLE_QUERY items | ```example below```
45
37
  - "limit" (Int) to limit the size of the results
46
38
 
47
39
  ## Result
48
40
 
49
41
  ```js
50
- }
51
42
  {
52
- url: 'https://images.google.com/search?tbm=isch&tbs=itp:clipart,qdr:y,ic:gray,isz:l,il:ol,ift:jpg&q=cats',
43
+ url: 'https://images.google.com/search?tbm=isch&tbs=itp:clipart,qdr:y,ic:gray,isz:l,il:ol,ift:jpg&q=cats%20%20%20-%22black%22%20-%22white%22&name=content&name2=content2',
53
44
  result: [
54
45
  {
55
- url: 'https://media.istockphoto.com/vectors/black-cats-set-vector-id599123506',
56
- height: '806',
46
+ url: 'https://media.gettyimages.com/vectors/cat-eating-fish-vector-id1216628506',
47
+ height: '1024',
57
48
  width: '1024'
58
49
  },
59
50
  {
60
- url: 'https://media.istockphoto.com/vectors/cats-vector-id455327075',
61
- height: '860',
51
+ url: 'https://www.ariatrade.gr/images/products/2021/10/110294_1.jpg',
52
+ height: '768',
62
53
  width: '1024'
63
54
  },
64
55
  {
65
- url: 'https://media.istockphoto.com/vectors/purring-cats-vector-silhouette-vector-id165749810?s=2048x2048',
66
- height: '1895',
56
+ url: 'https://media.gettyimages.com/illustrations/panther-leaping-illustration-id152406879?s=2048x2048',
57
+ height: '2048',
67
58
  width: '2048'
68
59
  },
69
- ...
60
+ {
61
+ url: 'https://media.gettyimages.com/illustrations/botany-plants-antique-engraving-illustration-erythrina-variegata-illustration-id970781520',
62
+ height: '1024',
63
+ width: '828'
64
+ }
70
65
  ]
66
+ ...
71
67
  }
72
68
  ```
73
69
 
74
70
  ## How to use ?
75
71
 
76
- - For the query parameter you need to set the name in upper case !
72
+ - **For the query parameter you need to set the name in upper case !**
73
+
74
+ ## Simple example
75
+
76
+ Search cats images
77
77
 
78
78
  ```js
79
- const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
79
+ (async function(){
80
+ const test = await GOOGLE_IMG_SCRAP({
81
+ search: "cats",
82
+ });
83
+
84
+ console.log(test);
85
+ })();
86
+ ```
87
+
88
+ ## Removing gstatic.com
89
+
90
+ ```js
91
+ (async function(){
92
+ const test = await GOOGLE_IMG_SCRAP({
93
+ search: "demon slayer background hd",
94
+ execute: function(element){
95
+ if(!element.url.match('gstatic.com')) return element;
96
+ }
97
+ });
98
+
99
+ console.log(test);
100
+ })();
101
+ ```
102
+
103
+ ## Custom query
80
104
 
81
- console.log(GOOGLE_QUERY);
105
+ All query options are optional (see below for all the options)
82
106
 
107
+ ```js
83
108
  (async function(){
84
109
  const test = await GOOGLE_IMG_SCRAP({
85
110
  search: "cats",
@@ -91,51 +116,91 @@ console.log(GOOGLE_QUERY);
91
116
  LICENCE: GOOGLE_QUERY.LICENCE.COMMERCIAL_AND_OTHER,
92
117
  EXTENSION: GOOGLE_QUERY.EXTENSION.JPG
93
118
  },
119
+ });
120
+
121
+ console.log(test);
122
+ })();
123
+ ```
124
+
125
+ ## Limit result size
126
+
127
+ ```js
128
+ (async function(){
129
+ const test = await GOOGLE_IMG_SCRAP({
130
+ search: "cats",
94
131
  limit: 5,
132
+ });
133
+
134
+ console.log(test);
135
+ })();
136
+ ```
137
+
138
+ ## Domains
139
+
140
+ Only scrap from a specific domain
141
+
142
+ ```js
143
+ (async function(){
144
+ const test = await GOOGLE_IMG_SCRAP({
145
+ search: "cats",
95
146
  domains: ["alamy.com", "istockphoto.com", "vecteezy.com"],
96
- excludeWords: ["black", "white"], //If you don't like black and white cats
97
- custom: "name=content&name2=content2",
98
- safeSearch: false,
99
- // excludeDomains: ["istockphoto.com", "alamy.com"]
100
147
  });
101
148
 
102
- console.log(test, test.result.length);
149
+ console.log(test);
103
150
  })();
104
151
  ```
105
152
 
106
- OR ALSO
153
+ ## Exclude domains
107
154
 
108
155
  ```js
109
- const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
156
+ (async function(){
157
+ const test = await GOOGLE_IMG_SCRAP({
158
+ search: "cats",
159
+ excludeDomains: ["istockphoto.com", "alamy.com"]
160
+ });
161
+
162
+ console.log(test);
163
+ })();
164
+ ```
165
+
166
+ ## Exclude words
110
167
 
168
+ If you don' like black cats and white cats
169
+
170
+ ```js
111
171
  (async function(){
112
172
  const test = await GOOGLE_IMG_SCRAP({
113
173
  search: "cats",
174
+ excludeWords: ["black", "white"], //If you don't like black cats and white cats
114
175
  });
115
176
 
116
177
  console.log(test, test.result.length);
117
178
  })();
118
179
  ```
119
180
 
120
- ## Removing gstatic.com
181
+ ## Safe search (no nsfw)
121
182
 
122
183
  ```js
123
- const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
124
-
125
184
  (async function(){
126
185
  const test = await GOOGLE_IMG_SCRAP({
127
- search: "demon slayer background hd",
128
- query: {
129
- SIZE: GOOGLE_QUERY.SIZE.LARGE,
130
- },
131
- domains: ["alphacoders.com"],
186
+ search: "cats",
132
187
  safeSearch: false,
133
- execute: function(element){
134
- if(!element.url.match('gstatic.com')) return element;
135
- }
136
188
  });
137
189
 
138
- console.log(test, test.result[test.result.length-1].url, test.result.length);
190
+ console.log(test);
191
+ })();
192
+ ```
193
+
194
+ ## Custom query params
195
+
196
+ ```js
197
+ (async function(){
198
+ const test = await GOOGLE_IMG_SCRAP({
199
+ search: "cats",
200
+ custom: "name=content&name2=content2",
201
+ });
202
+
203
+ console.log(test);
139
204
  })();
140
205
  ```
141
206
 
@@ -144,8 +209,6 @@ const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('google-img-scrap');
144
209
  - urlMatch work like filterByTiles
145
210
 
146
211
  ```js
147
- const { GOOGLE_IMG_SCRAP } = require('google-img-scrap');
148
-
149
212
  (async function(){
150
213
  const test = await GOOGLE_IMG_SCRAP({
151
214
  search: "cats",
@@ -154,12 +217,9 @@ const { GOOGLE_IMG_SCRAP } = require('google-img-scrap');
154
217
  ["draw", "white"],
155
218
  ["albino", "white"]
156
219
  ],
157
- execute: function(element){
158
- if(!element.url.match('gstatic.com')) return element;
159
- }
160
220
  });
161
221
 
162
- console.log(test, test.result.length);
222
+ console.log(test);
163
223
  })();
164
224
  ```
165
225
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "google-img-scrap",
3
- "version": "1.0.6",
4
- "description": "Scrap images from google images with a lot of options",
3
+ "version": "1.0.7",
4
+ "description": "Scrap images from google images with customs pre filled options",
5
5
  "main": "./src/google-img-scrap.js",
6
6
  "types": "./types/index.d.ts",
7
7
  "directories": {
@@ -1,11 +1,11 @@
1
1
  function buildQuery(query, translator){
2
- let result = [];
2
+ const result = [];
3
3
 
4
- let params = Object.keys(query);
5
- let toTranslate = Object.keys(translator);
4
+ const params = Object.keys(query);
5
+ const toTranslate = Object.keys(translator);
6
6
 
7
7
  for(const param of params){
8
- let queryName = param;
8
+ const queryName = param;
9
9
  if(toTranslate.includes(param)) queryName = toTranslate[param];
10
10
 
11
11
  result.push(`${queryName}=${query[param]}`);
package/test/test.js CHANGED
@@ -13,7 +13,6 @@ const { GOOGLE_IMG_SCRAP , GOOGLE_QUERY } = require('../src/google-img-scrap');
13
13
  LICENCE: GOOGLE_QUERY.LICENCE.COMMERCIAL_AND_OTHER,
14
14
  EXTENSION: GOOGLE_QUERY.EXTENSION.JPG
15
15
  },
16
- domains: ["alamy.com", "istockphoto.com", "vecteezy.com"],
17
16
  excludeWords: ["black", "white"], //If you don't like black and white cats
18
17
  custom: "name=content&name2=content2",
19
18
  safeSearch: false,