triangle-utils 1.2.8 → 1.2.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "triangle-utils",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "main": "Utils.js",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -56,10 +56,10 @@ export default class Utils_Bee {
56
56
  return undefined
57
57
  }
58
58
 
59
- async youtube_search(query) {
59
+ async youtube_search(query, options = {}) {
60
60
  for (let i = 0; i < 3; i++) {
61
61
  try {
62
- const bee_url = "https://app.scrapingbee.com/api/v1/youtube/search?api_key=" + this.config.scraping_bee_api_key + "&search=" + encodeURI(query)
62
+ const bee_url = "https://app.scrapingbee.com/api/v1/youtube/search?api_key=" + this.config.scraping_bee_api_key + "&search=" + encodeURI(query) + Object.entries(options).filter(([key, value]) => value !== undefined).map(([key, value]) => "&" + key + "=" + value).join("")
63
63
  console.log(bee_url)
64
64
  const response = await fetch(bee_url)
65
65
  if (!response.ok) {
@@ -69,11 +69,14 @@ export default class Utils_Bee {
69
69
  const data = await response.json()
70
70
  const results = data.results
71
71
 
72
- if (results === undefined || !Array.isArray(results)) {
72
+ if (results === undefined) {
73
73
  console.log("Failed to YouTube Search.")
74
74
  continue
75
75
  }
76
- return results
76
+ if (Array.isArray(results)) {
77
+ return results
78
+ }
79
+ return JSON.parse(results)
77
80
  } catch {
78
81
  console.log("Failed to YouTube Search.")
79
82
  }