Comparing version 0.0.2 to 0.0.3
"use strict"; | ||
var https = require('https'); | ||
var util = require('./util.js'); | ||
var https = require('https'); | ||
var util = require('./util.js'); | ||
var nextpage_regexp_l = /\"(\/browse_ajax\?action_continuation=1&continuation=([\w%]+))\"/; | ||
var error_regexp_g = /<div class="yt-alert-message" tabindex="0">\n[\s]+([^\n]+)[\s]+<\/div>/g; | ||
var error_regexp_l = /<div class="yt-alert-message" tabindex="0">\n[\s]+([^\n]+)[\s]+<\/div>/; | ||
var nextpage_regexp_l = /\"(\/browse_ajax\?action_continuation=1&continuation=([\w%]+))\"/; | ||
var error_regexp_g = /<div class="yt-alert-message" tabindex="0">\n[\s]+([^\n]+)[\s]+<\/div>/g; | ||
var error_regexp_l = /<div class="yt-alert-message" tabindex="0">\n[\s]+([^\n]+)[\s]+<\/div>/; | ||
@@ -13,5 +13,5 @@ exports.get_firstpage = function(playlist_id, options, callback) { | ||
if(resp.statusCode != 200) { | ||
return callback(new Error('Status code: '+resp.statusCode)); | ||
return callback(new Error('Status code: ' + resp.statusCode)); | ||
} | ||
let resp_string = ''; | ||
var resp_string = ''; | ||
resp.on('data', function(data) { | ||
@@ -21,11 +21,11 @@ resp_string += data.toString(); | ||
resp.on('end', function() { | ||
let errors = resp_string.match(error_regexp_g).splice(1); | ||
errors = errors.map(function(item) {return item.match(error_regexp_l)[1]}); | ||
var errors = resp_string.match(error_regexp_g).splice(1); | ||
errors = errors.map(function(item) { return item.match(error_regexp_l)[1] }); | ||
if(errors.length >= 1) { | ||
return callback(new Error(errors)); | ||
} | ||
let response = util.get_info(resp_string, playlist_id); | ||
let playlistitems = util.get_video_container(resp_string).split('<tr').splice(1); | ||
var response = util.get_general_info(resp_string, playlist_id); | ||
var playlistitems = util.get_video_container(resp_string).split('<tr').splice(1); | ||
response.items = playlistitems.map(function(item) { | ||
@@ -37,8 +37,8 @@ return util.build_video_object(item); | ||
}) | ||
let nextpage_link = resp_string.match(nextpage_regexp_l); | ||
if( nextpage_link && (options.limit ? options.limit > response.items.length : true) ) { | ||
var nextpage_link = resp_string.match(nextpage_regexp_l); | ||
if(nextpage_link && (options.limit ? options.limit > response.items.length : true)) { | ||
response.nextpage = nextpage_link[1]; | ||
} | ||
if(options.limit) { | ||
@@ -45,0 +45,0 @@ options.limit = options.limit - response.items.length; |
"use strict"; | ||
var https = require('https'); | ||
var firstpage = require('./firstpage.js'); | ||
var nonfirstpage = require('./nonfirstpage.js'); | ||
var util = require('./util.js') | ||
var https = require('https'); | ||
var firstpage = require('./firstpage.js'); | ||
var nonfirstpage = require('./nonfirstpage.js'); | ||
var util = require('./util.js') | ||
module.exports = function(link_or_id, object_or_callback ,callback) { | ||
module.exports = function(link_or_id, object_or_callback, callback) { | ||
if(!callback) { | ||
@@ -21,4 +21,3 @@ callback = object_or_callback; | ||
return callback(null, plist_obj); | ||
} | ||
else { | ||
} else { | ||
nonfirstpage.get_nonfirstpage(plist_obj.nextpage, object_or_callback, function(err2, plist_items) { | ||
@@ -25,0 +24,0 @@ if(err2) { |
"use strict"; | ||
var https = require('https'); | ||
var util = require('./util.js'); | ||
var https = require('https'); | ||
var util = require('./util.js'); | ||
@@ -14,14 +14,13 @@ exports.get_nonfirstpage = function(nextpage_link, options, callback) { | ||
var parsed_string; | ||
try { | ||
parsed_string = JSON.parse(resp_string); | ||
} | ||
catch(err) { | ||
} catch(err) { | ||
return callback(err); | ||
} | ||
var content = parsed_string.content_html; | ||
var next_page = parsed_string.load_more_widget_html; | ||
var next_page_link = util.between(next_page, 'data-uix-load-more-href="', '"'); | ||
var playlistitems = util.get_video_container(content).split('<tr').splice(1); | ||
@@ -34,4 +33,4 @@ var items = playlistitems.map(function(item) { | ||
}) | ||
if( next_page_link !== '' && (options.limit ? options.limit > items.length : true) ) { | ||
if(next_page_link !== '' && (options.limit ? options.limit > items.length : true)) { | ||
if(next_page_link === nextpage_link) { | ||
@@ -49,9 +48,7 @@ return callback(null, items); | ||
}) | ||
} else { | ||
return callback(null, items); | ||
} | ||
else { | ||
return callback(null, items); | ||
} | ||
}); | ||
}); | ||
}; | ||
"use strict"; | ||
var Entities = require('html-entities').AllHtmlEntities; | ||
var url = require('url'); | ||
var https = require('https'); | ||
var url = require('url'); | ||
var Entities = require('html-entities').AllHtmlEntities; | ||
var url = require('url'); | ||
var https = require('https'); | ||
var VIDEO_URL = "https://www.youtube.com/watch?v=" | ||
var PLAYLIST_URL = "https://www.youtube.com/playlist?list=" | ||
var VIDEO_URL = 'https://www.youtube.com/watch?v=' | ||
var PLAYLIST_URL = 'https://www.youtube.com/playlist?list=' | ||
exports.between = function(haystack, left, right) { | ||
var pos; | ||
pos = haystack.indexOf(left); | ||
if(pos === -1) { return ''; } | ||
haystack = haystack.slice(pos + left.length); | ||
pos = haystack.indexOf(right); | ||
if(pos === -1) { return ''; } | ||
haystack = haystack.slice(0, pos); | ||
return haystack; | ||
}; | ||
var author_reflink_regexp = /<ul class="pl-header-details"><li>(.*?(?=<\/li>))<\/li><li>.*?(?=<li>)<li>(.*?(?=<\/li>))<\/li><li>(.*?(?=<\/li>))<\/li>/; | ||
var playlist_name_regexp = /<h1 class="pl-header-title[^"]*" tabindex="0">\n[\s]*(.*?(?=\n))\n[\s]+(<\/h1>|<div)/; | ||
exports.get_info = function(body, plist_id) { | ||
var author_reflink_regexp = /<ul class="pl-header-details"><li>(.*?(?=<\/li>))<\/li><li>.*?(?=<li>)<li>(.*?(?=<\/li>))<\/li><li>(.*?(?=<\/li>))<\/li>/; | ||
var playlist_name_regexp = /<h1 class="pl-header-title[^"]*" tabindex="0">\n[\s]*(.*?(?=\n))\n[\s]+(<\/h1>|<div)/; | ||
exports.get_general_info = function(body, plist_id) { | ||
var important_txt = exports.between(body, 'branded-page-box clearfix', '<div class="playlist-auxiliary-actions">'); | ||
@@ -33,3 +21,3 @@ var author_match = important_txt.match(author_reflink_regexp); | ||
description: exports.remove_html(exports.between(important_txt, '<span class="pl-header-description-text" tabindex="0">', '</span>').replace(/<button class="yt-uix-button[\s\S]+/, '')), | ||
views: author_match[2].split(' ')[0].replace('.',''), | ||
views: author_match[2].split(' ')[0].replace('.', ''), | ||
last_updated: author_match[3], | ||
@@ -41,6 +29,6 @@ author: { | ||
user: important_txt.includes('/user/') ? exports.between(author_match[1], 'href="/user/', '"') : null, | ||
channel_url: url.resolve(PLAYLIST_URL, '/channel/'+exports.between(author_match[1], 'data-ytid="', '"')), | ||
channel_url: url.resolve(PLAYLIST_URL, '/channel/' + exports.between(author_match[1], 'data-ytid="', '"')), | ||
user_url: important_txt.includes('/user/') ? url.resolve(PLAYLIST_URL, exports.between(author_match[1], 'href="', '"')) : null, | ||
}, | ||
items: [] | ||
items: [], | ||
}; | ||
@@ -67,3 +55,3 @@ }; | ||
user: videoString.includes('/user/') ? exports.between(videoString, 'href="/user/', '"') : null, | ||
channel_url: url.resolve(PLAYLIST_URL, '/channel/'+exports.between(videoString, 'data-ytid="', '"')), | ||
channel_url: url.resolve(PLAYLIST_URL, '/channel/' + exports.between(videoString, 'data-ytid="', '"')), | ||
user_url: videoString.includes('/user/') ? url.resolve(PLAYLIST_URL, '/user/' + exports.between(videoString, 'href="/user/', '"')) : null, | ||
@@ -77,5 +65,5 @@ } | ||
string.replace(/\n/g, ' ') | ||
.replace(/\s*<\s*br\s*\/?\s*>\s*/gi, '\n') | ||
.replace(/<\s*\/\s*p\s*>\s*<\s*p[^>]*>/gi, '\n') | ||
.replace(/<.*?>/gi, '') | ||
.replace(/\s*<\s*br\s*\/?\s*>\s*/gi, '\n') | ||
.replace(/<\s*\/\s*p\s*>\s*<\s*p[^>]*>/gi, '\n') | ||
.replace(/<.*?>/gi, '') | ||
).trim(); | ||
@@ -97,4 +85,4 @@ }; | ||
var p = parsed.pathname.split('/'); | ||
var maybe_type = p[p.length -2]; | ||
var maybe_id = p[p.length -1]; | ||
var maybe_type = p[p.length - 2]; | ||
var maybe_id = p[p.length - 1]; | ||
if(maybe_type === 'channel') { | ||
@@ -104,13 +92,10 @@ if(id_regex.test(maybe_id)) { | ||
return callback(null, maybe_id); | ||
} else { | ||
return callback(new Error('unable to find a id in ' + link)); | ||
} | ||
else { | ||
return callback(new Error('unable to find a id in '+link)); | ||
} | ||
} | ||
else if(maybe_type === 'user') { | ||
} else if(maybe_type === 'user') { | ||
return exports.user_to_channel(maybe_id, callback); | ||
} else { | ||
return callback(new Error('unable to find a id in ' + link)); | ||
} | ||
else { | ||
return callback(new Error('unable to find a id in '+link)); | ||
} | ||
}; | ||
@@ -120,3 +105,3 @@ | ||
exports.user_to_channel = function(user, callback) { | ||
https.get('https://www.youtube.com/user/'+user, function(resp) { | ||
https.get('https://www.youtube.com/user/' + user, function(resp) { | ||
var response_string = ''; | ||
@@ -140,8 +125,21 @@ var found = false; | ||
return callback(null, 'UU' + channel_match[1].substr(2)); | ||
} else { | ||
return callback(new Error('unable to resolve the user ' + user)); | ||
} | ||
else { | ||
return callback(new Error('unable to resolve the user '+user)); | ||
} | ||
}); | ||
}); | ||
}; | ||
//taken from https://github.com/fent/node-ytdl-core/ | ||
exports.between = function(haystack, left, right) { | ||
var pos; | ||
pos = haystack.indexOf(left); | ||
if(pos === -1) { return ''; } | ||
haystack = haystack.slice(pos + left.length); | ||
if(!right) { return haystack; } | ||
pos = haystack.indexOf(right); | ||
if(pos === -1) { return ''; } | ||
haystack = haystack.slice(0, pos); | ||
return haystack; | ||
}; |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"repository": { | ||
@@ -11,0 +11,0 @@ "type": "git", |
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
17662
243