Skip to content

Commit

Permalink
Youtube support
Browse files Browse the repository at this point in the history
  • Loading branch information
syuilo committed Sep 14, 2016
1 parent 3f2cc08 commit 80f479f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ require('babel-polyfill');

const plugins: IPlugin[] = [
require('./plugins/wikipedia'),
require('./plugins/soundcloud')
require('./plugins/soundcloud'),
require('./plugins/youtube')
];

export default async (url: string, options?: Options): Promise<string> => {
Expand Down
27 changes: 27 additions & 0 deletions src/plugins/youtube/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as URL from 'url';
const pug = require('pug');
import Options from '../../options';

exports.test = (url: URL.Url) =>
url.hostname == 'youtube.com' ||
url.hostname == 'www.youtube.com' ||
url.hostname == 'youtu.be'
;

exports.compile = async (url: URL.Url, opts: Options) => {
let videoId: string;

switch (url.hostname) {
case 'www.youtube.com':
case 'youtube.com':
videoId = url.query.v;
break;
case 'youtu.be':
videoId = url.pathname;
break;
}

return pug.renderFile(`${__dirname}/view.pug`, {
videoId
});
};
1 change: 1 addition & 0 deletions src/plugins/youtube/view.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
iframe.youtube(src='https://www.youtube.com/embed/' + videoId, width='380', height='250', frameborder='0', allowfullscreen)
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"./src/options.ts",
"./src/general/index.ts",
"./src/plugins/wikipedia/index.ts",
"./src/plugins/youtube/index.ts",
"./src/plugins/soundcloud/index.ts"
]
}

0 comments on commit 80f479f

Please sign in to comment.