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