Socket
Socket
Sign inDemoInstall

flickr-set-get

Package Overview
Dependencies
162
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.1 to 1.1.2

tests/fixtures/getSizes_video_ok.json

5

CHANGELOG.md

@@ -0,1 +1,6 @@

1.1.2
-----
- Added support for downloading videos ([saemy](https://github.com/lmammino/flickr-set-get/pull/34))
1.1.1

@@ -2,0 +7,0 @@ -----

36

lib/Flickr.js

@@ -22,2 +22,3 @@ 'use strict';

* - **size** {string} The size of the image to download (eg. "Original", "Large", "Medium", etc.)
* - **videoSize** {string} The size of the video to download (eg. "Video Original", "HD MP4", "Mobile MP4", etc.)
* - **noOverwrite** {boolean} if true avoids to override already existing files (default: false)

@@ -49,2 +50,3 @@ * - **auth** {boolean|object} if false it will not use authentication. Otherwise it should be an object

size: 'Original',
videoSize: 'Video Original',
noOverwrite: false,

@@ -228,9 +230,18 @@ auth: false

var path = _path.join(_this.options.outputDir, photoId + '.jpg');
if (_this.options.noOverwrite && fs.existsSync(path)) {
_this.emit('photoSkipped', photoId, path);
async.setImmediate(function onAsync() {
cb(null, path);
});
var videoPath = _path.join(_this.options.outputDir, photoId + '.mp4');
if (_this.options.noOverwrite) {
var exists = fs.existsSync(path);
if (fs.existsSync(videoPath)) {
exists = true;
path = videoPath;
}
return;
if (exists) {
_this.emit('photoSkipped', photoId, path);
async.setImmediate(function onAsync() {
cb(null, path);
});
return;
}
}

@@ -247,4 +258,11 @@

if (!sizes[_this.options.size]) {
var sizeErr = new Error('Size "' + _this.options.size + '" not available');
var size = _this.options.size;
if (sizes['Video Original']) {
// This is a video.
size = _this.options.videoSize;
path = videoPath;
}
if (!sizes[size]) {
var sizeErr = new Error('Size "' + size + '" not available');
_this.emit('warning', sizeErr);

@@ -255,3 +273,3 @@

download(sizes[_this.options.size].source, path, function onDownloadComplete() {
download(sizes[size].source, path, function onDownloadComplete() {

@@ -258,0 +276,0 @@ if (err) {

@@ -13,3 +13,3 @@ {

],
"version": "1.1.1",
"version": "1.1.2",
"author": {

@@ -16,0 +16,0 @@ "name": "Luciano Mammino",

@@ -46,6 +46,6 @@ {

"pages":2,
"total":"5",
"total":"6",
"title":"Example set"
},
"stat":"ok"
}
}

@@ -29,2 +29,13 @@ {

"isfamily":0
},
{
"id":"video1",
"secret":"video1_secret",
"server":"someserver",
"farm":9,
"title":"video1",
"isprimary":"0",
"ispublic":1,
"isfriend":0,
"isfamily":0
}

@@ -36,6 +47,6 @@ ],

"pages":2,
"total":"5",
"total":"6",
"title":"Example set"
},
"stat":"ok"
}
}

@@ -62,2 +62,13 @@ {

"isfamily":0
},
{
"id":"video1",
"secret":"video1_secret",
"server":"someserver",
"farm":9,
"title":"video1",
"isprimary":"0",
"ispublic":1,
"isfriend":0,
"isfamily":0
}

@@ -69,6 +80,6 @@ ],

"pages":1,
"total":"5",
"total":"6",
"title":"Example set"
},
"stat":"ok"
}
}

@@ -77,2 +77,3 @@ 'use strict';

// Photos.
for (var i = 1; i < 6; i++) {

@@ -87,2 +88,12 @@ var path = 'temp/photo' + i + '.jpg';

// Videos.
for (var i = 1; i < 2; i++) {
var path = 'temp/video' + i + '.mp4';
if (fs.readFileSync(path, 'utf8') !== 'This is a video') {
ok = false;
}
fs.unlinkSync(path);
}
rmDirSyncIfExists('temp');

@@ -109,2 +120,10 @@

// Size response for the video.
nock('https://api.flickr.com')
.filteringPath(/photo_id=[^&]*/g, 'photo_id=XXX')
.get('/services/rest?photo_id=XXX&nojsoncallback=1&format=json' +
'&api_key=apiKey&method=flickr.photos.getSizes')
.reply(200, fs.readFileSync('./tests/fixtures/getSizes_video_ok.json', 'utf8'))
;
nock('https://farm9.staticflickr.com')

@@ -115,2 +134,6 @@ .get('/1234/12345678910_2a37e1c3ac_o.jpg')

;
nock('https://farm9.staticflickr.com')
.get('/1234/12345678910_2a37e1c3ac_vo.mp4')
.reply(200, 'This is a video')
;

@@ -131,2 +154,3 @@ f.downloadSet('someSet', 'someUser');

// Photos.
for (var i = 1; i < 6; i++) {

@@ -141,2 +165,12 @@ var path = 'temp/photo' + i + '.jpg';

// Videos.
for (var i = 1; i < 2; i++) {
var path = 'temp/video' + i + '.mp4';
if (fs.readFileSync(path, 'utf8') !== 'This is a video') {
ok = false;
}
fs.unlinkSync(path);
}
rmDirSyncIfExists('temp');

@@ -169,2 +203,10 @@

// Size response for the video.
nock('https://api.flickr.com')
.filteringPath(/photo_id=[^&]*/g, 'photo_id=XXX')
.get('/services/rest?photo_id=XXX&nojsoncallback=1&format=json' +
'&api_key=apiKey&method=flickr.photos.getSizes')
.reply(200, fs.readFileSync('./tests/fixtures/getSizes_video_ok.json', 'utf8'))
;
nock('https://farm9.staticflickr.com')

@@ -175,2 +217,6 @@ .get('/1234/12345678910_2a37e1c3ac_o.jpg')

;
nock('https://farm9.staticflickr.com')
.get('/1234/12345678910_2a37e1c3ac_vo.mp4')
.reply(200, 'This is a video')
;

@@ -229,5 +275,11 @@ f.downloadSet('someSet', 'someUser');

for (var i = 1; i < 2; i++) {
var path = 'temp/video' + i + '.mp4';
fs.writeFileSync(path, 'Not overwritten');
}
f.on('done', function onDone() {
var ok = true;
// Photos.
for (var i = 1; i < 6; i++) {

@@ -242,2 +294,12 @@ var path = 'temp/photo' + i + '.jpg';

// Videos.
for (var i = 1; i < 2; i++) {
var path = 'temp/video' + i + '.mp4';
if (fs.readFileSync(path, 'utf8') !== 'Not overwritten') {
ok = false;
}
fs.unlinkSync(path);
}
rmDirSyncIfExists('temp');

@@ -264,2 +326,10 @@

// Size response for the video.
nock('https://api.flickr.com')
.filteringPath(/photo_id=[^&]*/g, 'photo_id=XXX')
.get('/services/rest?photo_id=XXX&nojsoncallback=1&format=json' +
'&api_key=apiKey&method=flickr.photos.getSizes')
.reply(200, fs.readFileSync('./tests/fixtures/getSizes_video_ok.json', 'utf8'))
;
nock('https://farm9.staticflickr.com')

@@ -270,2 +340,6 @@ .get('/1234/12345678910_2a37e1c3ac_o.jpg')

;
nock('https://farm9.staticflickr.com')
.get('/1234/12345678910_2a37e1c3ac_vo.mp4')
.reply(200, 'This is a video')
;

@@ -272,0 +346,0 @@ f.downloadSet('someSet', 'someUser');

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc