attachment-detection

Attactment detection for youtube, images and links

npm install attachment-detection
12 downloads in the last week
20 downloads in the last month

Find relevant meta data from user-submitted links

Usage:

var AttachmentDetector = require('attachment-detection');
var detector = new AttachmentDetector();

detector.use(AttachmentDetector.YouTube);
detector.use(AttachmentDetector.Image);
detector.use(AttachmentDetector.Link);

Detectors are tried in the way they are used, so be sure to use the most specific ones first. Link catches all.

Each new attachment detector has its own set of handlers. When you have added some handlers to the detector, you can then pass the detector an array of string, containing one link each:

detector.detect([
  'http://www.youtube.com/watch?v=R_WHWCy48c0', 
  'http://youtu.be/R_WHWCy48c0', 
  'www.google.dk', 
  'www.test.com/image.jpg'
 ], function(attachments) {

}))

Responds with the following:

[{
  "link": "http://youtu.be/R_WHWCy48c0",
  "id": "R_WHWCy48c0",
  "type": "youtube",
  "url": "http://youtu.be/R_WHWCy48c0",
  "title": "GirlsOnDrugs - Pass the ∆",
  "description": "Location: UK\nReleased: May 2012\nGirlsOnDrugs\n(Alt -J - Breezeblocks Remix)\nhttp://soundcloud.com/girlsondrugs\nhttp://dl.dropbox.com/u/57622845/06%20Pass%20the.mp3",
  "images": [
    {
      "url": "http://i.ytimg.com/vi/R_WHWCy48c0/0.jpg",
      "height": 360,
      "width": 480
    },
    {
      "url": "http://i.ytimg.com/vi/R_WHWCy48c0/1.jpg",
      "height": 90,
      "width": 120
    },
    {
      "url": "http://i.ytimg.com/vi/R_WHWCy48c0/2.jpg",
      "height": 90,
      "width": 120
    },
    {
      "url": "http://i.ytimg.com/vi/R_WHWCy48c0/3.jpg",
      "height": 90,
      "width": 120
    }
  ]
}, {
  "link": "www.google.com",
  "type": "link",
  "url": "http://www.google.com",
  "title": "Google",
  "description": null
}, {
  "link": "www.test.com/image.jpg",
  "type": "image",
  "url": "http://www.test.com/image.jpg",
}]

Why not use og/opengraph data for everything?

For performance purposes we choose to utilize API's where available. That means we get YouTube video titles and thumbnails from the Google Data API instead of parsing the HTML.

npm loves you