const qs = require('querystring'); const url = require('url'); const Entities = require('html-entities').AllHtmlEntities; const util = require('./util'); const getMetaItem = (body, name) => { return util.between(body, `'); }; /** * Get video description from html * * @param {String} html * @return {String} */ exports.getVideoDescription = (html) => { const regex = /(.+?)<\/p>[\n\r\s]*?<\/div>/im; const description = html.match(regex); return description ? Entities.decode(util.stripHTML(description[1])) : ''; }; /** * Get video media (extra information) from html * * @param {String} body * @return {Object} */ exports.getVideoMedia = (body) => { let mediainfo = util.between(body, '
', '
'); if (mediainfo === '') { return {}; } const regexp = /

([\s\S]*?)<\/h4>[\s\S]*?[\s\S]*?
  • ([\s\S]*?)<\/li>/g; const contentRegexp = /(.*?)<\/a>/; const media = {}; let match; while ((match = regexp.exec(mediainfo)) != null) { const content = contentRegexp.exec(match[2]); if (content && content[1]) match[2] = content[1]; media[Entities.decode(match[1]).trim().replace(/\s/g, '_').toLowerCase()] = Entities.decode(match[2]); } return media; }; /** * Get video Owner from html. * * @param {String} body * @return {Object} */ const userRegexp = /))/; const VIDEO_URL = 'https://www.youtube.com/watch?v='; exports.getAuthor = (body) => { let ownerinfo = util.between(body, '