Comparing version 2.1.7 to 2.1.8
@@ -1,1 +0,1 @@ | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).ytSearch=t()}}(function(){return function i(o,l,s){function u(e,t){if(!l[e]){if(!o[e]){var r="function"==typeof require&&require;if(!t&&r)return r(e,!0);if(c)return c(e,!0);var n=new Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}var a=l[e]={exports:{}};o[e][0].call(a.exports,function(t){return u(o[e][1][t]||t)},a,a.exports,i,o,l,s)}return l[e].exports}for(var c="function"==typeof require&&require,t=0;t<s.length;t++)u(s[t]);return u}({1:[function(u,t,e){"use strict";var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};var c=u("cheerio"),f=u("dasu");u("async.parallellimit");f.follow=!1,f.debug=!1;var m=u("jsonpath"),h="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) (yt-search; https://www.npmjs.com/package/yt-search)",v=u("url"),r={};Object.keys(process.env).forEach(function(t){var e=process.env[t];if("0"==e||"false"==e||!e)return r[t]=!1;r[t]=e});var y=r.debug;function g(){y&&console.log.apply(this,arguments)}var n,T=u("querystring"),b=u("human-time"),x={YT:"https://youtube.com",SEARCH_MOBILE:"https://m.youtube.com/results",SEARCH_DESKTOP:"https://www.youtube.com/results"};function a(t,e){if(!e)return new Promise(function(r,n){a(t,function(t,e){if(t)return n(t);r(e)})});var r=void 0;if((r="string"==typeof t?{query:t}:t).userAgent&&(h=r.userAgent),r.search=r.query||r.search,r.original_search=r.search,r.videoId)return function(t,a){g("fn: getVideoMetaData");var e=void 0;"string"==typeof t&&(e=t);"object"===(void 0===t?"undefined":i(t))&&(e=t.videoId);var r="https://www.youtube.com/watch?hl=en&gl=US&v="+e,n=v.parse(r);n.headers={"user-agent":h,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},n.headers["user-agent"]="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15",f.req(n,function(t,e,r){if(t)a(t);else{if(200!==e.status)return a("http status: "+e.status);if(y){var n=u("fs");u("path");n.writeFileSync("dasu.response",e.responseText,"utf8")}try{!function(t,e){g("_parseVideoInitialData");var r=t.match(/ytInitialData.*=\s*({.*});/);if(!r[1])return e("could not find inital data in the html document");var n=t.match(/ytInitialPlayerResponse.*=\s*({.*});/);if(!n[1])return e("could not find inital player data in the html document");var a=JSON.parse(r[1]),i=JSON.parse(n[1]),o=m.value(a,"$..currentVideoEndpoint..videoId");if(!o)return e("video unavailable");if("ERROR"===m.value(i,"$..status")||"Video unavailable"===m.value(i,"$..reason"))return e("video unavailable");var l=m.value(a,"$..videoPrimaryInfoRenderer..title..text")||m.value(a,"$..videoPrimaryInfoRenderer..title..simpleText")||m.value(a,"$..videoPrimaryRenderer..title..text")||m.value(a,"$..videoPrimaryRenderer..title..simpleText")||m.value(a,"$..title..text")||m.value(a,"$..title..simpleText"),s=m.value(i,"$..description..text")||m.value(i,"$..description..simpleText")||m.value(a,"$..description..text")||m.value(a,"$..description..simpleText"),u=m.value(a,"$..owner..title..text")||m.value(a,"$..owner..title..simpleText"),c=m.value(a,"$..owner..navigationEndpoint..url")||m.value(a,"$..owner..title..url"),p="https://i.ytimg.com/vi/"+o+"/hqdefault.jpg",d=_(D(1e3*Number(m.value(i,"$..videoDetails..lengthSeconds")))),f=m.value(a,"$..sentimentBar..tooltip").split(/[,.]/).join("").split(/\D+/),h=(Number(f[0]),Number(f[1]),m.value(a,"$..dateText")),v={title:l,description:s,url:x.YT+"/watch?v="+o,videoId:o,seconds:Number(d.seconds),timestamp:d.timestamp,duration:d,views:Number(m.value(i,"$..videoDetails..viewCount")),genre:(m.value(i,"$..category")||"").toLowerCase(),uploadDate:m.value(i,"$..uploadDate"),ago:b(new Date(h)),image:p,thumbnail:p,author:{name:u,url:x.YT+c}};e(null,v)}(r,a)}catch(t){a(t)}}})}(r.videoId,e);if(r.listId)return function(t,a){g("fn: getPlaylistMetaData");var e=void 0;"string"==typeof t&&(e=t);"object"===(void 0===t?"undefined":i(t))&&(e=t.listId||t.playlistId);var r="https://www.youtube.com/playlist?hl=en&gl=US&list="+e,n=v.parse(r);n.headers={"user-agent":h,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},f.req(n,function(t,e,r){if(t)a(t);else{if(200!==e.status)return a("http status: "+e.status);if(y){var n=u("fs");u("path");n.writeFileSync("dasu.response",e.responseText,"utf8")}try{!function(t,e){g("fn: parsePlaylistBody"),console.log("parsePlaylistInitialData");var r=t.match(/ytInitialData.*=\s*({.*});/)[1];if(!r)throw new Error("failed to parse ytInitialData json data");var n=JSON.parse(r),a=m.value(n,"$..microformat..urlCanonical").split("=")[1];console.log("listId: "+a);var i=m.value(n,"$..sidebar.playlistSidebarRenderer.items[0]..stats[1].simpleText").match(/\d+/);console.log("viewCount: "+i);var o=m.query(n,"$..contents..tabs[0]..contents[0]..contents[0]..contents")[0],l=[];o.forEach(function(t){var e=t,r={title:m.value(e,"$..title..simpleText"),videoId:m.value(e,"$..videoId"),listId:a,thumbnail:m.value(e,"$..thumbnail..thumbnails[0]..url").split("?")[0],author:{name:m.value(e,"$..shortBylineText..runs[0]..text"),url:"https://youtube.com"+m.value(e,"$..shortBylineText..runs[0]..url")}};l.push(r)}),console.log(l),console.log("videos.length: "+l.length);var s={title:m.value(n,"$..microformat..title"),listId:a,url:"https://youtube.com/playlist?list="+a,views:Number(i),date:d(m.value(n,"$..sidebar.playlistSidebarRenderer.items[0]..stats[2]..simpleText")),image:l[0].thumbnail,thumbnail:l[0].thumbnail,videos:l,author:{name:m.value(n,"$..videoOwner..title..runs[0]..text"),url:"https://youtube.com"+m.value(n,"$..videoOwner..navigationEndpoint..url")}};e&&e(null,s)}(r,a)}catch(t){a(t)}}})}(r.listId,e);if(!r.search)return e(Error("yt-search: no query given"));!function c(p,d){var t=T.escape(p.search).split(/\s+/),e=p.hl||"en",r=p.gl||"US",n=p.category||"",a=Number(p.pageStart)||1,i=Number(p.pageEnd)||Number(p.pages)||1;a<=0&&(a=1)<=i&&(i+=1),Number.isNaN(i)&&d("error: pageEnd must be a number"),p.pageStart=a,p.pageEnd=i,p.currentPage=p.currentPage||a;var o="?";-1===(o+="search_query="+t.join("+")).indexOf("&hl=")&&(o+="&hl="+e),-1===o.indexOf("&gl=")&&(o+="&gl="+r),n&&(o+="&category="+n),p.sp&&(o+="&sp="+p.sp);var l=x.SEARCH_DESKTOP+o,s=v.parse(l);s.headers={"user-agent":h,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},g(s),g("getting results: "+p.currentPage),f.req(s,function(t,e,r){if(t)d(t);else{if(200!==e.status)return d("http status: "+e.status);if(y){var n=u("fs");u("path"),n.writeFileSync("dasu.response",e.responseText,"utf8")}try{$(r,function(t,e){if(t)return d(t);var r=e,n=r.filter(w),a=r.filter(I),i=r.filter(S);p._data=p._data||{},p._data.videos=p._data.videos||[],p._data.playlists=p._data.playlists||[],p._data.channels=p._data.channels||[],n.forEach(function(t){p._data.videos.push(t)}),a.forEach(function(t){p._data.playlists.push(t)}),i.forEach(function(t){p._data.channels.push(t)}),p.currentPage++;var o=p.currentPage<=p.pageEnd;if(o&&e._sp)p.sp=e._sp,setTimeout(function(){c(p,d)},1500);else{var l=p._data.videos.filter(w),s=p._data.playlists.filter(I),u=p._data.channels.filter(S);d(null,{videos:l,playlists:s,lists:s,accounts:u,channels:u})}})}catch(t){d(t)}}})}(r,e)}function w(t,e,r){if("video"!==t.type)return!1;var n=t.videoId;return r.findIndex(function(t){return n===t.videoId})===e}function I(t,e,r){if("list"!==t.type)return!1;var n=t.listId;return r.findIndex(function(t){return n===t.listId})===e}function S(t,e,r){if("channel"!==t.type)return!1;var n=t.url;return r.findIndex(function(t){return n===t.url})===e}function $(t,e){var r=c.load(t),n=r("li .yt-lockup-tile"),a=[],i=[];try{var o=r("div.search-pager > button ~")[0];a._sp=o.attribs.href.split("&sp=")[1]}catch(t){g("next page results link not found")}for(var l=0;l<n.length;l++){var s=r(n[l]);try{var u=p(r,s);u&&a.push(u)}catch(t){i.push(t)}}e(i[0]||void 0,a)}function p(t,e){var r=t("a",e).attr("href")||"",n=T.parse(r.split("?",2)[1]);return n.list?function(t,e){var r=t(".yt-lockup-content",e),n=t(".yt-lockup-title",r),a=t("a",n),i=a.text().trim(),o=a.attr("href"),l=T.parse(o.split("?",2)[1]),s=l.list,u=l.v,c="",p="",d="",f="",h="",v="",m=t(".yt-lockup-byline",r),y=t("a",m),g=y.attr("href")||"";if(g)0<=g.indexOf("channel/")&&(c=g.split("/").pop(),p="https://youtube.com/channel/"+c,d=y.text().trim()),0<=g.indexOf("user/")&&(f=g.split("/").pop(),h="https://youtube.com/user/"+f,v=y.text().trim());else{var b=m.text().trim();v=b}var x=t(".sidebar",e).text().trim(),w=Number(x.replace(/\D+/g,"")),I=t("li.yt-lockup-playlist-item",r),S=t("a",I[0]).attr("href"),$=T.parse(S.split("?",2)[1]).v,_=u||$,D="https://i.ytimg.com/vi/"+_+"/hqdefault.jpg";return{type:"list",title:i,url:"https://youtube.com/playlist?list="+s,listId:s,videoCountLabel:x,videoCount:w,image:D,thumbnail:D,author:{name:v||d,id:f||c,url:h||p,userId:f,userUrl:h,userName:v,channelId:c,channelUrl:p,channelName:d}}}(t,e):0===r.indexOf("/channel/")||0===r.indexOf("/user/")?function(t,e){var r="https:"+t("img",e).attr("src"),n=t(".yt-lockup-content",e),a=t(".yt-lockup-title",n),i=t("a",a),o=(i.text().trim(),i.attr("href")||""),l="",s="",u="",c="",p="",d="";0<=o.indexOf("channel/")&&(l=o.split("/").pop(),s="https://youtube.com/channel/"+l,u=i.text().trim());0<=o.indexOf("user/")&&(c=o.split("/").pop(),p="https://youtube.com/user/"+c,d=i.text().trim());var f=t(".yt-lockup-meta-info",n).text().trim(),h=Number(f.replace(/\D+/g,"")),v=t(".yt-lockup-description",n).text().trim();return m={type:"channel",title:d||u,description:v,url:p||s,videoCountLabel:f,videoCount:h,image:r,thumbnail:r,name:d||u,id:c||l},y="url",g=p||s,y in m?Object.defineProperty(m,y,{value:g,enumerable:!0,configurable:!0,writable:!0}):m[y]=g,m;var m,y,g}(t,e):n.v?function(t,e){var r=t(".yt-lockup-content",e),n=t(".yt-lockup-title",r),a=(t("img",e).src,t("a",n)),i=_(t("span",n).text()),o=a.attr("href")||"",l=T.parse(o.split("?",2)[1]).v,s=t(".yt-lockup-description",r).text().trim(),u=t(".yt-lockup-meta-info",r),c=t("li",u),p=t(c[0]).text(),d=t(c[1]).text(),f=Number(d.split(" ")[0].split(",").join("").trim()),h="",v="",m="",y="",g=t('a[href^="/user/"]',r);g&&(m=(g.attr("href")||"").replace("/user/","").trim(),y=g.text().trim());var b=t('a[href^="/channel/"]',r);b&&(h=(b.attr("href")||"").replace("/channel/","").trim(),v=b.text().trim());h&&"https://youtube.com/channel/"+h;m&&"https://youtube.com/user/"+m;var x="https://i.ytimg.com/vi/"+l+"/hqdefault.jpg";return{type:"video",title:a.text().trim(),description:s,url:"https://youtube.com/watch?v="+l,videoId:l,seconds:Number(i.seconds),timestamp:i.timestamp,duration:i,views:Number(f),image:x,thumbnail:x,ago:p,author:{name:y||v,url:g.attr("href")||b.attr("href")}}}(t,e):void 0}function _(t){var e=t.split(/\s+/),r=e[e.length-1].replace(/[^:.\d]/g,"");if(!r)return{toString:function(){return e[0]},seconds:0,timestamp:0};for(;r[r.length-1].match(/\D/);)r=r.slice(0,-1);for(var n=(r=r.replace(/\./g,":")).split(/[:.]/),a=0,i=0,o=n.length-1;0<=o;o--)if(!(n[o].length<=0)){var l=n[o].replace(/\D/g,"");if(a+=parseInt(l)*(0<i?Math.pow(60,i):1),2<++i)break}return{toString:function(){return a+" seconds ("+r+")"},seconds:a,timestamp:r}}function D(t){var e="",r=Math.floor(t/36e5),n=Math.floor(t/6e4)%60,a=Math.floor(t/1e3)%60;return r&&(e+=r+":"),n&&(e+=n+":"),String(a).length<2&&(e+="0"),e+=a}function d(t){g("fn: _parsePlaylistLastUpdateTime");for(var e=t.trim().split(/[\s.-]+/),r=0;r<e.length;r++){var n=e.slice(r),a=n.join(" "),i=n.reverse().join(" "),o=new Date(a),l=new Date(i);if("Invalid Date"!==o.toString())return s(o);if("Invalid Date"!==l.toString())return s(l)}return""}function s(t){return g("fn: _toInternalDateString"),t.getUTCFullYear()+"-"+t.getUTCMonth()+"-"+t.getUTCDate()}t.exports=function(t,e){return a(t,e)},t.exports.search=a,u.main===t&&(n="superman theme list pewdiepie channel",console.log("test: doing list search"),a({query:n,pageEnd:1},function(t,e){if(t)throw t;var r=e.videos,n=e.playlists,a=e.channels;console.log("videos: "+r.length),console.log("playlists: "+n.length),console.log("channels: "+a.length);for(var i=0;i<r.length;i++){var o=r[i],l=" ("+o.timestamp+")";console.log(o.title+l)}n.forEach(function(t){console.log("playlist: "+t.title+" | "+t.listId)}),a.forEach(function(t){console.log("channel: "+t.title+" | "+t.description)})}))},{"async.parallellimit":void 0,cheerio:void 0,dasu:void 0,fs:void 0,"human-time":void 0,jsonpath:void 0,path:void 0,querystring:void 0,url:void 0}]},{},[1])(1)}); | ||
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).ytSearch=t()}}(function(){return function n(o,l,s){function u(e,t){if(!l[e]){if(!o[e]){var r="function"==typeof require&&require;if(!t&&r)return r(e,!0);if(c)return c(e,!0);var i=new Error("Cannot find module '"+e+"'");throw i.code="MODULE_NOT_FOUND",i}var a=l[e]={exports:{}};o[e][0].call(a.exports,function(t){return u(o[e][1][t]||t)},a,a.exports,n,o,l,s)}return l[e].exports}for(var c="function"==typeof require&&require,t=0;t<s.length;t++)u(s[t]);return u}({1:[function(u,t,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};var c=u("cheerio"),f=u("dasu");u("async.parallellimit");f.follow=!1,f.debug=!1;var m=u("jsonpath"),h="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) (yt-search; https://www.npmjs.com/package/yt-search)",v=u("url"),r={};Object.keys(process.env).forEach(function(t){var e=process.env[t];if("0"==e||"false"==e||!e)return r[t]=!1;r[t]=e});var y=r.debug;function g(){y&&console.log.apply(this,arguments)}var i,D=u("querystring"),b=u("human-time"),x={YT:"https://youtube.com",SEARCH_MOBILE:"https://m.youtube.com/results",SEARCH_DESKTOP:"https://www.youtube.com/results"};function a(t,e){if(!e)return new Promise(function(r,i){a(t,function(t,e){if(t)return i(t);r(e)})});var r=void 0;if((r="string"==typeof t?{query:t}:t).userAgent&&(h=r.userAgent),r.search=r.query||r.search,r.original_search=r.search,r.videoId)return function(t,a){g("fn: getVideoMetaData");var e=void 0;"string"==typeof t&&(e=t);"object"===(void 0===t?"undefined":n(t))&&(e=t.videoId);var r="https://www.youtube.com/watch?hl=en&gl=US&v="+e,i=v.parse(r);i.headers={"user-agent":h,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},i.headers["user-agent"]="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Safari/605.1.15",f.req(i,function(t,e,r){if(t)a(t);else{if(200!==e.status)return a("http status: "+e.status);if(y){var i=u("fs");u("path");i.writeFileSync("dasu.response",e.responseText,"utf8")}try{!function(t,e){g("_parseVideoInitialData");var r=t.match(/ytInitialData.*=\s*({.*});/);if(!r[1])return e("could not find inital data in the html document");var i=t.match(/ytInitialPlayerResponse.*=\s*({.*});/);if(!i[1])return e("could not find inital player data in the html document");var a=JSON.parse(r[1]),n=JSON.parse(i[1]),o=m.value(a,"$..currentVideoEndpoint..videoId");if(!o)return e("video unavailable");if("ERROR"===m.value(n,"$..status")||"Video unavailable"===m.value(n,"$..reason"))return e("video unavailable");var l=m.value(a,"$..videoPrimaryInfoRenderer..title..text")||m.value(a,"$..videoPrimaryInfoRenderer..title..simpleText")||m.value(a,"$..videoPrimaryRenderer..title..text")||m.value(a,"$..videoPrimaryRenderer..title..simpleText")||m.value(a,"$..title..text")||m.value(a,"$..title..simpleText"),s=m.value(n,"$..description..text")||m.value(n,"$..description..simpleText")||m.value(a,"$..description..text")||m.value(a,"$..description..simpleText"),u=m.value(a,"$..owner..title..text")||m.value(a,"$..owner..title..simpleText"),c=m.value(a,"$..owner..navigationEndpoint..url")||m.value(a,"$..owner..title..url"),p="https://i.ytimg.com/vi/"+o+"/hqdefault.jpg",d=_(T(1e3*Number(m.value(n,"$..videoDetails..lengthSeconds")))),f=m.value(a,"$..sentimentBar..tooltip").split(/[,.]/).join("").split(/\D+/),h=(Number(f[0]),Number(f[1]),m.value(a,"$..dateText")),v={title:l,description:s,url:x.YT+"/watch?v="+o,videoId:o,seconds:Number(d.seconds),timestamp:d.timestamp,duration:d,views:Number(m.value(n,"$..videoDetails..viewCount")),genre:(m.value(n,"$..category")||"").toLowerCase(),uploadDate:m.value(n,"$..uploadDate"),ago:b(new Date(h)),image:p,thumbnail:p,author:{name:u,url:x.YT+c}};e(null,v)}(r,a)}catch(t){a(t)}}})}(r.videoId,e);if(r.listId)return function(t,a){g("fn: getPlaylistMetaData");var e=void 0;"string"==typeof t&&(e=t);"object"===(void 0===t?"undefined":n(t))&&(e=t.listId||t.playlistId);var r="https://www.youtube.com/playlist?hl=en&gl=US&list="+e,i=v.parse(r);i.headers={"user-agent":h,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},f.req(i,function(t,e,r){if(t)a(t);else{if(200!==e.status)return a("http status: "+e.status);if(y){var i=u("fs");u("path");i.writeFileSync("dasu.response",e.responseText,"utf8")}try{!function(t,e){g("fn: parsePlaylistBody");var r=t.match(/ytInitialData.*=\s*({.*});/)[1];if(!r)throw new Error("failed to parse ytInitialData json data");var i=JSON.parse(r),a=m.value(i,"$..microformat..urlCanonical").split("=")[1],n=m.value(i,"$..sidebar.playlistSidebarRenderer.items[0]..stats[1].simpleText").match(/\d+/),o=m.query(i,"$..contents..tabs[0]..contents[0]..contents[0]..contents")[0],l=[];o.forEach(function(t){var e=t,r={title:m.value(e,"$..title..simpleText"),videoId:m.value(e,"$..videoId"),listId:a,thumbnail:m.value(e,"$..thumbnail..thumbnails[0]..url").split("?")[0],author:{name:m.value(e,"$..shortBylineText..runs[0]..text"),url:"https://youtube.com"+m.value(e,"$..shortBylineText..runs[0]..url")}};l.push(r)});var s={title:m.value(i,"$..microformat..title"),listId:a,url:"https://youtube.com/playlist?list="+a,views:Number(n),date:d(m.value(i,"$..sidebar.playlistSidebarRenderer.items[0]..stats[2]..simpleText")),image:l[0].thumbnail,thumbnail:l[0].thumbnail,videos:l,author:{name:m.value(i,"$..videoOwner..title..runs[0]..text"),url:"https://youtube.com"+m.value(i,"$..videoOwner..navigationEndpoint..url")}};e&&e(null,s)}(r,a)}catch(t){a(t)}}})}(r.listId,e);if(!r.search)return e(Error("yt-search: no query given"));!function c(p,d){var t=D.escape(p.search).split(/\s+/),e=p.hl||"en",r=p.gl||"US",i=p.category||"",a=Number(p.pageStart)||1,n=Number(p.pageEnd)||Number(p.pages)||1;a<=0&&(a=1)<=n&&(n+=1),Number.isNaN(n)&&d("error: pageEnd must be a number"),p.pageStart=a,p.pageEnd=n,p.currentPage=p.currentPage||a;var o="?";-1===(o+="search_query="+t.join("+")).indexOf("&hl=")&&(o+="&hl="+e),-1===o.indexOf("&gl=")&&(o+="&gl="+r),i&&(o+="&category="+i),p.sp&&(o+="&sp="+p.sp);var l=x.SEARCH_DESKTOP+o,s=v.parse(l);s.headers={"user-agent":h,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},g(s),g("getting results: "+p.currentPage),f.req(s,function(t,e,r){if(t)d(t);else{if(200!==e.status)return d("http status: "+e.status);if(y){var i=u("fs");u("path"),i.writeFileSync("dasu.response",e.responseText,"utf8")}try{$(r,function(t,e){if(t)return d(t);var r=e,i=r.filter(w),a=r.filter(I),n=r.filter(S);p._data=p._data||{},p._data.videos=p._data.videos||[],p._data.playlists=p._data.playlists||[],p._data.channels=p._data.channels||[],i.forEach(function(t){p._data.videos.push(t)}),a.forEach(function(t){p._data.playlists.push(t)}),n.forEach(function(t){p._data.channels.push(t)}),p.currentPage++;var o=p.currentPage<=p.pageEnd;if(o&&e._sp)p.sp=e._sp,setTimeout(function(){c(p,d)},2500);else{var l=p._data.videos.filter(w),s=p._data.playlists.filter(I),u=p._data.channels.filter(S);d(null,{videos:l,playlists:s,lists:s,accounts:u,channels:u})}})}catch(t){d(t)}}})}(r,e)}function w(t,e,r){if("video"!==t.type)return!1;var i=t.videoId;return r.findIndex(function(t){return i===t.videoId})===e}function I(t,e,r){if("list"!==t.type)return!1;var i=t.listId;return r.findIndex(function(t){return i===t.listId})===e}function S(t,e,r){if("channel"!==t.type)return!1;var i=t.url;return r.findIndex(function(t){return i===t.url})===e}function $(t,e){var r=c.load(t),i=r("li .yt-lockup-tile"),a=[],n=[];try{var o=r("div.search-pager > button ~")[0];a._sp=o.attribs.href.split("&sp=")[1]}catch(t){g("next page results link not found")}for(var l=0;l<i.length;l++){var s=r(i[l]);try{var u=p(r,s);u&&a.push(u)}catch(t){n.push(t)}}e(n[0]||void 0,a)}function p(t,e){var r=t("a",e).attr("href")||"",i=D.parse(r.split("?",2)[1]);return i.list?function(t,e){var r=t(".yt-lockup-content",e),i=t(".yt-lockup-title",r),a=t("a",i),n=a.text().trim(),o=a.attr("href"),l=D.parse(o.split("?",2)[1]),s=l.list,u=l.v,c="",p="",d="",f="",h="",v="",m=t(".yt-lockup-byline",r),y=t("a",m),g=y.attr("href")||"";if(g)0<=g.indexOf("channel/")&&(c=g.split("/").pop(),p="https://youtube.com/channel/"+c,d=y.text().trim()),0<=g.indexOf("user/")&&(f=g.split("/").pop(),h="https://youtube.com/user/"+f,v=y.text().trim());else{var b=m.text().trim();v=b}var x=t(".sidebar",e).text().trim(),w=Number(x.replace(/\D+/g,"")),I=t("li.yt-lockup-playlist-item",r),S=t("a",I[0]).attr("href"),$=D.parse(S.split("?",2)[1]).v,_=u||$,T="https://i.ytimg.com/vi/"+_+"/hqdefault.jpg";return{type:"list",title:n,url:"https://youtube.com/playlist?list="+s,listId:s,videoCountLabel:x,videoCount:w,image:T,thumbnail:T,author:{name:v||d,id:f||c,url:h||p,userId:f,userUrl:h,userName:v,channelId:c,channelUrl:p,channelName:d}}}(t,e):0===r.indexOf("/channel/")||0===r.indexOf("/user/")?function(t,e){var r="https:"+t("img",e).attr("src"),i=t(".yt-lockup-content",e),a=t(".yt-lockup-title",i),n=t("a",a),o=(n.text().trim(),n.attr("href")||""),l="",s="",u="",c="",p="",d="";0<=o.indexOf("channel/")&&(l=o.split("/").pop(),s="https://youtube.com/channel/"+l,u=n.text().trim());0<=o.indexOf("user/")&&(c=o.split("/").pop(),p="https://youtube.com/user/"+c,d=n.text().trim());var f=t(".yt-lockup-meta-info",i).text().trim(),h=Number(f.replace(/\D+/g,"")),v=t(".yt-lockup-description",i).text().trim();return m={type:"channel",title:d||u,description:v,url:p||s,videoCountLabel:f,videoCount:h,image:r,thumbnail:r,name:d||u,id:c||l},y="url",g=p||s,y in m?Object.defineProperty(m,y,{value:g,enumerable:!0,configurable:!0,writable:!0}):m[y]=g,m;var m,y,g}(t,e):i.v?function(t,e){var r=t(".yt-lockup-content",e),i=t(".yt-lockup-title",r),a=(t("img",e).src,t("a",i)),n=_(t("span",i).text()),o=a.attr("href")||"",l=D.parse(o.split("?",2)[1]).v,s=t(".yt-lockup-description",r).text().trim(),u=t(".yt-lockup-meta-info",r),c=t("li",u),p=t(c[0]).text(),d=t(c[1]).text(),f=Number(d.split(" ")[0].split(",").join("").trim()),h="",v="",m="",y="",g=t('a[href^="/user/"]',r);g&&(m=(g.attr("href")||"").replace("/user/","").trim(),y=g.text().trim());var b=t('a[href^="/channel/"]',r);b&&(h=(b.attr("href")||"").replace("/channel/","").trim(),v=b.text().trim());h&&"https://youtube.com/channel/"+h;m&&"https://youtube.com/user/"+m;var x="https://i.ytimg.com/vi/"+l+"/hqdefault.jpg";return{type:"video",title:a.text().trim(),description:s,url:"https://youtube.com/watch?v="+l,videoId:l,seconds:Number(n.seconds),timestamp:n.timestamp,duration:n,views:Number(f),image:x,thumbnail:x,ago:p,author:{name:y||v,url:g.attr("href")||b.attr("href")}}}(t,e):void 0}function _(t){var e=t.split(/\s+/),r=e[e.length-1].replace(/[^:.\d]/g,"");if(!r)return{toString:function(){return e[0]},seconds:0,timestamp:0};for(;r[r.length-1].match(/\D/);)r=r.slice(0,-1);for(var i=(r=r.replace(/\./g,":")).split(/[:.]/),a=0,n=0,o=i.length-1;0<=o;o--)if(!(i[o].length<=0)){var l=i[o].replace(/\D/g,"");if(a+=parseInt(l)*(0<n?Math.pow(60,n):1),2<++n)break}return{toString:function(){return a+" seconds ("+r+")"},seconds:a,timestamp:r}}function T(t){var e="",r=Math.floor(t/36e5),i=Math.floor(t/6e4)%60,a=Math.floor(t/1e3)%60;return r&&(e+=r+":"),i&&(e+=i+":"),String(a).length<2&&(e+="0"),e+=a}function d(t){g("fn: _parsePlaylistLastUpdateTime");for(var e=t.trim().split(/[\s.-]+/),r=0;r<e.length;r++){var i=e.slice(r),a=i.join(" "),n=i.reverse().join(" "),o=new Date(a),l=new Date(n);if("Invalid Date"!==o.toString())return s(o);if("Invalid Date"!==l.toString())return s(l)}return""}function s(t){return g("fn: _toInternalDateString"),t.getUTCFullYear()+"-"+t.getUTCMonth()+"-"+t.getUTCDate()}t.exports=function(t,e){return a(t,e)},t.exports.search=a,u.main===t&&(i="superman theme list pewdiepie channel",console.log("test: doing list search"),a({query:i,pageEnd:1},function(t,e){if(t)throw t;var r=e.videos,i=e.playlists,a=e.channels;console.log("videos: "+r.length),console.log("playlists: "+i.length),console.log("channels: "+a.length);for(var n=0;n<r.length;n++){var o=r[n],l=" ("+o.timestamp+")";console.log(o.title+l)}i.forEach(function(t){console.log("playlist: "+t.title+" | "+t.listId)}),a.forEach(function(t){console.log("channel: "+t.title+" | "+t.description)})}))},{"async.parallellimit":void 0,cheerio:void 0,dasu:void 0,fs:void 0,"human-time":void 0,jsonpath:void 0,path:void 0,querystring:void 0,url:void 0}]},{},[1])(1)}); |
{ | ||
"name": "yt-search", | ||
"version": "2.1.7", | ||
"version": "2.1.8", | ||
"description": "search youtube", | ||
@@ -5,0 +5,0 @@ "main": "dist/yt-search.min.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27073