Merge pull request #58 from Martchus/renaming-utility

Enhance renaming utility
This commit is contained in:
Martchus 2020-10-01 21:01:44 +02:00 committed by GitHub
commit b7fb9d063c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View File

@ -192,7 +192,7 @@ if (WIDGETS_GUI OR QUICK_GUI)
endif () endif ()
# find tagparser # find tagparser
find_package(tagparser${CONFIGURATION_PACKAGE_SUFFIX} 9.2.0 REQUIRED) find_package(tagparser${CONFIGURATION_PACKAGE_SUFFIX} 9.3.0 REQUIRED)
use_tag_parser() use_tag_parser()
# enable experimental JSON export # enable experimental JSON export

View File

@ -208,9 +208,13 @@ TAGEDITOR_JS_VALUE TagEditorObject::parseFileInfo(const QString &fileName)
trackObject.setProperty(QStringLiteral("mediaType"), QString::fromUtf8(track.mediaTypeName())); trackObject.setProperty(QStringLiteral("mediaType"), QString::fromUtf8(track.mediaTypeName()));
trackObject.setProperty(QStringLiteral("format"), QString::fromUtf8(track.formatName())); trackObject.setProperty(QStringLiteral("format"), QString::fromUtf8(track.formatName()));
trackObject.setProperty(QStringLiteral("formatAbbreviation"), QString::fromUtf8(track.formatAbbreviation())); trackObject.setProperty(QStringLiteral("formatAbbreviation"), QString::fromUtf8(track.formatAbbreviation()));
trackObject.setProperty(QStringLiteral("description"), QString::fromUtf8(track.description().data())); trackObject.setProperty(QStringLiteral("version"), QString::number(track.version()));
trackObject.setProperty(QStringLiteral("language"), QString::fromStdString(track.language()));
trackObject.setProperty(QStringLiteral("description"), QString::fromStdString(track.description()));
trackObject.setProperty(QStringLiteral("shortDescription"), QString::fromStdString(track.shortDescription()));
tracksObject.setProperty(trackIndex, trackObject TAGEDITOR_JS_READONLY); tracksObject.setProperty(trackIndex, trackObject TAGEDITOR_JS_READONLY);
} }
fileInfoObject.setProperty(QStringLiteral("tracks"), tracksObject TAGEDITOR_JS_READONLY);
return fileInfoObject; return fileInfoObject;
} }

View File

@ -11,6 +11,12 @@ var includeArtist = true
var includeAlbum = true var includeAlbum = true
// specifies whether the title should be included // specifies whether the title should be included
var includeTitle = true var includeTitle = true
// specifies whether tags like [foo] should be stripped from the title if deduced from file name
var stripTags = false
// specifies whether the title deduced from the file name should be kept as-is
var keepTitleFromFileName = false
// specifies whether track information should be appended (like [H.265-320p AAC-LC-2ch-eng AAC-LC-2ch-ger])
var includeTrackInfo = false
// specifies the "distribution directory" // specifies the "distribution directory"
//var distDir = false; // don't move files around //var distDir = false; // don't move files around
var distDir = "/path/to/my/music-collection" // move files to an appropriate subdirectory under this path var distDir = "/path/to/my/music-collection" // move files to an appropriate subdirectory under this path
@ -28,7 +34,10 @@ var isMiscFile = function (tag) {
var isPartOfCollection = function (tag) { var isPartOfCollection = function (tag) {
return tag.comment === "collection" return tag.comment === "collection"
} }
//
// helper functions // helper functions
//
// returns whether the specified \a value is not undefined and not an empty string. // returns whether the specified \a value is not undefined and not an empty string.
function notEmpty(value) { function notEmpty(value) {
@ -57,7 +66,14 @@ function validDirectoryName(name) {
return name !== undefined ? name.replace(/[\/\\]/gi, " - ").replace( return name !== undefined ? name.replace(/[\/\\]/gi, " - ").replace(
/[<>?!*|:\".\n\f\r]/gi, "") : "" /[<>?!*|:\".\n\f\r]/gi, "") : ""
} }
// strips tags from the beginning or end of the string if configured
function tagsStripped(name) {
return stripTags ? name.replace(/^(\[[^\]]*\]\s*)+/g, "").replace(/(\s*\[[^\]]*\])+$/g, "") : name;
}
//
// actual script // actual script
//
// skip directories in this example script // skip directories in this example script
if (!tageditor.isFile) { if (!tageditor.isFile) {
@ -68,6 +84,7 @@ if (!tageditor.isFile) {
// parse file using the built-in parseFileInfo function // parse file using the built-in parseFileInfo function
var fileInfo = tageditor.parseFileInfo(tageditor.currentPath) var fileInfo = tageditor.parseFileInfo(tageditor.currentPath)
var tag = fileInfo.tag var tag = fileInfo.tag
var tracks = fileInfo.tracks
// deduce title and track number from the file name using the built-in parseFileName function (as fallback if tags missing) // deduce title and track number from the file name using the built-in parseFileName function (as fallback if tags missing)
var infoFromFileName = tageditor.parseFileName(fileInfo.currentBaseName) var infoFromFileName = tageditor.parseFileName(fileInfo.currentBaseName)
@ -156,7 +173,12 @@ var title = validFileName(tag.title)
if (includeTitle) { if (includeTitle) {
// use value from file name if the tag has no title information // use value from file name if the tag has no title information
if (!notEmpty(title)) { if (!notEmpty(title)) {
title = validFileName(infoFromFileName.title) if (!keepTitleFromFileName) {
title = validFileName(tagsStripped(infoFromFileName.title))
}
if (!notEmpty(title)) {
title = validFileName(tagsStripped(fileInfo.currentBaseName))
}
} }
if (newName.length > 0) { if (newName.length > 0) {
newName = newName.concat(lastSeparator, title) newName = newName.concat(lastSeparator, title)
@ -165,6 +187,11 @@ if (includeTitle) {
} }
} }
// append track info
if (includeTrackInfo && tracks.length > 0) {
newName = newName.concat(" [", tracks.map(track => track.description).join(" "), "]")
}
// append an appropriate suffix // append an appropriate suffix
var suffix = "" var suffix = ""
if (notEmpty(fileInfo.suitableSuffix)) { if (notEmpty(fileInfo.suitableSuffix)) {