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

52
LINES

< > BotCompany Repo | #1032326 // Playwright Module [youTubeSearch etc]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 65776K of libraries. Click here for Pure Java version (12144L/62K).

!7

cm PlaywrightModule > DynPrintLogAndEnabled {
  transient autoDispose new Borrowable<PlaywrightAndBrowser> sharedBrowser;
  
  start-thread {
    time "Chromium preloaded" {
      sharedBrowser.set(playwrightWithChromium());
    }
  }

  // borrow or create temporarily
  PlaywrightAndBrowser acquireBrowser(IResourceHolder res) {
    var borrowedBrowser = res.add(sharedBrowser.tempBorrow());
    var browser = borrowedBrowser!;
    if (browser == null)
      browser = res.add(tempPlaywrightWithChromium());
    else
      print("Using borrowed browser");
    ret browser;
  }
  
  // API
  
  WithURL<S> youTubeSearch(S query) { print exceptions {
      printFunctionCall youTubeSearch(query);
      temp res = resourceHolder();
      var browser = acquireBrowser(res);
      ret print(result := main youTubeSearch(browser!, query));
  }}
  
  WithURL<S> webSearch(S query) {
    ret first(webSearch_all(query));
  }
  
  L<WithURL<S>> webSearch_all(S query, MapSO urlParams default null) { print exceptions {
    printFunctionCall webSearch_all(query);
    temp res = resourceHolder();
    var browser = acquireBrowser(res);
    GoogleSearch gs = new(browser!, query);
    addAll(gs.urlParams, urlParams);
    ret print(result := googleSearch_all(gs));
  }}
  
  BufferedImage screenShootWebsite(S url, double delay default 2.0) { print exceptions {
    printFunctionCall screenShootWebsite(url, delay);
    temp res = resourceHolder();
    var browser = acquireBrowser(res);
    temp page = playwrightOpenPage(browser!, url);
    ret playwrightScreenshot(page, delay);
  }}
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, uelavcdoioby

No comments. add comment

Snippet ID: #1032326
Snippet name: Playwright Module [youTubeSearch etc]
Eternal ID of this version: #1032326/18
Text MD5: 5f6389dd280db00f9c557a95882d7c16
Transpilation MD5: 3e1d3549e332b5c83d1cc58aa204350d
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-02 01:43:11
Source code size: 1635 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 249 / 71022
Version history: 17 change(s)
Referenced in: #1032327 - dm_youTubeSearch
#1032350 - PlaywrightAndBrowser
#1032452 - dm_webSearch_all
#1032528 - dm_screenShootWebsite
#1032695 - dm_webSearch