mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 16:11:20 -08:00
build all packages
This commit is contained in:
1 parent
da45181d18
commit
66bb5326ec
11 files changed
+57
-31
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { setStyles, srtToVtt, vttToBlob, getExt, errorHandle } from './utils';
|
||||
import { setStyles, srtToVtt, vttToBlob, getExt } from './utils';
|
||||
import assToVtt from './utils/assToVtt';
|
||||
|
||||
export default class Subtitle {
|
||||
@@ -89,19 +89,16 @@ export default class Subtitle {
|
||||
return response.text();
|
||||
})
|
||||
.then(text => {
|
||||
const type = getExt(url);
|
||||
errorHandle(['srt', 'ass', 'vtt'].includes(type), `Unsupported subtitle format: ${type}`);
|
||||
const formatText = text.replace(/{[\s\S]*?}/g, '');
|
||||
|
||||
if (type === 'srt') {
|
||||
return vttToBlob(srtToVtt(formatText));
|
||||
switch (getExt(url)) {
|
||||
case 'srt':
|
||||
return vttToBlob(srtToVtt(text));
|
||||
case 'ass':
|
||||
return vttToBlob(assToVtt(text));
|
||||
case 'vtt':
|
||||
return vttToBlob(text);
|
||||
default:
|
||||
return url;
|
||||
}
|
||||
|
||||
if (type === 'ass') {
|
||||
return vttToBlob(assToVtt(formatText));
|
||||
}
|
||||
|
||||
return vttToBlob(formatText);
|
||||
})
|
||||
.catch(err => {
|
||||
notice.show(err);
|
||||
|
||||
@@ -151,6 +151,7 @@ export function tooltip(target, msg, pos = 'up') {
|
||||
export function srtToVtt(srtText) {
|
||||
return 'WEBVTT \r\n\r\n'.concat(
|
||||
srtText
|
||||
.replace(/{[\s\S]*?}/g, '')
|
||||
.replace(/\{\\([ibu])\}/g, '</$1>')
|
||||
.replace(/\{\\([ibu])1\}/g, '<$1>')
|
||||
.replace(/\{([ibu])\}/g, '<$1>')
|
||||
|
||||
Reference in new issue
Block a user