mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-23 14:37:40 +09:00
Youtube support
This commit is contained in:
parent
3f2cc08607
commit
80f479f9ea
@ -9,7 +9,8 @@ require('babel-polyfill');
|
|||||||
|
|
||||||
const plugins: IPlugin[] = [
|
const plugins: IPlugin[] = [
|
||||||
require('./plugins/wikipedia'),
|
require('./plugins/wikipedia'),
|
||||||
require('./plugins/soundcloud')
|
require('./plugins/soundcloud'),
|
||||||
|
require('./plugins/youtube')
|
||||||
];
|
];
|
||||||
|
|
||||||
export default async (url: string, options?: Options): Promise<string> => {
|
export default async (url: string, options?: Options): Promise<string> => {
|
||||||
|
27
src/plugins/youtube/index.ts
Normal file
27
src/plugins/youtube/index.ts
Normal file
@ -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
src/plugins/youtube/view.pug
Normal file
1
src/plugins/youtube/view.pug
Normal file
@ -0,0 +1 @@
|
|||||||
|
iframe.youtube(src='https://www.youtube.com/embed/' + videoId, width='380', height='250', frameborder='0', allowfullscreen)
|
@ -30,6 +30,7 @@
|
|||||||
"./src/options.ts",
|
"./src/options.ts",
|
||||||
"./src/general/index.ts",
|
"./src/general/index.ts",
|
||||||
"./src/plugins/wikipedia/index.ts",
|
"./src/plugins/wikipedia/index.ts",
|
||||||
|
"./src/plugins/youtube/index.ts",
|
||||||
"./src/plugins/soundcloud/index.ts"
|
"./src/plugins/soundcloud/index.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user