ytdl-core
Advanced tools
Comparing version 0.9.2 to 0.10.0
@@ -64,2 +64,5 @@ var PassThrough = require('stream').PassThrough; | ||
} | ||
if (options.begin) { | ||
url += '&begin=' + util.fromHumanTime(options.begin); | ||
} | ||
@@ -66,0 +69,0 @@ doDownload(stream, url, options, 3); |
@@ -48,2 +48,3 @@ var urllib = require('url'); | ||
var id = util.getVideoID(link); | ||
if (id instanceof Error) return callback(id); | ||
@@ -217,3 +218,3 @@ // Try getting config from the video page first. | ||
if (!info.formats.length) { | ||
callback(new Error('Video does not contain any available formats')); | ||
callback(new Error('This video is unavailable')); | ||
return; | ||
@@ -220,0 +221,0 @@ } |
@@ -237,6 +237,6 @@ var qs = require('querystring'); | ||
if (!id) { | ||
throw new Error('No video id found: ' + link); | ||
return new Error('No video id found: ' + link); | ||
} | ||
if (!idRegex.test(id)) { | ||
throw new Error('Video id (' + id + ') does not match expected format (' + idRegex.toString() + ')'); | ||
return new Error('Video id (' + id + ') does not match expected format (' + idRegex.toString() + ')'); | ||
} | ||
@@ -411,1 +411,38 @@ return id; | ||
}; | ||
/** | ||
* Converts human friendly time to milliseconds. Supports the format | ||
* 00:00:00.000 for hours, minutes, seconds, and milliseconds respectively. | ||
* And 0ms, 0s, 0m, 0h, and together 1m1s. | ||
* | ||
* @param {String|Number} time | ||
* @return {Number} | ||
*/ | ||
var numberFormat = /^\d+$/; | ||
var timeFormat = /^(?:(?:(\d+):)?(\d{1,2}):)?(\d{1,2})(?:\.(\d{3}))?$/; | ||
var timeUnits = { | ||
ms: 1, | ||
s: 1000, | ||
m: 60000, | ||
h: 3600000, | ||
}; | ||
exports.fromHumanTime = function(time) { | ||
if (typeof time === 'number') { return time; } | ||
if (numberFormat.test(time)) { return +time; } | ||
var firstFormat = timeFormat.exec(time); | ||
if (firstFormat) { | ||
return +(firstFormat[1] || 0) * timeUnits.h + | ||
+(firstFormat[2] || 0) * timeUnits.m + | ||
+(firstFormat[3] || 0) * timeUnits.s + | ||
+(firstFormat[4] || 0); | ||
} else { | ||
var total = 0; | ||
var r = /(\d+)(ms|s|m|h)/g; | ||
var rs; | ||
while ((rs = r.exec(time)) != null) { | ||
total += +rs[1] * timeUnits[rs[2]]; | ||
} | ||
return total; | ||
} | ||
}; |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.9.2", | ||
"version": "0.10.0", | ||
"repository": { | ||
@@ -28,6 +28,6 @@ "type": "git", | ||
"mocha": "*", | ||
"muk-prop": "^0.5.3", | ||
"muk-prop": "^1.0.0", | ||
"nock": "*", | ||
"sinon": "^1.17.6", | ||
"stream-equal": "~0.1.0" | ||
"stream-equal": "~1.0.0" | ||
}, | ||
@@ -34,0 +34,0 @@ "engines": { |
@@ -31,2 +31,3 @@ # node-ytdl-core | ||
* `range` - A byte range in the form `INT-INT` that specifies part of the file to download. ie 10355705-12452856. Note that this downloads a portion of the file, and not a separately spliced video. | ||
* `begin` - What time to begin downloading the video, supports formats 00:00:00.000, or 0ms, 0s, 0m, 0h, or number of milliseconds. Example: 1:30, 05:10.123, 10m30s | ||
* `requestOptions` - Anything to merge into the request options which `http.get()` is called with, such as headers. | ||
@@ -33,0 +34,0 @@ * `request` - A function that will be called for each request, instead of ytdl's internal method of making requests. Its signature looks like `Function(url, options, [callback(error, body)]): http.ClientRequest` |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
52011
1682
119
2