Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

49
LINES

< > BotCompany Repo | #1025357 // quickVisualize_nsfw

JavaX fragment (include) [tags: use-pretranspiled]

Uses 616K of libraries. Click here for Pure Java version (4421L/31K).

1  
sS quickVisualize_nsfw_progID = #1007145;
2  
static Lock quickVisualize_nsfw_lock = lock();
3  
4  
static bool quickVisualize_nsfw_hasCached(S query) {
5  
  ret quickVisualize_nsfw_imageFile(query).length() != 0;
6  
}
7  
8  
static BufferedImage quickVisualize_nsfw_fromCache(S query) {
9  
  File f = quickVisualize_nsfw_imageFile(query);
10  
  if (f.length() != 0) pcall { ret loadPNG(f); }
11  
  null;
12  
}
13  
14  
static S quickVisualize_nsfw_preprocess(S query) {
15  
  ret toUpper(shorten(trim(query), 200));
16  
}
17  
18  
static BufferedImage quickVisualize_nsfw(S query) {
19  
  query = quickVisualize_nsfw_preprocess(query);
20  
  if (empty(query)) null;
21  
  BufferedImage img = quickVisualize_nsfw_fromCache(query);
22  
  if (img != null) ret img;
23  
  File f = quickVisualize_nsfw_imageFile(query);
24  
  /*L<S> urls = googleImageSearch_multi(query);
25  
  saveTextFile(quickVisualize_nsfw_urlsFile(query), joinLines(urls));
26  
  if (empty(urls)) null;
27  
  img = loadBufferedImage(first(urls));*/
28  
  lock quickVisualize_nsfw_lock;
29  
  temp tempSetTL(googleImageSearch_new_nsfw, true);
30  
  img = googleImageSearch_new(query);
31  
  if (img == null) null;
32  
  savePNG(f, img);
33  
  ret img;
34  
}
35  
36  
static S quickVisualize_nsfw_imagePath(S query) {
37  
  query = quickVisualize_nsfw_preprocess(query);
38  
  ret fsI(quickVisualize_nsfw_progID) + "/nsfw/" + urlencode(query) + ".png";
39  
}
40  
41  
static File quickVisualize_nsfw_imageFile(S query) {
42  
  query = quickVisualize_nsfw_preprocess(query);
43  
  ret prepareProgramFile(quickVisualize_nsfw_progID, "nsfw/" + urlencode(query) + ".png");
44  
}
45  
46  
static File quickVisualize_nsfw_urlsFile(S query) {
47  
  query = quickVisualize_nsfw_preprocess(query);
48  
  ret prepareProgramFile(quickVisualize_nsfw_progID, "urls-" + urlencode(query) + ".txt");
49  
}

Author comment

Began life as a copy of #1007145

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025357
Snippet name: quickVisualize_nsfw
Eternal ID of this version: #1025357/3
Text MD5: 21179850e4b53a3236770e824cfb172d
Transpilation MD5: 1934c26acc0d0b5a8929a1688c9c0176
Author: stefan
Category: javax / imaging / networking
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-09-26 00:09:37
Source code size: 1718 bytes / 49 lines
Pitched / IR pitched: No / No
Views / Downloads: 146 / 228
Version history: 2 change(s)
Referenced in: [show references]