Migrate ::cue code to vtt2ass
This should allow for generic styles in vtt files to be parsed and converted to an ASS file
This commit is contained in:
parent
49519f1e17
commit
becaed79d1
2 changed files with 18 additions and 15 deletions
16
hidive.ts
16
hidive.ts
|
|
@ -1317,22 +1317,8 @@ export default class Hidive implements ServiceClass {
|
|||
const getVttContent = await this.req.getData(sub.url);
|
||||
if (getVttContent.ok && getVttContent.res) {
|
||||
console.info(`Subtitle Downloaded: ${sub.url}`);
|
||||
const cssLines = [];
|
||||
const cssGroups = getVttContent.res.body.matchAll(/::cue(?:.(.+)\))?{([^}]+)}/g);
|
||||
let defaultCss = '';
|
||||
for (const cssGroup of cssGroups) {
|
||||
//Below code will bulldoze defined sizes for custom ones
|
||||
/*if (!options.originalFontSize) {
|
||||
cssGroup[2] = cssGroup[2].replace(/( font-size:.+?;)/g, '').replace(/(font-size:.+?;)/g, '');
|
||||
}*/
|
||||
if (cssGroup[1]) {
|
||||
cssLines.push(`${cssGroup[1]}{${defaultCss}${cssGroup[2]}}`);
|
||||
} else {
|
||||
defaultCss = cssGroup[2];
|
||||
}
|
||||
}
|
||||
//vttConvert(getVttContent.res.body, false, subLang.name, fontSize);
|
||||
const sBody = vtt(undefined, chosenFontSize, getVttContent.res.body, cssLines.join('\r\n'), subsMargin, options.fontName);
|
||||
const sBody = vtt(undefined, chosenFontSize, getVttContent.res.body, '', subsMargin, options.fontName);
|
||||
sxData.title = `${subLang.language} / ${sxData.title}`;
|
||||
sxData.fonts = fontsData.assFonts(sBody) as Font[];
|
||||
fs.writeFileSync(sxData.path, sBody);
|
||||
|
|
|
|||
|
|
@ -410,6 +410,23 @@ function vtt(group: string | undefined, xFontSize: number | undefined, vttStr: s
|
|||
fontSize = xFontSize && xFontSize > 0 ? xFontSize : 34; // 1em to pix
|
||||
tmMrg = timeMargin ? timeMargin : 0; //
|
||||
rFont = replaceFont ? replaceFont : rFont;
|
||||
if (vttStr.match(/::cue(?:.(.+)\))?{([^}]+)}/g)) {
|
||||
const cssLines = [];
|
||||
let defaultCss = '';
|
||||
const cssGroups = vttStr.matchAll(/::cue(?:.(.+)\))?{([^}]+)}/g);
|
||||
for (const cssGroup of cssGroups) {
|
||||
//Below code will bulldoze defined sizes for custom ones
|
||||
/*if (!options.originalFontSize) {
|
||||
cssGroup[2] = cssGroup[2].replace(/( font-size:.+?;)/g, '').replace(/(font-size:.+?;)/g, '');
|
||||
}*/
|
||||
if (cssGroup[1]) {
|
||||
cssLines.push(`${cssGroup[1]}{${defaultCss}${cssGroup[2]}}`);
|
||||
} else {
|
||||
defaultCss = cssGroup[2];
|
||||
}
|
||||
}
|
||||
cssStr += cssLines.join('\r\n');
|
||||
}
|
||||
return convert(
|
||||
loadCSS(cssStr),
|
||||
loadVTT(vttStr)
|
||||
|
|
|
|||
Loading…
Reference in a new issue