more generic youtube matcher

This commit is contained in:
Evert Prants 2022-10-04 18:51:58 +03:00
parent 9e0feffc3c
commit 51df207701
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 10 additions and 5 deletions

View File

@ -39,7 +39,7 @@
},
{
"name": "urlreply",
"version": "1.0.5"
"version": "1.0.6"
},
{
"name": "utility",

View File

@ -2,7 +2,7 @@
"main": "plugin.js",
"name": "urlreply",
"description": "Fetch titles from web pages, specifically made for IRC",
"version": "1.0.5",
"version": "1.0.6",
"tags": ["irc"],
"dependencies": [],
"npmDependencies": ["cheerio@^1.0.0-rc.10"]

View File

@ -245,7 +245,7 @@ class URLReplyPlugin extends Plugin {
htmlHandlers = [];
// YouTube
this.registerHandler(this.name, 'youtube.com/', async (url: urllib.URL, msg: IMessage, data: any) => {
this.registerHandler(this.name, '/watch\\?v=', async (url: urllib.URL, msg: IMessage, data: any) => {
const det = url.searchParams.get('v');
if (!det) {
@ -304,7 +304,7 @@ class URLReplyPlugin extends Plugin {
// Find handlers matching this URL
for (const handler in urlHandlers) {
const obj = urlHandlers[handler];
if (url.indexOf(handler) !== -1 || !obj.action) {
if (!!url.match(handler) || !obj.action) {
try {
const urlParsed = new urllib.URL(url);
@ -313,6 +313,9 @@ class URLReplyPlugin extends Plugin {
logger.error(e.stack);
matched = false;
}
}
if (matched) {
break;
}
}
@ -320,7 +323,9 @@ class URLReplyPlugin extends Plugin {
// If there were no matches, pull the title of the website
if (!matched) {
try {
const data = await httpGET(url, {}, true);
const data = await httpGET(url, {
Accept: 'text/html,application/xhtml+xml,application/xml'
}, true);
if (!data) { return; }
const full = cheerio.load(data);