mirror of
https://github.com/misskey-dev/summaly.git
synced 2025-05-29 17:37:17 +09:00
Soundcloud support
This commit is contained in:
parent
b10db00a25
commit
3f2cc08607
@ -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> => {
|
||||||
|
28
src/plugins/soundcloud/index.ts
Normal file
28
src/plugins/soundcloud/index.ts
Normal 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"');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
@ -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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user