youtube-video-exists
Version:
Checks if a YouTube video exists under the given ID. No API key is required.
3 lines (2 loc) • 806 B
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var t,e=(t=require("axios"))&&"object"==typeof t&&"default"in t?t.default:t,a=new RegExp("^([0-9A-Za-z_-]{10}[048AEIMQUYcgkosw])$");exports.getVideoInfo=function(t){var r={existing:!1,validId:!1,private:void 0,info:void 0};return a.test(t)?(r.validId=!0,e.request({url:"oembed",baseURL:"https://www.youtube.com/",params:{url:"https://youtu.be/"+t,format:"json"},validateStatus:function(t){return 200===t||404===t||401===t}}).then((function(t){return 200===t.status?(r.existing=!0,r.private=!1,r.info={title:t.data.title,author:{name:t.data.author_name,url:t.data.author_url}}):401===t.status&&(r.existing=!0,r.private=!0),r}))):new Promise((function(t){return t(r)}))};
//# sourceMappingURL=youtube-video-exists.cjs.production.min.js.map