Comparing version 2.10.4 to 2.11.0
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.ytSearch = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } | ||
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } | ||
var _cheerio = require('cheerio'); | ||
@@ -60,3 +60,3 @@ var _dasu = require('dasu'); | ||
} | ||
_envs[key] = n; | ||
_envs[key.toLowerCase()] = n; | ||
}); | ||
@@ -66,2 +66,3 @@ var _debugging = _envs.debug; | ||
if (!_debugging) return; | ||
console.log('DEBUGGING'); | ||
console.log.apply(this, arguments); | ||
@@ -509,4 +510,10 @@ } | ||
var _title2 = _jp.value(item, '$..title..text') || _jp.value(item, '$..title..simpleText') || _jp.value(item, '$..displayName..text'); | ||
var _channelId = _jp.value(item, '$..channelRenderer..channelId') || ''; | ||
var _author_name2 = _jp.value(item, '$..shortBylineText..text') || _jp.value(item, '$..longBylineText..text') || _jp.value(item, '$..displayName..text') || _jp.value(item, '$..displayName..simpleText'); | ||
var about_channel = _jp.query(item, '$..channelRenderer..descriptionSnippet..text').join('') || ''; | ||
var video_count_label = _jp.value(item, '$..videoCountText..simpleText') || _jp.value(item, '$..videoCountText..label') || _jp.value(item, '$..videoCountText..text') || '0'; | ||
var channel_verified_label = _jp.value(item, '$..channelRenderer..ownerBadges..style') || _jp.value(item, '$..channelRenderer..ownerBadges..tooltip') || _jp.value(item, '$..channelRenderer..ownerBadges..label') || ''; | ||
var channel_verified = | ||
// has "verified" or "_verified" text in it | ||
channel_verified_label.toLowerCase().trim().search(/[\s_]?verified/) >= 0; | ||
var sub_count_label = _jp.value(item, '$..subscriberCountText..simpleText') || _jp.value(item, '$..subscriberCountText..text') || '0'; | ||
@@ -530,10 +537,12 @@ | ||
// url ( playlist ) | ||
// const url = _jp.value( item, '$..navigationEndpoint..url' ) | ||
var _url3 = _jp.value(item, '$..navigationEndpoint..url') || '/user/' + _title2; | ||
// base url | ||
var base_url = _jp.value(item, '$..navigationEndpoint..url') || _jp.value(item, '$..browseEndpoint..canonicalBaseUrl') || _jp.value(item, '$..browseEndpoint..url') || '/user/' + _title2; | ||
result = { | ||
type: 'channel', | ||
name: _author_name2, | ||
url: TEMPLATES.YT + _url3, | ||
url: TEMPLATES.YT + base_url, | ||
baseUrl: base_url, | ||
id: _channelId, | ||
title: _title2.trim(), | ||
about: about_channel, | ||
image: _thumbnail2, | ||
@@ -543,2 +552,3 @@ thumbnail: _thumbnail2, | ||
videoCountLabel: video_count_label, | ||
verified: channel_verified, | ||
subCount: _parseSubCountLabel(sub_count_label), | ||
@@ -564,7 +574,7 @@ subCountLabel: sub_count_label | ||
// const url = _jp.value( item, '$..navigationEndpoint..url' ) | ||
var _url4 = TEMPLATES.YT + '/watch?v=' + videoId; | ||
var _url3 = TEMPLATES.YT + '/watch?v=' + videoId; | ||
result = { | ||
type: 'live', | ||
videoId: videoId, | ||
url: _url4, | ||
url: _url3, | ||
title: _title3.trim(), | ||
@@ -592,3 +602,2 @@ description: _description, | ||
} | ||
if (result) { | ||
@@ -1132,3 +1141,7 @@ results.push(result); | ||
console.log('channels: ' + channels.length); | ||
console.log('topChannel name: ' + topChannel.name); | ||
console.log('topChannel.name: ' + topChannel.name); | ||
console.log('topChannel.baseUrl: ' + topChannel.baseUrl); | ||
console.log('topChannel.id: ' + topChannel.id); | ||
console.log('topChannel.about: ' + topChannel.about); | ||
console.log('topChannel.verified: ' + topChannel.verified); | ||
console.log('topChannel.videoCount: ' + topChannel.videoCount); | ||
@@ -1135,0 +1148,0 @@ console.log('topChannel.subCount: ' + topChannel.subCount); |
{ | ||
"name": "yt-search", | ||
"version": "2.10.4", | ||
"version": "2.11.0", | ||
"description": "search youtube", | ||
@@ -5,0 +5,0 @@ "main": "dist/yt-search.js", |
@@ -142,1 +142,18 @@ [![npm](https://img.shields.io/npm/v/yt-search.svg?maxAge=3600)](https://www.npmjs.com/package/yt-search) | ||
``` | ||
## Development / Debugging | ||
Modify `debug.js` by adding another mXX function and calling it at the top. | ||
Run with the debug flag ex: `DEBUG=1 node debug.js` | ||
The HTML response received by yt-search is written to `dasu.response`. | ||
Prettify `dasu.response` for easier debugging ex: `prettier --parser html` | ||
-- save it as a temporary file so it's not overwritten when you call the | ||
debug fn again if necessary ex: `pewdiepie.channel` or `superman.results` | ||
Most/all relevant data for parsing is found in the results inside the | ||
`ytInitialData` object. | ||
We're using `jsonpath-plus` for resilient parsing of the `ytInitialData` | ||
object that is subject to continuous modifications by YouTube. |
52062
1187
159