2018-04-15 02:51:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-07-05 21:27:11 +00:00
|
|
|
const UrlPattern = require('url-pattern');
|
2018-04-15 02:51:02 +00:00
|
|
|
|
2019-11-12 02:38:26 +00:00
|
|
|
const hosts = [
|
|
|
|
{
|
|
|
|
method: 'self',
|
|
|
|
label: 'self',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)reddit.com/r/:subreddit/comments/:id/:uri/'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'redditImage',
|
|
|
|
label: 'reddit',
|
|
|
|
pattern: new UrlPattern('http(s)\\://i.redd.it/:id.:ext(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'redditImage',
|
|
|
|
label: 'reddit',
|
|
|
|
pattern: new UrlPattern('http(s)\\://i.reddituploads.com/:id(?*)'),
|
|
|
|
},
|
2021-12-17 01:04:25 +00:00
|
|
|
{
|
|
|
|
method: 'redditAlbum',
|
|
|
|
label: 'reddit',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)reddit.com/gallery/:id'),
|
|
|
|
},
|
2019-11-12 02:38:26 +00:00
|
|
|
{
|
|
|
|
method: 'redditVideo',
|
|
|
|
label: 'reddit',
|
|
|
|
pattern: new UrlPattern('http(s)\\://v.redd.it/:id(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'imgurImage',
|
|
|
|
label: 'imgur',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(:subdomain.)imgur.com/(:id_d)(:id)(.:ext)(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'imgurAlbum',
|
|
|
|
label: 'imgur',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(:subdomain.)imgur.com/:type/:id(#:focus)(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'vidbleImage',
|
|
|
|
label: 'vidble',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)vidble.com/(show/):id(.:ext)(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'vidbleVideo',
|
|
|
|
label: 'vidble',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)vidble.com/watch?v=:id(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'vidbleAlbum',
|
|
|
|
label: 'vidble',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)vidble.com/album/:id(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'gfycat',
|
|
|
|
label: 'gfycat',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(:server.)gfycat.com/(gifs/detail/)(:id-mobile)(:id-size_restricted)(:id)(.:ext)(?*)'),
|
|
|
|
},
|
2021-12-17 01:04:25 +00:00
|
|
|
{
|
|
|
|
method: 'redgifs',
|
|
|
|
label: 'redgifs',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(:subdomain.)redgifs.com(/watch)/(:id-mobile)(:id)(.:ext)(?*)'),
|
|
|
|
},
|
2019-11-12 02:38:26 +00:00
|
|
|
{
|
|
|
|
method: 'erome',
|
|
|
|
label: 'erome',
|
|
|
|
pattern: new UrlPattern('http(s)\\://(www.)erome.com/a/:id(?*)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'eroshareAlbum',
|
|
|
|
label: 'eroshare',
|
|
|
|
pattern: new UrlPattern('http(s)\\://eroshare.com/:id(#)(:query)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
method: 'eroshareItem',
|
|
|
|
label: 'eroshare',
|
|
|
|
pattern: new UrlPattern('http(s)\\://eroshare.com/i/:id(#)(:query)'),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
const fallbacks = new Set([
|
|
|
|
'bbc',
|
|
|
|
'biqle',
|
|
|
|
'buzzfeed',
|
|
|
|
'chaturbate',
|
|
|
|
'dailymotion',
|
|
|
|
'eporner',
|
|
|
|
'instagram',
|
|
|
|
'keezmovies',
|
|
|
|
'liveleak',
|
|
|
|
'mixcloud',
|
|
|
|
'pornhd',
|
|
|
|
'pornhub',
|
|
|
|
'redtube',
|
|
|
|
'soundcloud',
|
|
|
|
'soundgasm',
|
|
|
|
'spankbang',
|
|
|
|
'spankwire',
|
|
|
|
'streamable',
|
|
|
|
'tiktok',
|
|
|
|
'tube8',
|
|
|
|
'tweakers',
|
|
|
|
'twitch',
|
|
|
|
'twitter',
|
|
|
|
'vimeo',
|
|
|
|
'xhamster',
|
|
|
|
'xnxx',
|
|
|
|
'youjizz',
|
|
|
|
'youporn',
|
|
|
|
'youtube',
|
|
|
|
]);
|
2018-04-15 02:51:02 +00:00
|
|
|
|
|
|
|
module.exports = function dissectLink(url) {
|
2019-11-12 02:38:26 +00:00
|
|
|
const hostMethod = hosts.reduce((acc, host) => {
|
2018-07-05 21:27:11 +00:00
|
|
|
if (acc) {
|
2018-04-15 02:51:02 +00:00
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
2018-06-09 23:34:28 +00:00
|
|
|
const match = host.pattern.match(url.replace(/(https?:\/\/)|(\/)+/g, '$1$2')); // remove double slashes
|
2018-04-15 02:51:02 +00:00
|
|
|
|
2018-07-05 21:27:11 +00:00
|
|
|
if (match) {
|
2018-04-15 02:51:02 +00:00
|
|
|
return Object.assign(match, {
|
2018-07-05 21:27:11 +00:00
|
|
|
url,
|
2018-04-20 02:40:37 +00:00
|
|
|
method: host.method,
|
2018-07-05 21:27:11 +00:00
|
|
|
label: host.label,
|
2018-04-15 02:51:02 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}, null);
|
2019-11-12 02:38:26 +00:00
|
|
|
|
|
|
|
if (hostMethod) {
|
|
|
|
return hostMethod;
|
|
|
|
}
|
|
|
|
|
2019-12-22 02:20:24 +00:00
|
|
|
const match = new UrlPattern('http(s)\\://(www.):hostname(*)').match(url);
|
2019-11-12 02:38:26 +00:00
|
|
|
|
2019-12-22 02:20:24 +00:00
|
|
|
if (match) {
|
|
|
|
const { hostname } = match;
|
|
|
|
|
|
|
|
if (hostname && fallbacks.has(hostname)) {
|
|
|
|
return {
|
|
|
|
url,
|
|
|
|
method: 'tube',
|
|
|
|
label: hostname,
|
|
|
|
};
|
|
|
|
}
|
2019-11-12 02:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2018-04-15 02:51:02 +00:00
|
|
|
};
|