2024-09-11 03:16:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
2024-09-11 03:16:56 +00:00
|
|
|
const UrlPattern = require('url-pattern');
|
2024-09-11 03:16:53 +00:00
|
|
|
|
|
|
|
const hosts = [{
|
2024-09-11 03:16:53 +00:00
|
|
|
method: 'self',
|
2024-09-11 03:16:53 +00:00
|
|
|
label: 'self',
|
2024-09-11 03:16:56 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)reddit.com/r/:subreddit/comments/:id/:uri/'),
|
2024-09-11 03:16:53 +00:00
|
|
|
}, {
|
2024-09-11 03:16:54 +00:00
|
|
|
method: 'redditImage',
|
2024-09-11 03:16:53 +00:00
|
|
|
label: 'reddit',
|
2024-09-11 03:16:57 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://i.redd.it/:id.:ext(?*)'),
|
2024-09-11 03:16:53 +00:00
|
|
|
}, {
|
2024-09-11 03:16:54 +00:00
|
|
|
method: 'redditImage',
|
2024-09-11 03:16:53 +00:00
|
|
|
label: 'reddit',
|
2024-09-11 03:16:56 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://i.reddituploads.com/:id(?*)'),
|
2024-09-11 03:16:54 +00:00
|
|
|
}, {
|
|
|
|
method: 'redditVideo',
|
|
|
|
label: 'reddit',
|
2024-09-11 03:16:57 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://v.redd.it/:id(?*)'),
|
2024-09-11 03:16:53 +00:00
|
|
|
}, {
|
2024-09-11 03:16:53 +00:00
|
|
|
method: 'imgurImage',
|
2024-09-11 03:16:53 +00:00
|
|
|
label: 'imgur',
|
2024-09-11 03:16:56 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://(:subdomain.)imgur.com/(:id_d)(:id)(.:ext)(?*)'),
|
2024-09-11 03:16:53 +00:00
|
|
|
}, {
|
|
|
|
method: 'imgurAlbum',
|
2024-09-11 03:16:53 +00:00
|
|
|
label: 'imgur',
|
2024-09-11 03:16:57 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id(#:focus)(?*)'),
|
2024-09-11 03:16:55 +00:00
|
|
|
}, {
|
|
|
|
method: 'vidbleImage',
|
|
|
|
label: 'vidble',
|
2024-09-11 03:16:57 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)vidble.com/(show/):id(.:ext)(?*)'),
|
2024-09-11 03:16:55 +00:00
|
|
|
}, {
|
|
|
|
method: 'vidbleVideo',
|
|
|
|
label: 'vidble',
|
2024-09-11 03:16:57 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)vidble.com/watch?v=:id(?*)'),
|
2024-09-11 03:16:55 +00:00
|
|
|
}, {
|
|
|
|
method: 'vidbleAlbum',
|
|
|
|
label: 'vidble',
|
2024-09-11 03:16:57 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)vidble.com/album/:id(?*)'),
|
2024-09-11 03:16:55 +00:00
|
|
|
}, {
|
|
|
|
method: 'gfycat',
|
|
|
|
label: 'gfycat',
|
2024-09-11 03:16:57 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://(:server.)gfycat.com/(gifs/detail/)(:id-mobile)(:id-size_restricted)(:id)(.:ext)(?*)'),
|
2024-09-11 03:16:57 +00:00
|
|
|
}, {
|
|
|
|
method: 'erome',
|
|
|
|
label: 'erome',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)erome.com/a/:id(?*)'),
|
2024-09-11 03:16:53 +00:00
|
|
|
}, {
|
2024-09-11 03:16:55 +00:00
|
|
|
method: 'eroshareAlbum',
|
2024-09-11 03:16:53 +00:00
|
|
|
label: 'eroshare',
|
2024-09-11 03:16:56 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://eroshare.com/:id(#)(:query)'),
|
2024-09-11 03:16:55 +00:00
|
|
|
}, {
|
|
|
|
method: 'eroshareItem',
|
|
|
|
label: 'eroshare',
|
2024-09-11 03:16:56 +00:00
|
|
|
pattern: new UrlPattern('http(s)\\://eroshare.com/i/:id(#)(:query)'),
|
2024-09-11 03:16:57 +00:00
|
|
|
}, {
|
|
|
|
method: 'pornhub',
|
|
|
|
label: 'pornhub',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)pornhub.com/view_video.php?viewkey=(:id)(?*)'),
|
2024-09-11 03:16:53 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
module.exports = function dissectLink(url) {
|
|
|
|
return hosts.reduce((acc, host) => {
|
2024-09-11 03:16:56 +00:00
|
|
|
if (acc) {
|
2024-09-11 03:16:53 +00:00
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
2024-09-11 03:16:55 +00:00
|
|
|
const match = host.pattern.match(url.replace(/(https?:\/\/)|(\/)+/g, '$1$2')); // remove double slashes
|
2024-09-11 03:16:53 +00:00
|
|
|
|
2024-09-11 03:16:56 +00:00
|
|
|
if (match) {
|
2024-09-11 03:16:53 +00:00
|
|
|
return Object.assign(match, {
|
2024-09-11 03:16:56 +00:00
|
|
|
url,
|
2024-09-11 03:16:53 +00:00
|
|
|
method: host.method,
|
2024-09-11 03:16:56 +00:00
|
|
|
label: host.label,
|
2024-09-11 03:16:53 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}, null);
|
|
|
|
};
|