| 1 | /***************************************************************************** |
| 2 | ** QNapi |
| 3 | ** Copyright (C) 2008-2017 Piotr KrzemiĆski <[email protected]> |
| 4 | ** |
| 5 | ** This program is free software; you can redistribute it and/or modify |
| 6 | ** it under the terms of the GNU General Public License as published by |
| 7 | ** the Free Software Foundation; either version 2 of the License, or |
| 8 | ** (at your option) any later version. |
| 9 | ** |
| 10 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
| 11 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | ** |
| 13 | *****************************************************************************/ |
| 14 | |
| 15 | #include "subrip.h"cxx . . $ `<file>/libqnapi/src/subconvert/formats/subrip.h`/ |
| 16 | |
| 17 | bool SubRipSubtitleFormatcxx . . $ SubRipSubtitleFormat#::detectcxx . . $ SubRipSubtitleFormat#detect(5f1b03c390062051).(const QStringListcxx . . $ QStringList# &lines) const { |
| 18 | QStringListcxx . . $ QStringList# lines2 = lines; |
| 19 | while (!lines2.isEmptycxx . . $ QList#isEmpty(50ce9a9e25b4a850).() && lines2.firstcxx . . $ QList#first(19b2b6f17af048b).().trimmedcxx . . $ QString#trimmed(dca2c5857e9adf82).().isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 20 | lines2.pop_frontcxx . . $ QList#pop_front(49f6e7a06ebc5aa8).(); |
| 21 | } |
| 22 | |
| 23 | QStringcxx . . $ QString# firstEntryBuffcxx . . $ QString#QString(49f6e7a06ebc5aa8).; |
| 24 | |
| 25 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (QString line, lines2) { |
| 26 | if (line.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) break; |
| 27 | firstEntryBuff +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). line +cxx . . $ operator+(3d22f08efddf8107). "\n"; |
| 28 | } |
| 29 | |
| 30 | QRegExpcxx . . $ QRegExp# rcxx . . $ QRegExp#QRegExp(31e086911ff70bd0).( |
| 31 | "^(\\d+)(\\n|\\r\\n|\\s+)(\\d{2}):(\\d{2}):(\\d{2})\\,(\\d{3})\\s+\\-\\->"cxx . . $ QString#QString(85c52e162fed56f9). |
| 32 | "\\s+(\\d{2}):(\\d{2}):(\\d{2})\\,(\\d{3})(.*)"); |
| 33 | |
| 34 | return r.exactMatchcxx . . $ QRegExp#exactMatch(f3b39adf77d9c36c).(firstEntryBuff); |
| 35 | } |
| 36 | |
| 37 | SubFilecxx . . $ SubFile# SubRipSubtitleFormatcxx . . $ SubRipSubtitleFormat#::decodecxx . . $ SubRipSubtitleFormat#decode(a10217bac3d52496).(const QStringListcxx . . $ QStringList# &lines) const { |
| 38 | SubFilecxx . . $ SubFile# sf; |
| 39 | |
| 40 | QRegExpcxx . . $ QRegExp# r1cxx . . $ QRegExp#QRegExp(31e086911ff70bd0).( |
| 41 | "^(\\d+)\\s+(\\d{2}):(\\d{2}):(\\d{2})\\,(\\d{3})\\s+\\-\\->\\s+(\\d{2}):"cxx . . $ QString#QString(85c52e162fed56f9). |
| 42 | "(\\d{2}):(\\d{2})\\,(\\d{3})(.*)"); |
| 43 | QRegExpcxx . . $ QRegExp# r2cxx . . $ QRegExp#QRegExp(31e086911ff70bd0).( |
| 44 | "^(\\d{2}):(\\d{2}):(\\d{2})\\,(\\d{3})\\s+\\-\\->\\s+(\\d{2}):(\\d{2}):("cxx . . $ QString#QString(85c52e162fed56f9). |
| 45 | "\\d{2})\\,(\\d{3})(.*)"); |
| 46 | QRegExpcxx . . $ QRegExp# rNumLinecxx . . $ QRegExp#QRegExp(31e086911ff70bd0).("^\\d+"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 47 | |
| 48 | QStringcxx . . $ QString# tokensBuffcxx . . $ QString#QString(e1217c004a86c950). = ""cxx . . $ QString#QString(85c52e162fed56f9)., numsBuffcxx . . $ QString#QString(49f6e7a06ebc5aa8).; |
| 49 | SrtTimestampscxx . . $ SubRipSubtitleFormat#SrtTimestamps# tss; |
| 50 | |
| 51 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (QString line, lines) { |
| 52 | if (r1.exactMatchcxx . . $ QRegExp#exactMatch(f3b39adf77d9c36c).(line)) { |
| 53 | if (!tokensBuff.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) addEntrycxx . . $ SubRipSubtitleFormat#addEntry(4c75c4ed8f6fa44c).(sf.entriescxx . . $ SubFile#entries., tokensBuff, tss); |
| 54 | tss.h1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#h1. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(2).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 55 | tss.m1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#m1. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(3).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 56 | tss.s1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#s1. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(4).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 57 | tss.ms1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#ms1. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(5).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 58 | tss.h2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#h2. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(6).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 59 | tss.m2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#m2. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(7).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 60 | tss.s2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#s2. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(8).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 61 | tss.ms2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#ms2. = r1.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(9).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 62 | numsBuff.clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 63 | } else if (r2.exactMatchcxx . . $ QRegExp#exactMatch(f3b39adf77d9c36c).(line)) { |
| 64 | if (!tokensBuff.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) addEntrycxx . . $ SubRipSubtitleFormat#addEntry(4c75c4ed8f6fa44c).(sf.entriescxx . . $ SubFile#entries., tokensBuff, tss); |
| 65 | tss.h1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#h1. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(1).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 66 | tss.m1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#m1. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(2).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 67 | tss.s1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#s1. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(3).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 68 | tss.ms1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#ms1. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(4).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 69 | tss.h2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#h2. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(5).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 70 | tss.m2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#m2. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(6).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 71 | tss.s2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#s2. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(7).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 72 | tss.ms2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#ms2. = r2.capcxx . . $ QRegExp#cap(ce915ed341d4a7f0).(8).toIntcxx . . $ QString#toInt(d7972accae11ee1f).(); |
| 73 | numsBuff.clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 74 | } else if (rNumLine.exactMatchcxx . . $ QRegExp#exactMatch(f3b39adf77d9c36c).(line)) { |
| 75 | numsBuff +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). line +cxx . . $ operator+(3d22f08efddf8107). "\n"; |
| 76 | } else if (!line.trimmedcxx . . $ QString#trimmed(dca2c5857e9adf82).().isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 77 | if (!numsBuff.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) { |
| 78 | tokensBuff +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). numsBuff; |
| 79 | numsBuff.clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 80 | } |
| 81 | tokensBuff +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). line +cxx . . $ operator+(3d22f08efddf8107). "\n"; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if (!tokensBuff.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) addEntrycxx . . $ SubRipSubtitleFormat#addEntry(4c75c4ed8f6fa44c).(sf.entriescxx . . $ SubFile#entries., tokensBuff, tss); |
| 86 | |
| 87 | return sf; |
| 88 | } |
| 89 | |
| 90 | QStringListcxx . . $ QStringList# SubRipSubtitleFormatcxx . . $ SubRipSubtitleFormat#::encodecxx . . $ SubRipSubtitleFormat#encode(547b88c4cc907c03).(const SubFilecxx . . $ SubFile# &subFile) const { |
| 91 | QStringListcxx . . $ QStringList# linescxx . . $ QStringList#QStringList(49f6e7a06ebc5aa8).; |
| 92 | int i = 1; |
| 93 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const SubEntry &entry, subFile.entries) { |
| 94 | lines <<cxx . . $ QStringList#`operator<<`(cb3c3d1614140851). encodeEntrycxx . . $ SubRipSubtitleFormat#encodeEntry(8675cc85dc16d75d).(entry, i++); |
| 95 | lines <<cxx . . $ QStringList#`operator<<`(85116071a693d053). ""cxx . . $ QString#QString(85c52e162fed56f9).; |
| 96 | } |
| 97 | return lines; |
| 98 | } |
| 99 | |
| 100 | void SubRipSubtitleFormatcxx . . $ SubRipSubtitleFormat#::addEntrycxx . . $ SubRipSubtitleFormat#addEntry(4c75c4ed8f6fa44c).(QVectorcxx . . $ QVector#<SubEntrycxx . . $ SubEntry#> &entries, |
| 101 | QStringcxx . . $ QString# &tokensBuff, |
| 102 | SrtTimestampscxx . . $ SubRipSubtitleFormat#SrtTimestamps# ×tamps) const { |
| 103 | SubEntrycxx . . $ SubEntry# se; |
| 104 | se.frameStartcxx . . $ SubEntry#frameStart. = 3600000L * timestamps.h1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#h1. + 60000L * timestamps.m1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#m1. + |
| 105 | 1000L * timestamps.s1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#s1. + timestamps.ms1cxx . . $ SubRipSubtitleFormat#SrtTimestamps#ms1.; |
| 106 | se.frameStopcxx . . $ SubEntry#frameStop. = 3600000L * timestamps.h2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#h2. + 60000L * timestamps.m2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#m2. + |
| 107 | 1000L * timestamps.s2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#s2. + timestamps.ms2cxx . . $ SubRipSubtitleFormat#SrtTimestamps#ms2.; |
| 108 | se.tokenscxx . . $ SubEntry#tokens. =cxx . . $ QVector#`operator=`(a1d068f9d22786ee). decodeTokenStreamcxx . . $ SubtitleFormat#decodeTokenStream(8709a708f98d071b).(tokensBuffcxx . . $ QString#QString(3520e46b33348bf6).); |
| 109 | |
| 110 | while (!se.tokenscxx . . $ SubEntry#tokens..isEmptycxx . . $ QVector#isEmpty(50ce9a9e25b4a850).() && se.tokenscxx . . $ SubEntry#tokens..backcxx . . $ QVector#back(19b2b6f17af048b).().typecxx . . $ SubToken#type. == STT_NEWLINEcxx . . $ STT_NEWLINE.) |
| 111 | se.tokenscxx . . $ SubEntry#tokens..pop_backcxx . . $ QVector#pop_back(49f6e7a06ebc5aa8).(); |
| 112 | |
| 113 | entries.push_backcxx . . $ QVector#push_back(77d9f17553126ecb).(se); |
| 114 | tokensBuff.clearcxx . . $ QString#clear(49f6e7a06ebc5aa8).(); |
| 115 | } |
| 116 | |
| 117 | QStringListcxx . . $ QStringList# SubRipSubtitleFormatcxx . . $ SubRipSubtitleFormat#::encodeEntrycxx . . $ SubRipSubtitleFormat#encodeEntry(8675cc85dc16d75d).(const SubEntrycxx . . $ SubEntry# &entry, |
| 118 | int i) const { |
| 119 | QStringcxx . . $ QString# tokensBuffcxx . . $ QString#QString(49f6e7a06ebc5aa8).; |
| 120 | foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`! (const SubToken &token, entry.tokens) { |
| 121 | tokensBuff +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). encodeTokencxx . . $ SubRipSubtitleFormat#encodeToken(a468b8cbbcf05ae6).(token); |
| 122 | } |
| 123 | |
| 124 | int h1 = entry.frameStartcxx . . $ SubEntry#frameStart. / 3600000; |
| 125 | int m1 = (entry.frameStartcxx . . $ SubEntry#frameStart. - h1 * 3600000) / 60000; |
| 126 | int s1 = (entry.frameStartcxx . . $ SubEntry#frameStart. - h1 * 3600000 - m1 * 60000) / 1000; |
| 127 | int ms1 = entry.frameStartcxx . . $ SubEntry#frameStart. - h1 * 3600000 - m1 * 60000 - s1 * 1000; |
| 128 | |
| 129 | int h2 = entry.frameStopcxx . . $ SubEntry#frameStop. / 3600000; |
| 130 | int m2 = (entry.frameStopcxx . . $ SubEntry#frameStop. - h2 * 3600000) / 60000; |
| 131 | int s2 = (entry.frameStopcxx . . $ SubEntry#frameStop. - h2 * 3600000 - m2 * 60000) / 1000; |
| 132 | int ms2 = entry.frameStopcxx . . $ SubEntry#frameStop. - h2 * 3600000 - m2 * 60000 - s2 * 1000; |
| 133 | |
| 134 | QStringListcxx . . $ QStringList# outcxx . . $ QStringList#QStringList(49f6e7a06ebc5aa8).; |
| 135 | out <<cxx . . $ QStringList#`operator<<`(85116071a693d053). QStringcxx . . $ QString#::numbercxx . . $ QString#number(f4fd9db251ca774b).(i) |
| 136 | <<cxx . . $ QStringList#`operator<<`(85116071a693d053). QStringcxx . . $ QString#QString(85c52e162fed56f9).("%1:%2:%3,%4 --> %5:%6:%7,%8") |
| 137 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(h1, 2, 10, QCharcxx . . $ QChar#('0')) |
| 138 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(m1, 2, 10, QCharcxx . . $ QChar#('0')) |
| 139 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(s1, 2, 10, QCharcxx . . $ QChar#('0')) |
| 140 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(ms1, 3, 10, QCharcxx . . $ QChar#('0')) |
| 141 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(h2, 2, 10, QCharcxx . . $ QChar#('0')) |
| 142 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(m2, 2, 10, QCharcxx . . $ QChar#('0')) |
| 143 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(s2, 2, 10, QCharcxx . . $ QChar#('0')) |
| 144 | .argcxx . . $ QString#arg(64ab2ed17cc11715).(ms2, 3, 10, QCharcxx . . $ QChar#('0')) |
| 145 | <<cxx . . $ QStringList#`operator<<`(cb3c3d1614140851). tokensBuff.splitcxx . . $ QString#split(c8b44a97dcb6200d).("\n"cxx . . $ QString#QString(85c52e162fed56f9).); |
| 146 | return out; |
| 147 | } |
| 148 | |
| 149 | QStringcxx . . $ QString# SubRipSubtitleFormatcxx . . $ SubRipSubtitleFormat#::encodeTokencxx . . $ SubRipSubtitleFormat#encodeToken(a468b8cbbcf05ae6).(const SubTokencxx . . $ SubToken# &entry) const { |
| 150 | switch (entry.typecxx . . $ SubToken#type.) { |
| 151 | case STT_WScxx . . $ STT_WS.: |
| 152 | returncxx . . $ QString#QString(e1217c004a86c950). " "cxx . . $ QString#QString(85c52e162fed56f9).; |
| 153 | case STT_WORDcxx . . $ STT_WORD.: |
| 154 | return entrycxx . . $ QString#QString(3520e46b33348bf6)..payloadcxx . . $ SubToken#payload.; |
| 155 | case STT_NEWLINEcxx . . $ STT_NEWLINE.: |
| 156 | returncxx . . $ QString#QString(e1217c004a86c950). "\n"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 157 | case STT_BOLDcxx . . $ STT_BOLD.: |
| 158 | returncxx . . $ QString#QString(e1217c004a86c950). "<b>"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 159 | case STT_BOLD_ENDcxx . . $ STT_BOLD_END.: |
| 160 | returncxx . . $ QString#QString(e1217c004a86c950). "</b>"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 161 | case STT_ITALICcxx . . $ STT_ITALIC.: |
| 162 | returncxx . . $ QString#QString(e1217c004a86c950). "<i>"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 163 | case STT_ITALIC_ENDcxx . . $ STT_ITALIC_END.: |
| 164 | returncxx . . $ QString#QString(e1217c004a86c950). "</i>"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 165 | case STT_UNDERLINEcxx . . $ STT_UNDERLINE.: |
| 166 | returncxx . . $ QString#QString(e1217c004a86c950). "<u>"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 167 | case STT_UNDERLINE_ENDcxx . . $ STT_UNDERLINE_END.: |
| 168 | returncxx . . $ QString#QString(e1217c004a86c950). "</u>"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 169 | case STT_FONTCOLORcxx . . $ STT_FONTCOLOR.: |
| 170 | return QStringcxx . . $ QString#QString(e1217c004a86c950).("<font color=\"#%1\">").argcxx . . $ QString#arg(bc823072288cbbb5).(entry.payloadcxx . . $ SubToken#payload.); |
| 171 | case STT_FONTCOLOR_ENDcxx . . $ STT_FONTCOLOR_END.: |
| 172 | returncxx . . $ QString#QString(e1217c004a86c950). "</font>"cxx . . $ QString#QString(85c52e162fed56f9).; |
| 173 | default: |
| 174 | returncxx . . $ QString#QString(e1217c004a86c950). ""cxx . . $ QString#QString(85c52e162fed56f9).; |
| 175 | } |
| 176 | } |