Socket
Socket
Sign inDemoInstall

open-graph-scraper

Package Overview
Dependencies
Maintainers
1
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

open-graph-scraper - npm Package Compare versions

Comparing version 2.1.0 to 2.2.0

62

app.js

@@ -6,5 +6,3 @@ var request = require('request'),

module.exports = function (options, callback) {
exports.getInfo(options, function (err, results) {
callback(err, results);
});
return exports.info(options, callback);
};

@@ -302,2 +300,28 @@

/*
* Promised info
*/
exports.info = function (options, callback) {
var that = this;
return new Promise(function (complete, reject) {
var hasCallback = typeof callback === 'function';
var done = function (error, info) {
if (error) {
if (hasCallback) {
callback(error, info);
}
return reject(error, info);
}
if (hasCallback) {
callback(error, info);
}
return complete(info);
};
that.getInfo(options, done);
});
};
/*
* get info

@@ -478,3 +502,7 @@ * @param string url - user input of url

if (ogImages.length) {
ogObject.ogImage = ogImages[0];
if (options.allMedia) {
ogObject.ogImage = ogImages;
} else {
ogObject.ogImage = ogImages[0];
}
}

@@ -484,3 +512,7 @@

if (ogVideos.length) {
ogObject.ogVideo = ogVideos[0];
if (options.allMedia) {
ogObject.ogVideo = ogVideos;
} else {
ogObject.ogVideo = ogVideos[0];
}
}

@@ -490,3 +522,7 @@

if (twitterImages.length) {
ogObject.twitterImage = twitterImages[0];
if (options.allMedia) {
ogObject.twitterImage = twitterImages;
} else {
ogObject.twitterImage = twitterImages[0];
}
}

@@ -496,3 +532,7 @@

if (twitterPlayers.length) {
ogObject.twitterPlayer = twitterPlayers[0];
if (options.allMedia) {
ogObject.twitterPlayer = twitterPlayers;
} else {
ogObject.twitterPlayer = twitterPlayers[0];
}
}

@@ -503,8 +543,8 @@

// Get title tag if og title was not provided
if (!ogObject.ogTitle && $("title").text() && $("title").text().length > 0) {
ogObject.ogTitle = $("title").text();
if (!ogObject.ogTitle && $('head > title').text() && $('head > title').text().length > 0) {
ogObject.ogTitle = $('head > title').text();
}
// Get meta description tag if og description was not provided
if (!ogObject.ogDescription && $('meta[name="description"]').attr('content') && $('meta[name="description"]').attr('content').length > 0) {
ogObject.ogDescription = $('meta[name="description"]').attr('content');
if (!ogObject.ogDescription && $('head > meta[name="description"]').attr('content') && $('head > meta[name="description"]').attr('content').length > 0) {
ogObject.ogDescription = $('head > meta[name="description"]').attr('content');
}

@@ -511,0 +551,0 @@ }

2

package.json
{
"name": "open-graph-scraper",
"description": "Node.js scraper service for Open Graph info",
"version": "2.1.0",
"version": "2.2.0",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "app.js",

@@ -31,6 +31,6 @@ openGraphScraper

Note: By default if page dose not have something like a `og:title` tag it will try and look for it in other places and return that. If you truely only want open graph info you can use the option `onlyGetOpenGraphInfo` and set it to `true`. In addition, this will also scrape twitter info!
Note: By default if page dose not have something like a `og:title` tag it will try and look for it in other places and return that. If you truely only want open graph info you can use the option `onlyGetOpenGraphInfo` and set it to `true`.
### Results JSON
Check the return for a ```success``` flag. If success is set to true, then the url input was valid. Otherwise it will be set to false. The above eample will return something like...
Check the return for a ```success``` flag. If success is set to true, then the url input was valid. Otherwise it will be set to false. The above example will return something like...
```

@@ -54,2 +54,6 @@ {

### Features
- This will also scrape twitter info!
- There is a `allMedia` flag you can set to `true` if you want all the images/videos send back.
### Tests

@@ -56,0 +60,0 @@ You have to have mocha running. To install it run...

@@ -80,3 +80,3 @@ var app = require('../app'),

'url': 'https://twitter.com/'
}
};

@@ -86,4 +86,10 @@ // testing 304 page

'url': 'http://www.wemeanbusinesslondon.com/blog/2016/5/10/the-entrepreneur-spiration-series-going-nuts-for-pip-nut'
}
};
// testing all media
var options19 = {
'url': 'http://ogp.me',
'allMedia': true
};
// test videos

@@ -94,3 +100,3 @@ var optionsYoutube = {

optionsTwitch = {
'url': 'https://www.twitch.tv/battlefield/v/64886482'
'url': 'https://www.twitch.tv/warcraft/v/78039967'
};

@@ -278,2 +284,13 @@

});
it('Valid Call - should contain array of images', function (done) {
app(options19, function (err, result) {
expect(err).to.be(false);
expect(result.success).to.be(true);
expect(result.data.ogImage[0].url).to.be('http://ogp.me/logo.png');
expect(result.data.ogImage[0].width).to.be('300');
expect(result.data.ogImage[0].height).to.be('300');
expect(result.data.ogImage[0].type).to.be('image/png');
done();
});
});
it('Valid Call - Test Youtube Video - Should Return correct Open Graph Info', function (done) {

@@ -286,3 +303,3 @@ app(optionsYoutube, function (err, result) {

expect(result.data.ogUrl).to.be('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
expect(result.data.ogDescription).to.be('Music video by Rick Astley performing Never Gonna Give You Up. YouTube view counts pre-VEVO: 2,573,462 (C) 1987 PWL');
expect(result.data.ogDescription).to.be('Rick Astley - Never Gonna Give You Up (Official Music Video) Listen On Spotify: http://smarturl.it/AstleySpotify Buy On iTunes: http://smarturl.it/AstleyGHiT...');
expect(result.data.ogType).to.be('video');

@@ -292,4 +309,4 @@ expect(result.data.ogImage.url).to.be('https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg');

expect(result.data.ogVideo.type).to.be('text/html');
expect(result.data.ogVideo.width).to.be('480');
expect(result.data.ogVideo.height).to.be('360');
expect(result.data.ogVideo.width).to.be('1280');
expect(result.data.ogVideo.height).to.be('720');
done();

@@ -305,4 +322,4 @@ });

expect(result.data.ogType).to.be('video.other');
expect(result.data.ogImage.url).to.be('https://static-cdn.jtvnw.net/v1/AUTH_system/vods_6fbe/battlefield_21175918848_448240534/thumb/customabc4420a66bb33bd-480x320.jpg');
expect(result.data.ogVideo.url).to.be('http://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?videoId=v64886482&playerType=facebook');
expect(result.data.ogImage.url).to.be('https://static-cdn.jtvnw.net/v1/AUTH_system/vods_1138/warcraft_22339636096_485121236/thumb/thumb0-480x320.jpg');
expect(result.data.ogVideo.url).to.be('http://www-cdn.jtvnw.net/swflibs/TwitchPlayer.swf?videoId=v78039967&playerType=facebook');
expect(result.data.ogVideo.type).to.be('application/x-shockwave-flash');

@@ -318,3 +335,3 @@ expect(result.data.ogVideo.width).to.be('620');

expect(result.success).to.be(true);
expect(result.data.ogSiteName).to.be('Flickr - Photo Sharing!');
expect(result.data.ogSiteName).to.be('Flickr');
expect(result.data.ogTitle).to.be('Heimgarten');

@@ -321,0 +338,0 @@ expect(result.data.ogUrl).to.be('https://www.flickr.com/photos/travelgraph/18791678505/');

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc