RenameParser::Environment videoFileEnv;
bool useVideoFileEnv = false;
- if (!env.value("RenameAsVideoFile", "").isEmpty())
+ if (!isVideoFile(r) && !env.value("RenameAsVideoFile", "").isEmpty())
{
+ // TODO What should be done if there is more than one video file?
QSqlQuery &q = db->prepare(
"SELECT rd.* "
" FROM rename_data rd "
" AND rd2.type = rd.type "
// TODO there should only be one of those.
// Waiting for video_codec normalization
+ // TODO not all video files have a video codec set
" AND rd.video_codec <> 'none' "
" AND rd.video_codec <> '') "
" WHERE rd2.fid = :fid "
if (db->exec(q) && q.next())
{
QSqlRecord r = q.record();
- setupRenameEnv(r, videoFileEnv);
+ setupRenameEnv(r, videoFileEnv, true);
renameEngine->evaluate(videoFileEnv);
if (!videoFileEnv.value("FileName", "").isEmpty())
{
fl.failedRename = false;
db->setFileLocation(fl);
+ db->log(tr("Rename: New name is same as current name for <%1>").arg(oldFile.filePath()));
continue;
}
env["RenamingAsVideoFile"] = renamingAsVideoFile ? "1" : "";
}
+bool isVideoFile(const QSqlRecord &record)
+{
+ const auto vcodec = record.value("video_codec");
+
+ if (!vcodec.isNull() && !vcodec.toString().isEmpty())
+ return true;
+
+ // Unfortunately not all video files have a video codec set
+ const auto extension = record.value("extension");
+
+ static const auto knownVideoFileExtensions = {"mkv", "avi", "mp4"};
+
+ return std::find(std::begin(knownVideoFileExtensions),
+ std::end(knownVideoFileExtensions),
+ extension) != std::end(knownVideoFileExtensions);
+}
+
#ifdef Q_OS_WIN
#include <QDir>
#include <windows.h>
void LOCALMYLISTSHARED_EXPORT setupRenameEnv(const QSqlRecord &record, RenameParser::Environment &env, bool renamingAsVideoFile = false);
+bool LOCALMYLISTSHARED_EXPORT isVideoFile(const QSqlRecord &record);
+
QString exactPath(const QString &path);
bool LOCALMYLISTSHARED_EXPORT renameFile(const QString &oldName, const QString &newName, QString *actualPath = 0);