Skip to content

Commit

Permalink
Fix auto-generated RTL captions position
Browse files Browse the repository at this point in the history
  • Loading branch information
absidue committed Dec 8, 2024
1 parent fd94f3e commit f3d5d86
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,8 @@ export default defineComponent({
if (url.hostname.endsWith('.youtube.com') && url.pathname === '/api/timedtext' &&
url.searchParams.get('caps') === 'asr' && url.searchParams.get('kind') === 'asr' && url.searchParams.get('fmt') === 'vtt') {
const stringBody = new TextDecoder().decode(response.data)
const cleaned = stringBody.replaceAll(/ align:start position:0%$/gm, '')
// position:0% for LTR text and position:100% for RTL text
const cleaned = stringBody.replaceAll(/ align:start position:(?:10)?0%$/gm, '')

response.data = new TextEncoder().encode(cleaned).buffer
}
Expand Down Expand Up @@ -2484,7 +2485,8 @@ export default defineComponent({
const response = await fetch(caption.url)
let text = await response.text()

text = text.replaceAll(/ align:start position:0%$/gm, '')
// position:0% for LTR text and position:100% for RTL text
text = text.replaceAll(/ align:start position:(?:10)?0%$/gm, '')

const url = `data:${caption.mimeType};charset=utf-8,${encodeURIComponent(text)}`

Expand Down

0 comments on commit f3d5d86

Please sign in to comment.