Soundcloud support

This commit is contained in:
syuilo 2016-09-14 03:51:10 +09:00
parent b10db00a25
commit 3f2cc08607
3 changed files with 32 additions and 2 deletions

View File

@ -8,7 +8,8 @@ require('babel-core/register');
require('babel-polyfill'); require('babel-polyfill');
const plugins: IPlugin[] = [ const plugins: IPlugin[] = [
require('./plugins/wikipedia') require('./plugins/wikipedia'),
require('./plugins/soundcloud')
]; ];
export default async (url: string, options?: Options): Promise<string> => { export default async (url: string, options?: Options): Promise<string> => {

View File

@ -0,0 +1,28 @@
import * as URL from 'url';
import * as request from 'request';
import Options from '../../options';
exports.test = (url: URL.Url) => {
return url.hostname == 'soundcloud.com';
};
exports.compile = async (url: URL.Url, opts: Options) => {
request({
url: 'http://soundcloud.com/oembed',
method: 'get',
qs: {
format: 'json',
url: url.href
}
}, (err, response, body) => {
if (err) {
throw err;
} else if (response.statusCode !== 200) {
return null;
} else {
const parsed = JSON.parse(body);
const html = parsed.html;
return html.replace('height="400"', 'height="200"');
}
});
};

View File

@ -29,6 +29,7 @@
"./src/iplugin.ts", "./src/iplugin.ts",
"./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/soundcloud/index.ts"
] ]
} }