Skip to content

Commit d742825

Browse files
committed
[amazon subs] fix Arabic subs
1 parent 875f29c commit d742825

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Amazon_Video_-_subtitle_downloader.user.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @name Amazon Video - subtitle downloader
33
// @description Allows you to download subtitles from Amazon Video
44
// @license MIT
5-
// @version 1.7.0
5+
// @version 1.7.1
66
// @namespace tithen-firion.github.io
77
// @include /^https:\/\/www\.amazon\.com\/(gp\/(video|product)|(.*?\/)?dp)\/.+/
88
// @include /^https:\/\/www\.amazon\.de\/(gp\/(video|product)|(.*?\/)?dp)\/.+/
@@ -70,7 +70,7 @@ s.innerHTML = 'p.download:hover { cursor:pointer }';
7070
document.head.appendChild(s);
7171

7272
// XML to SRT
73-
function xmlToSrt(xmlString) {
73+
function xmlToSrt(xmlString, lang) {
7474
xmlString = xmlString.replace(/<tt:br\/>/gi, '\n');
7575
try {
7676
let parser = new DOMParser();
@@ -87,6 +87,9 @@ function xmlToSrt(xmlString) {
8787
for(let i=0, l=lines.length; i < l; ++i) {
8888
let text = lines[i].innerHTML.trim();
8989
if(text != '') {
90+
if(lang.indexOf('ar') == 0)
91+
text = text.replace(/^(?!\u202B|\u200F)/gm, '\u202B');
92+
9093
srtLines.push(i+1);
9194
srtLines.push(lines[i].getAttribute('begin').replace('.',',') + ' --> ' + lines[i].getAttribute('end').replace('.',','));
9295
srtLines.push(text);
@@ -97,12 +100,12 @@ function xmlToSrt(xmlString) {
97100
}
98101

99102
// download subs and save them
100-
function downloadSubs(url, title, downloadVars) {
103+
function downloadSubs(url, title, downloadVars, lang) {
101104
var req = new XMLHttpRequest();
102105
req.open('get', url);
103106
req.onload = function() {
104107
progressBar.increment();
105-
var srt = xmlToSrt(req.response);
108+
var srt = xmlToSrt(req.response, lang);
106109
if(downloadVars) {
107110
downloadVars.zip.file(title, srt);
108111
--downloadVars.subCounter;
@@ -169,7 +172,7 @@ function downloadInfo(url, downloadVars) {
169172
if(downloadVars)
170173
++downloadVars.subCounter;
171174
progressBar.incrementMax();
172-
downloadSubs(subInfo.url, title + lang + '.srt', downloadVars);
175+
downloadSubs(subInfo.url, title + lang + '.srt', downloadVars, lang);
173176
});
174177
if(downloadVars)
175178
--downloadVars.infoCounter;

0 commit comments

Comments
 (0)