Comparing version 2.2.3 to 2.2.4
@@ -1,1 +0,1 @@ | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).ytSearch=e()}}(function(){return function l(r,o,u){function s(t,e){if(!o[t]){if(!r[t]){var i="function"==typeof require&&require;if(!e&&i)return i(t,!0);if(c)return c(t,!0);var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}var a=o[t]={exports:{}};r[t][0].call(a.exports,function(e){return s(r[t][1][e]||e)},a,a.exports,l,r,o,u)}return o[t].exports}for(var c="function"==typeof require&&require,e=0;e<u.length;e++)s(u[e]);return s}({1:[function(s,e,t){"use strict";var l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};var G=s("cheerio"),c=s("dasu");s("async.parallellimit");c.follow=!1,c.debug=!1;var W=s("jsonpath"),d="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) (yt-search; https://www.npmjs.com/package/yt-search)",h=s("url"),i={};Object.keys(process.env).forEach(function(e){var t=process.env[e];if("0"==t||"false"==t||!t)return i[e]=!1;i[e]=t});var m=i.debug;function X(){m&&console.log.apply(this,arguments)}var n,g=s("querystring"),y=s("human-time"),Q={YT:"https://youtube.com",SEARCH_MOBILE:"https://m.youtube.com/results",SEARCH_DESKTOP:"https://www.youtube.com/results"};function a(e,t){if(!t)return new Promise(function(i,n){a(e,function(e,t){if(e)return n(e);i(t)})});var i=void 0;if((i="string"==typeof e?{query:e}:e).userAgent&&(d=i.userAgent),i.search=i.query||i.search,i.original_search=i.search,i.videoId)return function(e,a){X("fn: getVideoMetaData");var t=void 0;"string"==typeof e&&(t=e);"object"===(void 0===e?"undefined":l(e))&&(t=e.videoId);var i="https://www.youtube.com/watch?hl=en&gl=US&v="+t,n=h.parse(i);n.headers={"user-agent":d,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",c.req(n,function(e,t,i){if(e)a(e);else{if(200!==t.status)return a("http status: "+t.status);if(m){var n=s("fs");s("path");n.writeFileSync("dasu.response",t.responseText,"utf8")}try{!function(e,t){X("_parseVideoInitialData");var i=j(S(/ytInitialData.*=\s*{/,e),"{","}");if(!i)return t("could not find inital data in the html document");var n=j(S(/ytInitialPlayerResponse.*=\s*{/,e),"{","}");if(!n)return t("could not find inital player data in the html document");var a=JSON.parse(i),l=JSON.parse(n),r=W.value(a,"$..currentVideoEndpoint..videoId");if(!r)return t("video unavailable");if("ERROR"===W.value(l,"$..status")||"Video unavailable"===W.value(l,"$..reason"))return t("video unavailable");var o=W.value(a,"$..videoPrimaryInfoRenderer..title..text")||W.value(a,"$..videoPrimaryInfoRenderer..title..simpleText")||W.value(a,"$..videoPrimaryRenderer..title..text")||W.value(a,"$..videoPrimaryRenderer..title..simpleText")||W.value(a,"$..title..text")||W.value(a,"$..title..simpleText"),u=W.query(a,"$..description..text").join("")||W.query(l,"$..description..simpleText").join("")||W.query(l,"$..microformat..description..simpleText").join("")||W.query(l,"$..videoDetails..shortDescription").join(""),s=W.value(a,"$..owner..title..text")||W.value(a,"$..owner..title..simpleText"),c=W.value(a,"$..owner..navigationEndpoint..url")||W.value(a,"$..owner..title..url"),d="https://i.ytimg.com/vi/"+r+"/hqdefault.jpg",v=te(I(1e3*Number(W.value(l,"$..videoDetails..lengthSeconds")))),p=W.value(a,"$..sentimentBar..tooltip").split(/[,.]/).join("").split(/\D+/),f=(Number(p[0]),Number(p[1]),W.value(a,"$..dateText")),h={title:o,description:u,url:Q.YT+"/watch?v="+r,videoId:r,seconds:Number(v.seconds),timestamp:v.timestamp,duration:v,views:Number(W.value(l,"$..videoDetails..viewCount")),genre:(W.value(l,"$..category")||"").toLowerCase(),uploadDate:W.value(l,"$..uploadDate"),ago:y(new Date(f)),image:d,thumbnail:d,author:{name:s,url:Q.YT+c}};t(null,h)}(i,a)}catch(e){a(e)}}})}(i.videoId,t);if(i.listId)return function(e,a){X("fn: getPlaylistMetaData");var t=void 0;"string"==typeof e&&(t=e);"object"===(void 0===e?"undefined":l(e))&&(t=e.listId||e.playlistId);var i="https://www.youtube.com/playlist?hl=en&gl=US&list="+t,n=h.parse(i);n.headers={"user-agent":d,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},c.req(n,function(e,t,i){if(e)a(e);else{if(200!==t.status)return a("http status: "+t.status);if(m){var n=s("fs");s("path");n.writeFileSync("dasu.response",t.responseText,"utf8")}try{!function(e,t){X("fn: parsePlaylistBody");var i=e.match(/ytInitialData.*=\s*({.*});/)[1];if(!i)throw new Error("failed to parse ytInitialData json data");var n=JSON.parse(i),a=W.value(n,"$..microformat..urlCanonical").split("=")[1],l=W.value(n,"$..sidebar.playlistSidebarRenderer.items[0]..stats[1].simpleText").match(/\d+/),r=W.query(n,"$..contents..tabs[0]..contents[0]..contents[0]..contents")[0],o=[];r.forEach(function(e){var t=e,i={title:W.value(t,"$..title..simpleText"),videoId:W.value(t,"$..videoId"),listId:a,thumbnail:W.value(t,"$..thumbnail..thumbnails[0]..url").split("?")[0],author:{name:W.value(t,"$..shortBylineText..runs[0]..text"),url:"https://youtube.com"+W.value(t,"$..shortBylineText..runs[0]..url")}};o.push(i)});var u={title:W.value(n,"$..microformat..title"),listId:a,url:"https://youtube.com/playlist?list="+a,views:Number(l),date:v(W.value(n,"$..sidebar.playlistSidebarRenderer.items[0]..stats[2]..simpleText")),image:o[0].thumbnail,thumbnail:o[0].thumbnail,videos:o,author:{name:W.value(n,"$..videoOwner..title..runs[0]..text"),url:"https://youtube.com"+W.value(n,"$..videoOwner..navigationEndpoint..url")}};t&&t(null,u)}(i,a)}catch(e){a(e)}}})}(i.listId,t);if(!i.search)return t(Error("yt-search: no query given"));!function v(p,f){var e=g.escape(p.search).split(/\s+/),t=p.hl||"en",i=p.gl||"US",n=p.category||"",a=Number(p.pageStart)||1,l=Number(p.pageEnd)||Number(p.pages)||1;a<=0&&(a=1)<=l&&(l+=1),Number.isNaN(l)&&f("error: pageEnd must be a number"),p.pageStart=a,p.pageEnd=l,p.currentPage=p.currentPage||a;var r="?";-1===(r+="search_query="+e.join("+")).indexOf("&hl=")&&(r+="&hl="+t),-1===r.indexOf("&gl=")&&(r+="&gl="+i),n&&(r+="&category="+n),p.sp&&(r+="&sp="+p.sp);var o=Q.SEARCH_DESKTOP+r,u=h.parse(o);u.headers={"user-agent":d,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},X(u),X("getting results: "+p.currentPage),c.req(u,function(e,t,i){if(e)f(e);else{if(200!==t.status)return f("http status: "+t.status);if(m){var n=s("fs");s("path"),n.writeFileSync("dasu.response",t.responseText,"utf8")}try{w(i,function(e,t){if(e)return f(e);var i=t,n=i.filter(x),a=i.filter($),l=i.filter(b),r=i.filter(T);p._data=p._data||{},p._data.videos=p._data.videos||[],p._data.playlists=p._data.playlists||[],p._data.channels=p._data.channels||[],p._data.live=p._data.live||[],n.forEach(function(e){p._data.videos.push(e)}),a.forEach(function(e){p._data.playlists.push(e)}),l.forEach(function(e){p._data.channels.push(e)}),r.forEach(function(e){p._data.live.push(e)}),p.currentPage++;var o=p.currentPage<=p.pageEnd;if(o&&t._sp)p.sp=t._sp,setTimeout(function(){v(p,f)},2500);else{var u=p._data.videos.filter(x),s=p._data.playlists.filter($),c=p._data.channels.filter(b),d=p._data.live.filter(T);f(null,{videos:u,live:d,playlists:s,lists:s,accounts:c,channels:c})}})}catch(e){f(e)}}})}(i,t)}function x(e,t,i){if("video"!==e.type)return!1;var n=e.videoId;return i.findIndex(function(e){return n===e.videoId})===t}function $(e,t,i){if("list"!==e.type)return!1;var n=e.listId;return i.findIndex(function(e){return n===e.listId})===t}function b(e,t,i){if("channel"!==e.type)return!1;var n=e.url;return i.findIndex(function(e){return n===e.url})===t}function T(e,t,i){if("live"!==e.type)return!1;var n=e.videoId;return i.findIndex(function(e){return n===e.videoId})===t}function Z(e){var t=void 0;return"string"!=typeof e?e.length?Z(t=e[0]):void 0:0===(t=(t=(t=(t=e).split("?")[0]).split("/default.jpg").join("/hqdefault.jpg")).split("/default.jpeg").join("/hqdefault.jpeg")).indexOf("//")?"https://"+t.slice(2):t.split("http://").join("https://")}function ee(e){if(e){var t=e.split(/\s+/).filter(function(e){return e.match(/\d/)})[0].toLowerCase(),i=Number(t.replace(/\D/g,""));return 0<=t.indexOf("m")?1e6*i:0<=t.indexOf("k")?1e3*i:i}}function w(e,t){var n=/{.*}/,i=G.load(e),a=i("div#initial-data").html()||"";if(!(a=n.exec(a)||""))for(var l=i("script"),r=0;r<l.length;r++){i(l[r]).html().split("\n").forEach(function(e){for(var t=void 0;0<=(t=e.indexOf("ytInitialData"));){e=e.slice(t+"ytInitialData".length);var i=n.exec(e);i&&i.length>a.length&&(a=i)}})}if(!a)return t("could not find inital data in the html document");var o=[],u=[],s=JSON.parse(a[0]),c=W.query(s,"$..itemSectionRenderer..contents.*");X("items.length: "+c.length);for(var d=0;d<c.length;d++){var v=c[d],p=void 0,f="unknown",h=v.compactPlaylistRenderer||v.playlistRenderer,m=v.compactChannelRenderer||v.channelRenderer,g=v.compactVideoRenderer||v.videoRenderer,y=h&&W.value(v,"$..playlistId"),x=m&&W.value(v,"$..channelId"),$=g&&W.value(v,"$..videoId");$&&(f="video"),x&&(f="channel"),y&&(f="list"),0<=W.query(v,"$..viewCountText..text").join("").indexOf("watching")&&(f="live");try{switch(f){case"video":var b=Z(W.value(v,"$..thumbnail..url"))||Z(W.value(v,"$..thumbnails..url"))||Z(W.value(v,"$..thumbnails")),T=W.value(v,"$..title..text")||W.value(v,"$..title..simpleText"),w=W.value(v,"$..shortBylineText..text")||W.value(v,"$..longBylineText..text"),I=W.value(v,"$..shortBylineText..url")||W.value(v,"$..longBylineText..url"),S=W.value(v,"$..publishedTimeText..text")||W.value(v,"$..publishedTimeText..simpleText"),j=W.value(v,"$..viewCountText..text")||W.value(v,"$..viewCountText..simpleText")||"0",_=Number(j.split(/\s+/)[0].split(/[,.]/).join("").trim()),q=te(W.value(v,"$..lengthText..text")||W.value(v,"$..lengthText..simpleText")||"0:00"),D=W.query(v,"$..description..text").join("")||W.query(v,"$..descriptionSnippet..text").join("");p={type:"video",videoId:$,url:Q.YT+"/watch?v="+$,title:T.trim(),description:D,image:b,thumbnail:b,seconds:Number(q.seconds),timestamp:q.timestamp,duration:q,ago:S,views:Number(_),author:{name:w,url:Q.YT+I}};break;case"list":var E=Z(W.value(v,"$..thumbnail..url"))||Z(W.value(v,"$..thumbnails..url"))||Z(W.value(v,"$..thumbnails")),N=W.value(v,"$..title..text")||W.value(v,"$..title..simpleText"),C=W.value(v,"$..shortBylineText..text")||W.value(v,"$..longBylineText..text")||W.value(v,"$..shortBylineText..simpleText")||W.value(v,"$..longBylineText..simpleTextn")||"YouTube",O=W.value(v,"$..shortBylineText..url")||W.value(v,"$..longBylineText..url")||"",B=W.value(v,"$..videoCountShortText..text")||W.value(v,"$..videoCountText..text")||W.value(v,"$..videoCountShortText..simpleText")||W.value(v,"$..videoCountText..simpleText")||W.value(v,"$..thumbnailText..text")||W.value(v,"$..thumbnailText..simpleText");p={type:"list",listId:y,url:Q.YT+"/playlist?list="+y,title:N.trim(),image:E,thumbnail:E,videoCount:B,author:{name:C,url:Q.YT+O}};break;case"channel":var R=Z(W.value(v,"$..thumbnail..url"))||Z(W.value(v,"$..thumbnails..url"))||Z(W.value(v,"$..thumbnails")),P=W.value(v,"$..title..text")||W.value(v,"$..title..simpleText")||W.value(v,"$..displayName..text"),M=W.value(v,"$..shortBylineText..text")||W.value(v,"$..longBylineText..text")||W.value(v,"$..displayName..text")||W.value(v,"$..displayName..simpleText"),Y=W.value(v,"$..videoCountText..text")||W.value(v,"$..videoCountText..simpleText")||"0",k=W.value(v,"$..subscriberCountText..text")||W.value(v,"$..subscriberCountText..simpleText");"string"==typeof k&&(k=k.split(/\s+/).filter(function(e){return e.match(/\d/)})[0]);var U=W.value(v,"$..navigationEndpoint..url")||"/user/"+P;p={type:"channel",name:M,url:Q.YT+U,title:P.trim(),image:R,thumbnail:R,videoCount:Number(Y.replace(/\D+/g,"")),videoCountLabel:Y,subCount:ee(k),subCountLabel:k};break;case"live":var L=Z(W.value(v,"$..thumbnail..url"))||Z(W.value(v,"$..thumbnails..url"))||Z(W.value(v,"$..thumbnails")),A=W.value(v,"$..title..text")||W.value(v,"$..title..simpleText"),V=W.value(v,"$..shortBylineText..text")||W.value(v,"$..longBylineText..text"),z=W.value(v,"$..shortBylineText..url")||W.value(v,"$..longBylineText..url"),F=W.query(v,"$..viewCountText..text").join("")||W.query(v,"$..viewCountText..simpleText").join("")||"0",H=Number(F.split(/\s+/)[0].split(/[,.]/).join("").trim()),J=W.query(v,"$..description..text").join("")||W.query(v,"$..descriptionSnippet..text").join("");p={type:"live",videoId:$,url:Q.YT+"/watch?v="+$,title:A.trim(),description:J,image:L,thumbnail:L,watching:Number(H),author:{name:V,url:Q.YT+z}}}p&&u.push(p)}catch(e){X(e),o.push(e)}}var K=W.value(s,"$..continuation");return u._ctoken=K,o.length?t(o.pop(),u):t(null,u)}function te(e){var t=e.split(/\s+/),i=t[t.length-1].replace(/[^:.\d]/g,"");if(!i)return{toString:function(){return t[0]},seconds:0,timestamp:0};for(;i[i.length-1].match(/\D/);)i=i.slice(0,-1);for(var n=(i=i.replace(/\./g,":")).split(/[:.]/),a=0,l=0,r=n.length-1;0<=r;r--)if(!(n[r].length<=0)){var o=n[r].replace(/\D/g,"");if(a+=parseInt(o)*(0<l?Math.pow(60,l):1),2<++l)break}return{toString:function(){return a+" seconds ("+i+")"},seconds:a,timestamp:i}}function I(e){var t="",i=Math.floor(e/36e5),n=Math.floor(e/6e4)%60,a=Math.floor(e/1e3)%60;return i&&(t+=i+":"),n&&(t+=n+":"),String(a).length<2&&(t+="0"),t+=a}function v(e){X("fn: _parsePlaylistLastUpdateTime");for(var t=e.trim().split(/[\s.-]+/),i=0;i<t.length;i++){var n=t.slice(i),a=n.join(" "),l=n.reverse().join(" "),r=new Date(a),o=new Date(l);if("Invalid Date"!==r.toString())return u(r);if("Invalid Date"!==o.toString())return u(o)}return""}function u(e){return X("fn: _toInternalDateString"),e.getFullYear()+"-"+e.getMonth()+"-"+e.getDate()}function S(e,t){var i=S.cache||{};(S.cache=i)[t]=i[t]||{};var n=i[t].lines||t.split("\n");i[t].lines=n,clearTimeout(i[t].timeout),i[t].timeout=setTimeout(function(){delete i[t]},100);for(var a=0;a<n.length;a++){var l=n[a];if(e.test(l))return l}return""}function j(e,t,i){var n=e.indexOf(t),a=e.lastIndexOf(i);return n<0?"":a<0?"":e.slice(n,a+1)}e.exports=function(e,t){return a(e,t)},e.exports.search=a,s.main===e&&(n="superman theme list pewdiepie channel",console.log("test: doing list search"),a({query:n,pageEnd:1},function(e,t){if(e)throw e;var i=t.videos,n=t.playlists,a=t.channels;console.log("videos: "+i.length),console.log("playlists: "+n.length),console.log("channels: "+a.length);for(var l=0;l<i.length;l++){var r=i[l],o=" ("+r.timestamp+")";console.log(r.title+o)}n.forEach(function(e){console.log("playlist: "+e.title+" | "+e.listId)}),a.forEach(function(e){console.log("channel: "+e.title+" | "+e.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(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).ytSearch=e()}(function(){return function l(r,u,o){function s(t,e){if(!u[t]){if(!r[t]){var i="function"==typeof require&&require;if(!e&&i)return i(t,!0);if(c)return c(t,!0);var n=new Error("Cannot find module '"+t+"'");throw n.code="MODULE_NOT_FOUND",n}var a=u[t]={exports:{}};r[t][0].call(a.exports,function(e){return s(r[t][1][e]||e)},a,a.exports,l,r,u,o)}return u[t].exports}for(var c="function"==typeof require&&require,e=0;e<o.length;e++)s(o[e]);return s}({1:[function(s,e,t){"use strict";function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var G=s("cheerio"),c=s("dasu");s("async.parallellimit");c.follow=!1,c.debug=!1;var W=s("jsonpath"),v="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html) (yt-search; https://www.npmjs.com/package/yt-search)",h=s("url"),i={};Object.keys(process.env).forEach(function(e){var t=process.env[e];if("0"==t||"false"==t||!t)return i[e]=!1;i[e]=t});var m=i.debug;function X(){m&&console.log.apply(this,arguments)}var n,y=s("querystring"),g=s("human-time"),Q={YT:"https://youtube.com",SEARCH_MOBILE:"https://m.youtube.com/results",SEARCH_DESKTOP:"https://www.youtube.com/results"};function a(e,t){if(!t)return new Promise(function(i,n){a(e,function(e,t){return e?n(e):void i(t)})});var i="string"==typeof e?{query:e}:e;if(i.userAgent&&(v=i.userAgent),i.search=i.query||i.search,i.original_search=i.search,i.videoId)return function(e,a){var t;X("fn: getVideoMetaData"),"string"==typeof e&&(t=e);"object"===l(e)&&(t=e.videoId);var i="https://www.youtube.com/watch?hl=en&gl=US&v="+t,n=h.parse(i);n.headers={"user-agent":v,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",c.req(n,function(e,t,i){if(e)a(e);else{if(200!==t.status)return a("http status: "+t.status);var n;m&&(n=s("fs"),s("path"),n.writeFileSync("dasu.response",t.responseText,"utf8"));try{!function(e,t){X("_parseVideoInitialData");var i=j(S(/ytInitialData.*=\s*{/,e),"{","}");if(!i)return t("could not find inital data in the html document");var n=j(S(/ytInitialPlayerResponse.*=\s*{/,e),"{","}");if(!n)return t("could not find inital player data in the html document");var a=JSON.parse(i),l=JSON.parse(n),r=W.value(a,"$..currentVideoEndpoint..videoId");if(!r)return t("video unavailable");if("ERROR"===W.value(l,"$..status")||"Video unavailable"===W.value(l,"$..reason"))return t("video unavailable");var u=W.value(a,"$..videoPrimaryInfoRenderer..title..text")||W.value(a,"$..videoPrimaryInfoRenderer..title..simpleText")||W.value(a,"$..videoPrimaryRenderer..title..text")||W.value(a,"$..videoPrimaryRenderer..title..simpleText")||W.value(a,"$..title..text")||W.value(a,"$..title..simpleText"),o=W.query(a,"$..description..text").join("")||W.query(l,"$..description..simpleText").join("")||W.query(l,"$..microformat..description..simpleText").join("")||W.query(l,"$..videoDetails..shortDescription").join(""),s=W.value(a,"$..owner..title..text")||W.value(a,"$..owner..title..simpleText"),c=W.value(a,"$..owner..navigationEndpoint..url")||W.value(a,"$..owner..title..url"),v="https://i.ytimg.com/vi/"+r+"/hqdefault.jpg",d=Z(function(e){var t="",i=Math.floor(e/36e5),n=Math.floor(e/6e4)%60,a=Math.floor(e/1e3)%60;i&&(t+=i+":");n&&(t+=n+":");String(a).length<2&&(t+="0");return t+=a}(1e3*Number(W.value(l,"$..videoDetails..lengthSeconds")))),p=W.value(a,"$..sentimentBar..tooltip").split(/[,.]/).join("").split(/\D+/),f=(Number(p[0]),Number(p[1]),W.value(a,"$..uploadDate")||W.value(a,"$..dateText..simpleText")),h=f&&g(new Date(f))||"",m={title:u,description:o,url:Q.YT+"/watch?v="+r,videoId:r,seconds:Number(d.seconds),timestamp:d.timestamp,duration:d,views:Number(W.value(l,"$..videoDetails..viewCount")),genre:(W.value(l,"$..category")||"").toLowerCase(),uploadDate:I(f),ago:h,image:v,thumbnail:v,author:{name:s,url:Q.YT+c}};t(null,m)}(i,a)}catch(e){a(e)}}})}(i.videoId,t);if(i.listId)return function(e,a){var t;X("fn: getPlaylistMetaData"),"string"==typeof e&&(t=e);"object"===l(e)&&(t=e.listId||e.playlistId);var i="https://www.youtube.com/playlist?hl=en&gl=US&list="+t,n=h.parse(i);n.headers={"user-agent":v,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"},c.req(n,function(e,t,i){if(e)a(e);else{if(200!==t.status)return a("http status: "+t.status);var n;m&&(n=s("fs"),s("path"),n.writeFileSync("dasu.response",t.responseText,"utf8"));try{!function(e,t){X("fn: parsePlaylistBody");var i=e.match(/ytInitialData.*=\s*({.*});/)[1];if(!i)throw new Error("failed to parse ytInitialData json data");var n=JSON.parse(i),a=W.value(n,"$..microformat..urlCanonical").split("=")[1],l=W.value(n,"$..sidebar.playlistSidebarRenderer.items[0]..stats[1].simpleText").match(/\d+/),r=W.query(n,"$..contents..tabs[0]..contents[0]..contents[0]..contents")[0],u=[];r.forEach(function(e){var t=e,i={title:W.value(t,"$..title..simpleText")||W.value(t,"$..title..text")||W.query(item,"$..title..text").join(""),videoId:W.value(t,"$..videoId"),listId:a,thumbnail:W.value(t,"$..thumbnail..thumbnails[0]..url").split("?")[0],author:{name:W.value(t,"$..shortBylineText..runs[0]..text"),url:"https://youtube.com"+W.value(t,"$..shortBylineText..runs[0]..url")}};u.push(i)});var o={title:W.value(n,"$..microformat..title"),listId:a,url:"https://youtube.com/playlist?list="+a,views:Number(l),date:function(e){X("fn: _parsePlaylistLastUpdateTime");for(var t=e.trim().split(/[\s.-]+/),i=0;i<t.length;i++){var n=t.slice(i),a=n.join(" "),l=n.reverse().join(" "),r=new Date(a),u=new Date(l);if("Invalid Date"!==r.toString())return I(r);if("Invalid Date"!==u.toString())return I(u)}return""}(W.value(n,"$..sidebar.playlistSidebarRenderer.items[0]..stats[2]..simpleText")),image:u[0].thumbnail,thumbnail:u[0].thumbnail,videos:u,author:{name:W.value(n,"$..videoOwner..title..runs[0]..text"),url:"https://youtube.com"+W.value(n,"$..videoOwner..navigationEndpoint..url")}};t&&t(null,o)}(i,a)}catch(e){a(e)}}})}(i.listId,t);if(!i.search)return t(Error("yt-search: no query given"));!function d(p,f){var e=y.escape(p.search).split(/\s+/);var t=p.hl||"en";var i=p.gl||"US";var n=p.category||"";var a=Number(p.pageStart)||1;var l=Number(p.pageEnd)||Number(p.pages)||1;a<=0&&(a=1)<=l&&(l+=1);Number.isNaN(l)&&f("error: pageEnd must be a number");p.pageStart=a;p.pageEnd=l;p.currentPage=p.currentPage||a;var r="?";r+="search_query="+e.join("+");-1===r.indexOf("&hl=")&&(r+="&hl="+t);-1===r.indexOf("&gl=")&&(r+="&gl="+i);n&&(r+="&category="+n);p.sp&&(r+="&sp="+p.sp);var u=Q.SEARCH_DESKTOP+r;var o=h.parse(u);o.headers={"user-agent":v,accept:"text/html","accept-encoding":"gzip","accept-language":"en-US"};X(o);X("getting results: "+p.currentPage);c.req(o,function(e,t,i){if(e)f(e);else{if(200!==t.status)return f("http status: "+t.status);var n;m&&(n=s("fs"),s("path"),n.writeFileSync("dasu.response",t.responseText,"utf8"));try{w(i,function(e,t){if(e)return f(e);var i=t,n=i.filter(x),a=i.filter($),l=i.filter(b),r=i.filter(T);p._data=p._data||{},p._data.videos=p._data.videos||[],p._data.playlists=p._data.playlists||[],p._data.channels=p._data.channels||[],p._data.live=p._data.live||[],n.forEach(function(e){p._data.videos.push(e)}),a.forEach(function(e){p._data.playlists.push(e)}),l.forEach(function(e){p._data.channels.push(e)}),r.forEach(function(e){p._data.live.push(e)}),p.currentPage++;var u,o,s,c,v=p.currentPage<=p.pageEnd;v&&t._sp?(p.sp=t._sp,setTimeout(function(){d(p,f)},2500)):(u=p._data.videos.filter(x),o=p._data.playlists.filter($),s=p._data.channels.filter(b),c=p._data.live.filter(T),f(null,{videos:u,live:c,playlists:o,lists:o,accounts:s,channels:s}))})}catch(e){f(e)}}})}(i,t)}function x(e,t,i){if("video"!==e.type)return!1;var n=e.videoId;return i.findIndex(function(e){return n===e.videoId})===t}function $(e,t,i){if("list"!==e.type)return!1;var n=e.listId;return i.findIndex(function(e){return n===e.listId})===t}function b(e,t,i){if("channel"!==e.type)return!1;var n=e.url;return i.findIndex(function(e){return n===e.url})===t}function T(e,t,i){if("live"!==e.type)return!1;var n=e.videoId;return i.findIndex(function(e){return n===e.videoId})===t}function w(e,t){var n=/{.*}/,i=G.load(e),a=i("div#initial-data").html()||"";if(!(a=n.exec(a)||""))for(var l=i("script"),r=0;r<l.length;r++){i(l[r]).html().split("\n").forEach(function(e){for(var t;0<=(t=e.indexOf("ytInitialData"));){e=e.slice(t+"ytInitialData".length);var i=n.exec(e);i&&i.length>a.length&&(a=i)}})}if(!a)return t("could not find inital data in the html document");var u=[],o=[],s=JSON.parse(a[0]),c=W.query(s,"$..itemSectionRenderer..contents.*");X("items.length: "+c.length);for(var v=0;v<c.length;v++){var d=c[v],p=void 0,f="unknown",h=d.compactPlaylistRenderer||d.playlistRenderer,m=d.compactChannelRenderer||d.channelRenderer,y=d.compactVideoRenderer||d.videoRenderer,g=h&&W.value(d,"$..playlistId"),x=m&&W.value(d,"$..channelId"),$=y&&W.value(d,"$..videoId");$&&(f="video"),x&&(f="channel"),g&&(f="list"),0<=W.query(d,"$..viewCountText..text").join("").indexOf("watching")&&(f="live");try{switch(f){case"video":var b=ee(W.value(d,"$..thumbnail..url"))||ee(W.value(d,"$..thumbnails..url"))||ee(W.value(d,"$..thumbnails")),T=W.value(d,"$..title..text")||W.value(d,"$..title..simpleText"),w=W.value(d,"$..shortBylineText..text")||W.value(d,"$..longBylineText..text"),I=W.value(d,"$..shortBylineText..url")||W.value(d,"$..longBylineText..url"),S=W.value(d,"$..publishedTimeText..text")||W.value(d,"$..publishedTimeText..simpleText"),j=W.value(d,"$..viewCountText..text")||W.value(d,"$..viewCountText..simpleText")||"0",_=Number(j.split(/\s+/)[0].split(/[,.]/).join("").trim()),q=Z(W.value(d,"$..lengthText..text")||W.value(d,"$..lengthText..simpleText")||"0:00"),D=W.query(d,"$..description..text").join("")||W.query(d,"$..descriptionSnippet..text").join(""),p={type:"video",videoId:$,url:Q.YT+"/watch?v="+$,title:T.trim(),description:D,image:b,thumbnail:b,seconds:Number(q.seconds),timestamp:q.timestamp,duration:q,ago:S,views:Number(_),author:{name:w,url:Q.YT+I}};break;case"list":var E=ee(W.value(d,"$..thumbnail..url"))||ee(W.value(d,"$..thumbnails..url"))||ee(W.value(d,"$..thumbnails")),N=W.value(d,"$..title..text")||W.value(d,"$..title..simpleText"),C=W.value(d,"$..shortBylineText..text")||W.value(d,"$..longBylineText..text")||W.value(d,"$..shortBylineText..simpleText")||W.value(d,"$..longBylineText..simpleTextn")||"YouTube",O=W.value(d,"$..shortBylineText..url")||W.value(d,"$..longBylineText..url")||"",B=W.value(d,"$..videoCountShortText..text")||W.value(d,"$..videoCountText..text")||W.value(d,"$..videoCountShortText..simpleText")||W.value(d,"$..videoCountText..simpleText")||W.value(d,"$..thumbnailText..text")||W.value(d,"$..thumbnailText..simpleText");p={type:"list",listId:g,url:Q.YT+"/playlist?list="+g,title:N.trim(),image:E,thumbnail:E,videoCount:B,author:{name:C,url:Q.YT+O}};break;case"channel":var R=ee(W.value(d,"$..thumbnail..url"))||ee(W.value(d,"$..thumbnails..url"))||ee(W.value(d,"$..thumbnails")),P=W.value(d,"$..title..text")||W.value(d,"$..title..simpleText")||W.value(d,"$..displayName..text"),M=W.value(d,"$..shortBylineText..text")||W.value(d,"$..longBylineText..text")||W.value(d,"$..displayName..text")||W.value(d,"$..displayName..simpleText"),Y=W.value(d,"$..videoCountText..text")||W.value(d,"$..videoCountText..simpleText")||"0",k=W.value(d,"$..subscriberCountText..text")||W.value(d,"$..subscriberCountText..simpleText");"string"==typeof k&&(k=k.split(/\s+/).filter(function(e){return e.match(/\d/)})[0]);var U=W.value(d,"$..navigationEndpoint..url")||"/user/"+P;p={type:"channel",name:M,url:Q.YT+U,title:P.trim(),image:R,thumbnail:R,videoCount:Number(Y.replace(/\D+/g,"")),videoCountLabel:Y,subCount:function(e){if(!e)return;var t=e.split(/\s+/).filter(function(e){return e.match(/\d/)})[0].toLowerCase(),i=Number(t.replace(/\D/g,""));return 0<=t.indexOf("m")?1e6*i:0<=t.indexOf("k")?1e3*i:i}(k),subCountLabel:k};break;case"live":var L=ee(W.value(d,"$..thumbnail..url"))||ee(W.value(d,"$..thumbnails..url"))||ee(W.value(d,"$..thumbnails")),A=W.value(d,"$..title..text")||W.value(d,"$..title..simpleText"),V=W.value(d,"$..shortBylineText..text")||W.value(d,"$..longBylineText..text"),z=W.value(d,"$..shortBylineText..url")||W.value(d,"$..longBylineText..url"),F=W.query(d,"$..viewCountText..text").join("")||W.query(d,"$..viewCountText..simpleText").join("")||"0",H=Number(F.split(/\s+/)[0].split(/[,.]/).join("").trim()),J=W.query(d,"$..description..text").join("")||W.query(d,"$..descriptionSnippet..text").join("");p={type:"live",videoId:$,url:Q.YT+"/watch?v="+$,title:A.trim(),description:J,image:L,thumbnail:L,watching:Number(H),author:{name:V,url:Q.YT+z}}}p&&o.push(p)}catch(e){X(e),u.push(e)}}var K=W.value(s,"$..continuation");return o._ctoken=K,u.length?t(u.pop(),o):t(null,o)}function I(e){return e=new Date(e),X("fn: _toInternalDateString"),e.getFullYear()+"-"+(e.getMonth()+1)+"-"+e.getDate()}function Z(e){var t=e.split(/\s+/),i=t[t.length-1].replace(/[^:.\d]/g,"");if(!i)return{toString:function(){return t[0]},seconds:0,timestamp:0};for(;i[i.length-1].match(/\D/);)i=i.slice(0,-1);for(var n=(i=i.replace(/\./g,":")).split(/[:.]/),a=0,l=0,r=n.length-1;0<=r;r--)if(!(n[r].length<=0)){var u=n[r].replace(/\D/g,"");if(a+=parseInt(u)*(0<l?Math.pow(60,l):1),2<++l)break}return{toString:function(){return a+" seconds ("+i+")"},seconds:a,timestamp:i}}function ee(e){var t;return"string"!=typeof e?e.length?ee(t=e[0]):void 0:0===(t=(t=(t=(t=e).split("?")[0]).split("/default.jpg").join("/hqdefault.jpg")).split("/default.jpeg").join("/hqdefault.jpeg")).indexOf("//")?"https://"+t.slice(2):t.split("http://").join("https://")}function S(e,t){var i=S.cache||{};(S.cache=i)[t]=i[t]||{};var n=i[t].lines||t.split("\n");i[t].lines=n,clearTimeout(i[t].timeout),i[t].timeout=setTimeout(function(){delete i[t]},100);for(var a=0;a<n.length;a++){var l=n[a];if(e.test(l))return l}return""}function j(e,t,i){var n=e.indexOf(t),a=e.lastIndexOf(i);return n<0||a<0?"":e.slice(n,a+1)}e.exports=a,e.exports.search=a,s.main===e&&(n="superman theme list pewdiepie channel",console.log("test: doing list search"),a({query:n,pageEnd:1},function(e,t){if(e)throw e;var i=t.videos,n=t.playlists,a=t.channels;console.log("videos: "+i.length),console.log("playlists: "+n.length),console.log("channels: "+a.length);for(var l=0;l<i.length;l++){var r=i[l],u=" (".concat(r.timestamp,")");console.log(r.title+u)}n.forEach(function(e){console.log("playlist: ".concat(e.title," | ").concat(e.listId))}),a.forEach(function(e){console.log("channel: ".concat(e.title," | ").concat(e.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.2.3", | ||
"version": "2.2.4", | ||
"description": "search youtube", | ||
@@ -16,3 +16,3 @@ "main": "dist/yt-search.min.js", | ||
"build": "npm run build:src && npm run uglify", | ||
"build:src": "browserify --node --no-bundle-external --standalone ytSearch -t [ babelify --presets [ env ] ] src/index.js -o dist/yt-search.js 2>&1 | wooster", | ||
"build:src": "browserify --node --no-bundle-external --standalone ytSearch -t [ babelify --presets [ @babel/preset-env ] ] src/index.js -o dist/yt-search.js 2>&1 | wooster", | ||
"uglify": "uglifyjs dist/yt-search.js -cmo dist/yt-search.min.js", | ||
@@ -46,13 +46,13 @@ "prepublishOnly": "npm test", | ||
"devDependencies": { | ||
"@babel/core": "~7.11.4", | ||
"@babel/preset-env": "~7.11.0", | ||
"@talmobi/faucet": "0.0.3", | ||
"babel-core": "~6.26.0", | ||
"babel-preset-env": "~1.6.1", | ||
"babelify": "~8.0.0", | ||
"browserify": "~16.2.3", | ||
"cross-env": "~6.0.3", | ||
"spacestandard": "~0.2.0", | ||
"tape": "~4.9.0", | ||
"uglify-js": "~3.4.9", | ||
"wooster": "~0.3.9" | ||
"babelify": "~10.0.0", | ||
"browserify": "~16.5.2", | ||
"cross-env": "~7.0.2", | ||
"spacestandard": "~0.3.0", | ||
"tape": "~5.0.1", | ||
"uglify-js": "~3.10.2", | ||
"wooster": "~0.5.0" | ||
} | ||
} |
392
README.md
@@ -19,28 +19,54 @@ [![npm](https://img.shields.io/npm/v/yt-search.svg?maxAge=3600)](https://www.npmjs.com/package/yt-search) | ||
## Easy to use | ||
```bash | ||
```javascript | ||
const yts = require( 'yt-search' ) | ||
const r = await yts( 'superman theme' ) | ||
yts( 'superman theme', function ( err, r ) { | ||
if ( err ) throw err | ||
const videos = r.videos | ||
videos.forEach( function ( v ) { | ||
const views = String( v.views ).padStart( 10, ' ' ) | ||
console.log( `${ views } | ${ v.title } (${ v.timestamp }) | ${ v.author.name }` ) | ||
} ) | ||
const videos = r.videos.slice( 0, 3 ) | ||
videos.forEach( function ( v ) { | ||
const views = String( v.views ).padStart( 10, ' ' ) | ||
console.log( `${ views } | ${ v.title } (${ v.timestamp }) | ${ v.author.name }` ) | ||
} ) | ||
``` | ||
// promises also supported | ||
// const r = await yts( 'superman theme' ) | ||
###### output | ||
```javascript | ||
38295386 | Superman Theme (4:13) | Super Man | ||
8267273 | Superman • Main Theme • John Williams (4:26) | HD Film Tributes | ||
470527 | Superman Theme John Williams Extended Version (7:29) | radqo112 | ||
``` | ||
#### single video | ||
```javascript | ||
const video = await yts( { videoId: '_4Vt0UGwmgQ' } ) | ||
console.log( video.title + ` (${ video.duration.timestamp })` ) | ||
``` | ||
###### output | ||
```javascript | ||
36195691 | Superman Theme (4:13) | Super Man | ||
6618027 | Superman • Main Theme • John Williams (4:26) | HD Film Tributes | ||
6521591 | Superman - Main Theme (BBC Proms) (4:46) | m fowkes | ||
Philip Glass. - Koyaanisqatsi (original version) (3:29) | ||
``` | ||
> API/Docs/Samples at bottom of README! | ||
#### single playlist | ||
```javascript | ||
const list = await yts( { listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ' } ) | ||
console.log( 'playlist title: ' + list.title ) | ||
list.videos.forEach( function ( video ) { | ||
console.log( video.title ) | ||
} ) | ||
``` | ||
###### output | ||
```javascript | ||
playlist title: Superman Themes | ||
The Max Fleischer Cartoon (From "Superman") | ||
[Deleted video] | ||
Superman Theme | ||
[Private video] | ||
Superman The Animated Series Full Theme | ||
Smallville theme song | ||
Reprise / Fly Away | ||
Superman Doomsday Soundtrack- Main Title | ||
Hans Zimmer - Man of Steel Theme | ||
Supergirl CW Soundtrack - Superman Theme Extended | ||
``` | ||
## About | ||
@@ -59,31 +85,23 @@ Simple function to get youtube search results. | ||
```bash | ||
const opts = { | ||
query: 'superman theme', | ||
// search: 'superman theme', // same as opts.query | ||
pageStart: 1, // first page result | ||
pageEnd: 3, // until page 3 | ||
// get metadata for a single video by id | ||
// if set, will ignore all other options | ||
// videoId: 'e9vrfEoc8_g', | ||
// get metadata a single playlist by id | ||
// if set, will ignore all other options | ||
// listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
} | ||
var opts = { query: 'superman theme' } | ||
yts( opts, function ( err, r ) { | ||
// if opts is a string then yt-search | ||
// will create this default options object | ||
if ( typeof opts === 'string' ) { | ||
opts = { | ||
query: opts, | ||
pageStart: 1, | ||
pageEnd: 3 | ||
} | ||
} | ||
if ( err ) throw err | ||
console.log( r.videos ) // video results | ||
console.log( r.playlists ) // playlist results | ||
console.log( r.channels ) // channel results | ||
console.log( r.live ) // live stream results | ||
} ) | ||
// ... | ||
var opts = { videoId: 'e9vrfEoc8_g' } | ||
yts( opts, function ( err, video ) { | ||
if ( err ) throw err | ||
console.log( video ) // single video metadata | ||
} ) | ||
var opts = { listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ' } | ||
yts( opts, function ( err, playlist ) { | ||
if ( err ) throw err | ||
console.log( playlist ) // single playlist metadata | ||
console.log( playlist.videos ) // playlist videos | ||
} ) | ||
``` | ||
@@ -98,293 +116,1 @@ | ||
``` | ||
## API | ||
###### Search ( video result ) | ||
```js | ||
const yts = require( 'yt-search' ) | ||
yts( 'superman theme', function ( err, r ) { | ||
const videos = r.videos | ||
const playlists = r.playlists || r.lists | ||
const channels = r.channels || r.accounts | ||
console.log( videos[ 0 ] ) | ||
} ) | ||
``` | ||
###### Output ( video, search result ) | ||
```js | ||
{ type: 'video', | ||
title: 'Superman Theme', | ||
description: 'The theme song from Superman: The Movie.', | ||
url: 'https://youtube.com/watch?v=e9vrfEoc8_g', | ||
videoId: 'e9vrfEoc8_g', | ||
seconds: 253, | ||
timestamp: '4:13', | ||
duration: | ||
{ toString: [Function: toString], | ||
seconds: 253, | ||
timestamp: '4:13' }, | ||
views: 36195691, | ||
thumbnail: 'https://i.ytimg.com/vi/e9vrfEoc8_g/default.jpg', | ||
image: 'https://i.ytimg.com/vi/e9vrfEoc8_g/hqdefault.jpg', | ||
ago: '10 years ago', | ||
author: | ||
{ name: 'Super Man', | ||
id: 'Redmario2569', | ||
url: '/user/Redmario2569', | ||
userId: 'Redmario2569', | ||
userName: 'Super Man', | ||
userUrl: '/user/Redmario2569', | ||
channelId: '', | ||
channelUrl: '', | ||
channelName: '' } } | ||
``` | ||
###### Search ( playlist result ) | ||
```js | ||
const yts = require( 'yt-search' ) | ||
yts( 'superman theme playlist', function ( err, r ) { | ||
const videos = r.videos | ||
const playlists = r.playlists || r.lists | ||
const channels = r.channels || r.accounts | ||
console.log( playlists[ 0 ] ) | ||
} ) | ||
``` | ||
###### Output ( playlist, search result ) | ||
```js | ||
{ type: 'list', | ||
title: 'Superman Theme Songs', | ||
url: | ||
'https://youtube.com/playlist?list=PLYhKAl2FoGzC0IQkgfVtM991w3E8ro1yG', | ||
listId: 'PLYhKAl2FoGzC0IQkgfVtM991w3E8ro1yG', | ||
videoCountLabel: '21 videos', | ||
videoCount: 21, | ||
thumbnail: 'https://i.ytimg.com/vi/yCCq_6ankAI/default.jpg', | ||
image: 'https://i.ytimg.com/vi/yCCq_6ankAI/hqdefault.jpg', | ||
author: | ||
{ name: 'AJ Lelievre', | ||
id: 'UCNtE3kchpzZNnC2ZIGSBR9A', | ||
url: 'https://youtube.com/channel/UCNtE3kchpzZNnC2ZIGSBR9A', | ||
userId: '', | ||
userUrl: '', | ||
userName: '', | ||
channelId: 'UCNtE3kchpzZNnC2ZIGSBR9A', | ||
channelUrl: 'https://youtube.com/channel/UCNtE3kchpzZNnC2ZIGSBR9A', | ||
channelName: 'AJ Lelievre' } } | ||
``` | ||
###### Search ( channel result ) | ||
```js | ||
const yts = require( 'yt-search' ) | ||
yts( 'superman theme playlist', function ( err, r ) { | ||
const videos = r.videos | ||
const playlists = r.playlists || r.lists | ||
const channels = r.channels || r.accounts | ||
console.log( channels[ 0 ] ) | ||
} ) | ||
``` | ||
###### Output ( channel, search result ) | ||
```js | ||
{ type: 'channel', | ||
title: 'PewDiePie', | ||
description: 'I make videos.', | ||
url: 'https://youtube.com/user/PewDiePie', | ||
videoCountLabel: '4,067 videos', | ||
videoCount: 4067, | ||
thumbnail: | ||
'https://yt3.ggpht.com/a/AGF-l79FVckie4j9WT-4cEW6iu3gPd4GivQf_XNSWg=s176-c-k-c0x00ffffff-no-rj-mo', | ||
name: 'PewDiePie', | ||
id: 'PewDiePie' } | ||
``` | ||
###### Video metadata by id | ||
```js | ||
const yts = require( 'yt-search' ) | ||
const opts = { videoId: 'e9vrfEoc8_g' } | ||
yts( opts, function ( err, video ) { | ||
console.log( video ) | ||
} ) | ||
``` | ||
###### Output ( video metadata ) | ||
```js | ||
{ title: 'Superman Theme', | ||
description: 'The theme song from Superman: The Movie', | ||
url: 'https://www.youtube.com/watch?v=e9vrfEoc8_g', | ||
videoId: 'e9vrfEoc8_g', | ||
seconds: 253, | ||
timestamp: '4:13', | ||
duration: | ||
{ toString: [Function: toString], | ||
seconds: 253, | ||
timestamp: '4:13' }, | ||
views: 36200427, | ||
genre: 'music', | ||
uploadDate: '2009-07-27', | ||
ago: '10 years ago', | ||
thumbnail: 'https://i.ytimg.com/vi/e9vrfEoc8_g/default.jpg', | ||
image: 'https://i.ytimg.com/vi/e9vrfEoc8_g/hqdefault.jpg', | ||
author: | ||
{ name: 'Super Man', | ||
id: 'Redmario2569', | ||
url: 'https://youtube.com/user/Redmario2569', | ||
userId: 'Redmario2569', | ||
userName: 'Super Man', | ||
userUrl: 'https://youtube.com/user/Redmario2569', | ||
channelId: 'UCARqIOgzDc-UUAREIitbBwA', | ||
channelName: 'Super Man', | ||
channelUrl: 'https://youtube.com/channel/UCARqIOgzDc-UUAREIitbBwA' } } | ||
``` | ||
###### Playlist metadata by id | ||
```js | ||
const yts = require( 'yt-search' ) | ||
const opts = { listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ' } | ||
yts( opts, function ( err, video ) { | ||
console.log( video ) | ||
} ) | ||
``` | ||
###### Output ( playlist metadata ) | ||
```js | ||
{ title: 'Superman Themes', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://www.youtube.com/playlist?hl=en&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
videoCount: 10, | ||
views: 336, | ||
lastUpdate: '2018-5-24', | ||
thumbnail: 'https://i.ytimg.com/vi/IQtKjU_pOuw/hqdefault.jpg', | ||
items: | ||
[ { title: 'The Max Fleischer Cartoon (From "Superman")', | ||
videoId: 'IQtKjU_pOuw', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=IQtKjU_pOuw&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/IQtKjU_pOuw/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/IQtKjU_pOuw/hqdefault.jpg', | ||
owner: 'Sammy Timberg - Topic', | ||
author: [Object] }, | ||
{ title: '[Deleted video]', | ||
videoId: 'g1PjuAq-ua0', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=g1PjuAq-ua0&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/g1PjuAq-ua0/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/g1PjuAq-ua0/hqdefault.jpg', | ||
owner: undefined, | ||
author: {} }, | ||
{ title: 'Superman Theme', | ||
videoId: 'e9vrfEoc8_g', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=e9vrfEoc8_g&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/e9vrfEoc8_g/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/e9vrfEoc8_g/hqdefault.jpg', | ||
owner: 'Super Man', | ||
author: [Object] }, | ||
{ title: '[Private video]', | ||
videoId: 'Br_8B1exfm8', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=Br_8B1exfm8&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/Br_8B1exfm8/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/Br_8B1exfm8/hqdefault.jpg', | ||
owner: undefined, | ||
author: {} }, | ||
{ title: 'Superman The Animated Series Full Theme', | ||
videoId: 'FHpOVBEXCxM', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=FHpOVBEXCxM&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/FHpOVBEXCxM/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/FHpOVBEXCxM/hqdefault.jpg', | ||
owner: 'Meta Man', | ||
author: [Object] }, | ||
{ title: 'Smallville theme song', | ||
videoId: 'uzlyGxDx8Ck', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=uzlyGxDx8Ck&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/uzlyGxDx8Ck/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/uzlyGxDx8Ck/hqdefault.jpg', | ||
owner: 'WilliamOst26', | ||
author: [Object] }, | ||
{ title: 'Reprise / Fly Away', | ||
videoId: 'szCj7nsC_Zw', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=szCj7nsC_Zw&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/szCj7nsC_Zw/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/szCj7nsC_Zw/hqdefault.jpg', | ||
owner: 'John Ottman - Topic', | ||
author: [Object] }, | ||
{ title: 'Superman Doomsday Soundtrack- Main Title', | ||
videoId: '2HrFrAspWF8', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=2HrFrAspWF8&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/2HrFrAspWF8/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/2HrFrAspWF8/hqdefault.jpg', | ||
owner: 'oved5555', | ||
author: [Object] }, | ||
{ title: 'Hans Zimmer - Man of Steel Theme', | ||
videoId: 'EngKxF3Cqh4', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=EngKxF3Cqh4&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/EngKxF3Cqh4/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/EngKxF3Cqh4/hqdefault.jpg', | ||
owner: 'Camw1n', | ||
author: [Object] }, | ||
{ title: 'Supergirl CW Soundtrack - Superman Theme Extended', | ||
videoId: 'ACeO5Yf1r9w', | ||
listId: 'PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
url: | ||
'https://youtube.com/watch?v=ACeO5Yf1r9w&list=PL7k0JFoxwvTbKL8kjGI_CaV31QxCGf1vJ', | ||
thumbnailUrl: 'https://i.ytimg.com/vi/ACeO5Yf1r9w/default.jpg', | ||
thumbnailUrlHQ: 'https://i.ytimg.com/vi/ACeO5Yf1r9w/hqdefault.jpg', | ||
owner: 'Flash Music', | ||
author: [Object] } ], | ||
author: | ||
{ name: 'Cave Spider10', | ||
id: 'UCdwR7fIE2xyXlNRc7fb9tJg', | ||
url: 'https://youtube.com/channel/UCdwR7fIE2xyXlNRc7fb9tJg', | ||
channelId: 'UCdwR7fIE2xyXlNRc7fb9tJg', | ||
channelUrl: 'https://youtube.com/channel/UCdwR7fIE2xyXlNRc7fb9tJg', | ||
channelUrlText: 'Cave Spider10', | ||
userId: '', | ||
userUrl: '', | ||
userUrlText: '' } } | ||
``` | ||
21368
114