video-parser
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,5 @@ | ||
# 2.1.0 | ||
- Add authentication processing based on version upgrade of Facebook sdk ([@ignocide](https://github.com/ignocide)) | ||
# 2.0.0 | ||
@@ -2,0 +6,0 @@ |
@@ -52,2 +52,7 @@ /** | ||
}, | ||
facebook: { | ||
appId: '', | ||
appSecret: '', | ||
access_token: '' | ||
}, | ||
ttl: 3600 * 12 // 1 day | ||
@@ -64,2 +69,3 @@ }) | ||
this._config = config | ||
this._updateFacebookToken(function () {}) | ||
} | ||
@@ -560,44 +566,60 @@ | ||
var self = this | ||
FB.napi(id, function (err, res) { | ||
if (err) { | ||
return cb('video.invalid_url') | ||
} | ||
var retry = 0 | ||
if (res.published === false) { | ||
return cb('video.forbidden') | ||
} | ||
// filter | ||
var filtered = [] | ||
for (var i = 0; i < res.format.length; i++) { | ||
if (res.format[i].width > 400) { | ||
filtered.push(res.format[i]) | ||
var _requestFacebook = function () { | ||
FB.setAccessToken(self._config.facebook.access_token) | ||
FB.napi(id, function (err, res) { | ||
if (err) { | ||
if (err.response.error.code == 104) { | ||
if (retry == 0) { | ||
retry++ | ||
self._updateFacebookToken(function () { | ||
return _requestFacebook() | ||
}) | ||
} | ||
return cb('facebook.auth') | ||
} | ||
return cb('video.invalid_url') | ||
} | ||
} | ||
var thumbnail = filtered.length > 0 ? filtered[0] : res.format[res.format.length - 1] | ||
self.loadMeta(function (err, meta) { | ||
if (err) { | ||
return cb(err) | ||
if (res.published === false) { | ||
return cb('video.forbidden') | ||
} | ||
// filter | ||
var filtered = [] | ||
for (var i = 0; i < res.format.length; i++) { | ||
if (res.format[i].width > 400) { | ||
filtered.push(res.format[i]) | ||
} | ||
} | ||
var thumbnail = filtered.length > 0 ? filtered[0] : res.format[res.format.length - 1] | ||
cb(err, { | ||
id: id, | ||
url: ['https://www.facebook.com/', res.from.id, '/videos/', id].join(''), | ||
name: res.from.name, | ||
desc: res.description, | ||
thumb_url: thumbnail.picture || res.picture, | ||
duration: Math.round(meta.format.duration), | ||
ctime: moment(res.created_time).format(), | ||
ratings: null, | ||
details: { | ||
definition: '', | ||
author: { | ||
id: res.from.id, | ||
title: res.from.name | ||
}, | ||
source: res.source | ||
self.loadMeta(function (err, meta) { | ||
if (err) { | ||
return cb(err) | ||
} | ||
}) | ||
}, 'facebook_meta_' + id, res.source) | ||
}) | ||
cb(err, { | ||
id: id, | ||
url: ['https://www.facebook.com/', res.from.id, '/videos/', id].join(''), | ||
name: res.from.name, | ||
desc: res.description, | ||
thumb_url: thumbnail.picture || res.picture, | ||
duration: Math.round(meta.format.duration), | ||
ctime: moment(res.created_time).format(), | ||
ratings: null, | ||
details: { | ||
definition: '', | ||
author: { | ||
id: res.from.id, | ||
title: res.from.name | ||
}, | ||
source: res.source | ||
} | ||
}) | ||
}, 'facebook_meta_' + id, res.source) | ||
}) | ||
} | ||
_requestFacebook() | ||
} | ||
@@ -642,3 +664,2 @@ | ||
} | ||
Parser.prototype.requestDailymotion = function (cb, id) { | ||
@@ -1155,2 +1176,18 @@ var url = ['https://api.dailymotion.com/video/', | ||
Parser.prototype._updateFacebookToken = function (cb) { | ||
var self = this | ||
var opts = self._config.facebook | ||
FB.api('oauth/access_token', { | ||
client_id: opts.appId, | ||
client_secret: opts.appSecret, | ||
grant_type: 'client_credentials' | ||
}, function (res) { | ||
if (!res || res.error) { | ||
return cb('facebook.auth') | ||
} | ||
opts.access_token = res.access_token | ||
cb(null, res.access_token) | ||
}) | ||
} | ||
module.exports = Parser |
{ | ||
"name": "video-parser", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"author": { | ||
@@ -40,3 +40,3 @@ "name": "egg", | ||
"cheerio": "^0.19.0", | ||
"fb": "^0.7.0", | ||
"fb": "^2.0.0", | ||
"fluent-ffmpeg": "^2.0.1", | ||
@@ -43,0 +43,0 @@ "merge-defaults": "^0.2.1", |
@@ -60,3 +60,8 @@ # video-parser | ||
key: '' | ||
} | ||
}, | ||
facebook: { | ||
appId: '', | ||
appSecret: '', | ||
access_token: '' | ||
}, | ||
ttl: 3600 * 12 // 1 day | ||
@@ -63,0 +68,0 @@ }) |
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
54185
1194
378
+ Addedany-promise@1.3.0(transitive)
+ Addedbabel-runtime@6.26.0(transitive)
+ Addedcore-decorators@0.17.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedfb@2.0.0(transitive)
+ Addedms@2.0.0(transitive)
+ Addedregenerator-runtime@0.11.1(transitive)
- Removedcrypto@0.0.3(transitive)
- Removedfb@0.7.3(transitive)
- Removedrequest@2.9.203(transitive)
Updatedfb@^2.0.0