Skip to content

Commit

Permalink
Merge pull request #50 from ndaidong/dev
Browse files Browse the repository at this point in the history
Update README
  • Loading branch information
ndaidong authored Jul 14, 2017
2 parents 96a90f1 + f38d6f7 commit ed83db4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ Extract main article, main image and meta data from URL.
[![Dependency Status](https://gemnasium.com/badges/github.com/ndaidong/article-parser.svg)](https://gemnasium.com/github.com/ndaidong/article-parser)
[![NSP Status](https://nodesecurity.io/orgs/techpush/projects/d965e951-5bc6-41d3-90da-81e2a3b7e40f/badge)](https://nodesecurity.io/orgs/techpush/projects/d965e951-5bc6-41d3-90da-81e2a3b7e40f)

### Installation
### Usage

```
npm install article-parser
```

### Usage
Then:

```
var {
Expand All @@ -31,10 +31,10 @@ extract(url).then((article) => {

### APIs

- configure(Object conf)
- extract(String url)
- parseWithEmbedly(String url [, String EmbedlyKey])
- getConfig()
- [configure(Object conf)](#configureobject-conf)
- [extract(String url)](#extractstring-url)
- [parseWithEmbedly(String url [, String EmbedlyKey])](#parsewithembedlystring-url--string-embedlykey)
- [getConfig()](#getconfig)


#### configure(Object conf)
Expand Down
12 changes: 10 additions & 2 deletions src/parsers/extensions/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ var parser = {
],
extract: (url) => {
return new Promise((resolve, reject) => {

let vid = getYtid(url);

if (!vid) {
throw new Error('No video ID found');
}

url = `https://www.youtube.com/watch?v=${vid}`;

return extract(url).then((data) => {

let vid = getYtid(url);
return {
vid,
title: data.title,
canonicals: [
`https://www.youtube.com/watch?v=${vid}`,
url,
`https://youtu.be/${vid}`,
`https://www.youtube.com/v/${vid}`,
`https://www.youtube.com/embed/${vid}`
Expand Down
8 changes: 8 additions & 0 deletions test/specs/extensions/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,12 @@ var hasRequiredKeys = (o) => {
});
});

let badurl = 'https://www.youtube.com/watch?v=';

test(`Testing with .extract('${badurl}')`, (t) => {
extract(badurl).catch((e) => {
let msg = `No video ID found`;
t.equals(e.message, msg, 'It must return an error.');
}).finally(t.end);
});
})();

0 comments on commit ed83db4

Please sign in to comment.