Use track info in example script
This commit is contained in:
parent
4951f5bdc3
commit
aa21519660
|
@ -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)) {
|
||||||
|
|
Loading…
Reference in New Issue