| 138 | } |
| 139 | |
| 140 | TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName) |
| 141 | { |
| 142 | Diagnostics diag; |
| 143 | AbortableProgressFeedback progress; // FIXME: actually use the progress object |
| 144 | MediaFileInfo fileInfo(std::string(toNativeFileName(fileName).data())); |
| 145 | |
| 146 | // add basic file information |
| 147 | auto fileInfoObject = m_engine->newObject(); |
| 148 | fileInfoObject.setProperty(QStringLiteral("currentPath"), QString::fromUtf8(fileInfo.path().data())); |
| 149 | fileInfoObject.setProperty(QStringLiteral("currentPathWithoutExtension"), QString::fromUtf8(fileInfo.pathWithoutExtension().data())); |
| 150 | fileInfoObject.setProperty(QStringLiteral("currentName"), QString::fromUtf8(fileInfo.fileName(false).data())); |
| 151 | fileInfoObject.setProperty(QStringLiteral("currentBaseName"), QString::fromUtf8(fileInfo.fileName(true).data())); |
| 152 | QString suffix = fromNativeFileName(fileInfo.extension().data()); |
| 153 | if (suffix.startsWith('.')) { |
| 154 | suffix.remove(0, 1); |
| 155 | } |
| 156 | fileInfoObject.setProperty(QStringLiteral("currentSuffix"), suffix TAGEDITOR_JS_READONLY); |
| 157 | |
| 158 | // parse further file information |
| 159 | bool criticalParseingErrorOccured = false, ioErrorOccured = false; |
| 160 | try { |
| 161 | fileInfo.parseEverything(diag, progress); |
| 162 | } catch (const Failure &) { |
| 163 | // parsing notifications will be added anyways |
| 164 | criticalParseingErrorOccured = true; |
| 165 | } catch (const std::ios_base::failure &) { |
| 166 | criticalParseingErrorOccured = true; |
| 167 | ioErrorOccured = true; |
| 168 | } |
| 169 | |
| 170 | // add diag messages |
| 171 | auto diagObj = m_engine->newArray(static_cast<uint>(diag.size())); |
| 172 | diagObj << diag; |
| 173 | criticalParseingErrorOccured |= diag.level() >= DiagLevel::Critical; |
| 174 | fileInfoObject.setProperty(QStringLiteral("hasCriticalMessages"), criticalParseingErrorOccured); |
| 175 | fileInfoObject.setProperty(QStringLiteral("ioErrorOccured"), ioErrorOccured); |
| 176 | fileInfoObject.setProperty(QStringLiteral("diagMessages"), diagObj); |
| 177 | |
| 178 | // add MIME-type, suitable suffix and technical summary |
| 179 | fileInfoObject.setProperty(QStringLiteral("mimeType"), qstr(fileInfo.mimeType()) TAGEDITOR_JS_READONLY); |
| 180 | fileInfoObject.setProperty(QStringLiteral("suitableSuffix"), qstr(fileInfo.containerFormatAbbreviation()) TAGEDITOR_JS_READONLY); |
| 181 | fileInfoObject.setProperty(QStringLiteral("technicalSummary"), qstr(fileInfo.technicalSummary()) TAGEDITOR_JS_READONLY); |
| 182 | fileInfoObject.setProperty(QStringLiteral("hasAudioTracks"), fileInfo.hasTracksOfType(MediaType::Audio) TAGEDITOR_JS_READONLY); |
| 183 | fileInfoObject.setProperty(QStringLiteral("hasVideoTracks"), fileInfo.hasTracksOfType(MediaType::Video) TAGEDITOR_JS_READONLY); |
| 184 | |
| 185 | // add tag information |
| 186 | const vector<Tag *> tags = fileInfo.tags(); |
| 187 | auto combinedTagObject = m_engine->newObject(); |
| 188 | auto tagsObject = m_engine->newArray(static_cast<uint>(tags.size())); |
| 189 | std::uint32_t tagIndex = 0; |
| 190 | for (auto tagIterator = tags.cbegin(), end = tags.cend(); tagIterator != end; ++tagIterator, ++tagIndex) { |
| 191 | const Tag &tag = **tagIterator; |
| 192 | auto tagObject = m_engine->newObject(); |
| 193 | combinedTagObject << tag; |
| 194 | tagObject << tag; |
| 195 | tagsObject.setProperty(tagIndex, tagObject TAGEDITOR_JS_READONLY); |
| 196 | } |
| 197 | fileInfoObject.setProperty(QStringLiteral("tag"), combinedTagObject TAGEDITOR_JS_READONLY); |
no test coverage detected