diff --git a/api/video.js b/api/video.js index c0a2895..2a73546 100644 --- a/api/video.js +++ b/api/video.js @@ -45,14 +45,29 @@ function rewriteVideoDescription(descriptionHtml, id) { // https://www.youtube.com/watch?v=fhum63fAwrI www.youtube.com/watch?v= // https://www.youtube.com/watch?v=i-szWOrc3Mo www.youtube.com/ (unsupported by cloudtube currently) // https://www.youtube.com/watch?v=LSG71wbKpbQ www.youtube.com/channel/ - descriptionHtml = descriptionHtml.replace(new RegExp(`([^<]+)<\/a>`, "g"), `$4`) - descriptionHtml = descriptionHtml.replace(new RegExp(`([^<]+)<\/a>`, "g"), `$4`) - descriptionHtml = descriptionHtml.replace(new RegExp(`(?:([0-5]?[0-9]):)?([0-5]?[0-9]):([0-5][0-9])`, "g"), function(match, p1, p2, p3, offset, string){ - if (p1 === undefined) { - return `${p2}:${p3}` + + descriptionHtml = descriptionHtml.replace(new RegExp(`([^<]+)`, "g"), `$3`) + descriptionHtml = descriptionHtml.replace(new RegExp(`([^<]+)<\/a>`, "g"), `$2`) + descriptionHtml = descriptionHtml.replace(new RegExp(`(?:([0-9]*):)?([0-5]?[0-9]):([0-5][0-9])`, "g"), (_, hours, minutes, seconds) => { + let timeURL, timeDisplay, timeSeconds + if (hours === undefined) { + timeURL = `${minutes}m${seconds}s` + timeDisplay = `${minutes}:${seconds}` + timeSeconds = minutes*60 + + seconds + } else { + timeURL = `${hours}h${minutes}m${seconds}s` + timeDisplay = `${hours}:${minutes}:${seconds}` + timeSeconds = hours*60*60 + minutes*60 + + seconds } - return `${p1}:${p2}:${p3}` + + const params = new URLSearchParams() + params.set("v", id) + params.set("t", timeURL) + const url = "/watch?" + params + + return pug.render(`a(href=url data-clickable-timestamp=timeSeconds)= timeDisplay`, {url, timeURL, timeDisplay, timeSeconds}) }) + return descriptionHtml }