diff --git a/README.md b/README.md index df6828d..a2f69d2 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ premium subscription!** ### Pending Implementation * Detect and write the appropriate video extension (instead of hard-code mp4). -* Improve SRT support for i, b and u. * Add ASS support. * Add muxing (MP4+ASS=MKV). * Add series API to download an entire series rather than per-episode. diff --git a/src/subtitle/formats/srt.js b/src/subtitle/formats/srt.js index 75e1570..3c6efc8 100644 --- a/src/subtitle/formats/srt.js +++ b/src/subtitle/formats/srt.js @@ -2,7 +2,7 @@ var xml2js = require('xml2js'); /** - * Converts an input buffer to a SRT subtitle. + * Converts an input buffer to a SubRip subtitle. * @param {Buffer|string} input * @param {function(Error, string=)} done */ @@ -62,7 +62,12 @@ function _suffix(value, length) { * @returns {string} */ function _text(text) { - return text.replace(/{[^}]+}/g, '').replace(/\\n/ig, '\n'); + return text + .replace(/{\\i1}(.+){\\i0}/g, '$1') + .replace(/{\\b1}(.+){\\b0}/g, '$1') + .replace(/{\\u1}(.+){\\u0}/g, '$1') + .replace(/{[^}]+}/g, '') + .replace(/\\n(\s+)?/ig, '\n'); } /**