replace youtube duration parser function
This commit is contained in:
parent
0242f3229b
commit
1f46817721
@ -39,7 +39,7 @@
|
||||
},
|
||||
{
|
||||
"name": "urlreply",
|
||||
"version": "1.0.0"
|
||||
"version": "1.0.2"
|
||||
},
|
||||
{
|
||||
"name": "utility",
|
||||
|
@ -2,7 +2,7 @@
|
||||
"main": "plugin.js",
|
||||
"name": "urlreply",
|
||||
"description": "Fetch titles from web pages, specifically made for IRC",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"tags": ["irc"],
|
||||
"dependencies": [],
|
||||
"npmDependencies": ["cheerio@^1.0.0-rc.3"]
|
||||
|
@ -33,45 +33,24 @@ function findUrls(text: string): string[] {
|
||||
return urlArray;
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/a/22149575
|
||||
function ytDuration(source: string): string {
|
||||
const a = source.match(/\d+/g);
|
||||
let res;
|
||||
// https://gist.github.com/denniszhao/8972cd4ae637cf10fe01
|
||||
function ytDuration(time: string): string {
|
||||
const a = time.match(/\d+H|\d+M|\d+S/g);
|
||||
|
||||
if (!a) {
|
||||
return '';
|
||||
let result = 0;
|
||||
|
||||
const d: {[key: string]: number} = { H: 3600, M: 60, S: 1 };
|
||||
let num;
|
||||
let type;
|
||||
|
||||
for (const char of a || []) {
|
||||
num = char.slice(0, char.length - 1);
|
||||
type = char.slice(char.length - 1, char.length);
|
||||
|
||||
result += parseInt(num, 10) * d[type];
|
||||
}
|
||||
|
||||
if (source.indexOf('M') >= 0 && source.indexOf('H') === -1 && source.indexOf('S') === -1) {
|
||||
res = [0, a[0], 0];
|
||||
}
|
||||
|
||||
if (source.indexOf('H') >= 0 && source.indexOf('M') === -1) {
|
||||
res = [a[0], 0, a[1]];
|
||||
}
|
||||
|
||||
if (source.indexOf('H') >= 0 && source.indexOf('M') === -1 && source.indexOf('S') === -1) {
|
||||
res = [a[0], 0, 0];
|
||||
}
|
||||
|
||||
let duration = 0;
|
||||
|
||||
if (a.length === 3) {
|
||||
duration = duration + parseInt(a[0], 10) * 3600;
|
||||
duration = duration + parseInt(a[1], 10) * 60;
|
||||
duration = duration + parseInt(a[2], 10);
|
||||
}
|
||||
|
||||
if (a.length === 2) {
|
||||
duration = duration + parseInt(a[0], 10) * 60;
|
||||
duration = duration + parseInt(a[1], 10);
|
||||
}
|
||||
|
||||
if (a.length === 1) {
|
||||
duration = duration + parseInt(a[0], 10);
|
||||
}
|
||||
|
||||
return toHHMMSS(duration.toString());
|
||||
return toHHMMSS(result.toString());
|
||||
}
|
||||
|
||||
async function dailymotionFromId(id: string, msg: IMessage): Promise<boolean> {
|
||||
|
Loading…
Reference in New Issue
Block a user