Commit b8a4b3fd authored by Urs Fleisch's avatar Urs Fleisch
Browse files

QML: Script to import from CSV file.

parent 9f396fdf
......@@ -32,8 +32,9 @@
* 0: <= 3.0.2
* 1: 3.1
* 2: 3.2
* 3: 3.3
*/
static const int CONFIG_VERSION = 2;
static const int CONFIG_VERSION = 3;
/** Version of configuration file read, -1 if not read yet. */
int ConfigStore::s_configVersion = -1;
......
......@@ -97,74 +97,89 @@ void UserActionsConfig::readFromConfig(ISettings* config)
}
config->endGroup();
if (cmdNr == 1) {
setDefaultUserActions();
}
setDefaultUserActions(cmdNr != 1);
}
/**
* Set default user actions.
* @param upgradeOnly if true only upgrade configuration with new actions
*/
void UserActionsConfig::setDefaultUserActions()
void UserActionsConfig::setDefaultUserActions(bool upgradeOnly)
{
m_contextMenuCommands.clear();
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QString(), QLatin1String("@separator")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Album Art"), QLatin1String("@beginmenu")));
if (!upgradeOnly) {
m_contextMenuCommands.clear();
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QString(), QLatin1String("@separator")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Album Art"), QLatin1String("@beginmenu")));
}
#ifdef HAVE_QML
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Resize Album Art"), QLatin1String("@qml %{qmlpath}/script/ResizeAlbumArt.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Extract Album Art"), QLatin1String("@qml %{qmlpath}/script/ExtractAlbumArt.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Embed Album Art"), QLatin1String("@qml %{qmlpath}/script/EmbedAlbumArt.qml"), false, true));
if (!upgradeOnly || ConfigStore::getConfigVersion() < 2) {
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Resize Album Art"), QLatin1String("@qml %{qmlpath}/script/ResizeAlbumArt.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Extract Album Art"), QLatin1String("@qml %{qmlpath}/script/ExtractAlbumArt.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Embed Album Art"), QLatin1String("@qml %{qmlpath}/script/EmbedAlbumArt.qml"), false, true));
}
#endif
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Google Images"), QLatin1String("%{browser} http://www.google.com/search?tbm=isch&q=%u{artist}%20%u{album}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Amazon"), QLatin1String("%{browser} http://www.amazon.com/s?search-alias=aps&field-keywords=%u{artist}+%u{album}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QString(), QLatin1String("@endmenu")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Lyrics"), QLatin1String("@beginmenu")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LyricWiki"), QLatin1String("%{browser} http://lyricwiki.org/%u{artist}:%u{title}")));
if (!upgradeOnly) {
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Google Images"), QLatin1String("%{browser} http://www.google.com/search?tbm=isch&q=%u{artist}%20%u{album}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Amazon"), QLatin1String("%{browser} http://www.amazon.com/s?search-alias=aps&field-keywords=%u{artist}+%u{album}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QString(), QLatin1String("@endmenu")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Lyrics"), QLatin1String("@beginmenu")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LyricWiki"), QLatin1String("%{browser} http://lyricwiki.org/%u{artist}:%u{title}")));
}
#ifdef HAVE_QML
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Embed Lyrics"), QLatin1String("@qml %{qmlpath}/script/EmbedLyrics.qml"), false, true));
if (!upgradeOnly || ConfigStore::getConfigVersion() < 2) {
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Embed Lyrics"), QLatin1String("@qml %{qmlpath}/script/EmbedLyrics.qml"), false, true));
}
#endif
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Lyrics.com"), QLatin1String("%{browser} http://www.lyrics.com/search.php?what=all&keyword=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("AZLyrics"), QLatin1String("%{browser} http://search.azlyrics.com/search.php?q=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Dark Lyrics"), QLatin1String("%{browser} http://www.darklyrics.com/search?q=%u{album}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Metro Lyrics"), QLatin1String("%{browser} http://www.metrolyrics.com/search.php?category=artisttitle&search=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("SongLyrics"), QLatin1String("%{browser} http://www.songlyrics.com/index.php?section=search&searchW=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LyricsMode"), QLatin1String("%{browser} http://www.lyricsmode.com/search.php?search=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Lyrster"), QLatin1String("%{browser} http://www.lyrster.com/songs-lyrics/%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("MP3 Lyrics"), QLatin1String("%{browser} http://mp3lyrics.com/Search/Advanced/?Track=%u{title}&Artist=%u{artist}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LRC123"), QLatin1String("%{browser} http://www.lrc123.com/?keyword=%u{artist}+%u{title}&field=all")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LyrDB LRC"), QLatin1String("%{browser} http://lyrdb.com/karaoke/index.htm?q=%u{artist}+%u{title}&action=search")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QString(), QLatin1String("@endmenu")));
if (!upgradeOnly) {
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Lyrics.com"), QLatin1String("%{browser} http://www.lyrics.com/search.php?what=all&keyword=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("AZLyrics"), QLatin1String("%{browser} http://search.azlyrics.com/search.php?q=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Dark Lyrics"), QLatin1String("%{browser} http://www.darklyrics.com/search?q=%u{album}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Metro Lyrics"), QLatin1String("%{browser} http://www.metrolyrics.com/search.php?category=artisttitle&search=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("SongLyrics"), QLatin1String("%{browser} http://www.songlyrics.com/index.php?section=search&searchW=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LyricsMode"), QLatin1String("%{browser} http://www.lyricsmode.com/search.php?search=%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Lyrster"), QLatin1String("%{browser} http://www.lyrster.com/songs-lyrics/%u{artist}+%u{title}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("MP3 Lyrics"), QLatin1String("%{browser} http://mp3lyrics.com/Search/Advanced/?Track=%u{title}&Artist=%u{artist}")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LRC123"), QLatin1String("%{browser} http://www.lrc123.com/?keyword=%u{artist}+%u{title}&field=all")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("LyrDB LRC"), QLatin1String("%{browser} http://lyrdb.com/karaoke/index.htm?q=%u{artist}+%u{title}&action=search")));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QString(), QLatin1String("@endmenu")));
}
#ifdef HAVE_QML
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("QML Console"), QLatin1String("@qmlview %{qmlpath}/script/QmlConsole.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("ReplayGain to SoundCheck"), QLatin1String("@qml %{qmlpath}/script/ReplayGain2SoundCheck.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Text Encoding ID3v1"), QLatin1String("@qml %{qmlpath}/script/ShowTextEncodingV1.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Export CSV"), QLatin1String("@qml %{qmlpath}/script/ExportCsv.qml %{directory}/export.csv"), false, true));
if (!upgradeOnly || ConfigStore::getConfigVersion() < 2) {
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("QML Console"), QLatin1String("@qmlview %{qmlpath}/script/QmlConsole.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("ReplayGain to SoundCheck"), QLatin1String("@qml %{qmlpath}/script/ReplayGain2SoundCheck.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Text Encoding ID3v1"), QLatin1String("@qml %{qmlpath}/script/ShowTextEncodingV1.qml"), false, true));
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Export CSV"), QLatin1String("@qml %{qmlpath}/script/ExportCsv.qml %{directory}/export.csv"), false, true));
}
if (!upgradeOnly || ConfigStore::getConfigVersion() < 3) {
m_contextMenuCommands.push_back(
UserActionsConfig::MenuCommand(QLatin1String("Import CSV"), QLatin1String("@qml %{qmlpath}/script/ImportCsv.qml %{directory}/export.csv"), false, true));
}
#endif
}
......
......@@ -179,8 +179,9 @@ public:
/**
* Set default user actions.
* @param upgradeOnly if true only upgrade configuration with new actions
*/
void setDefaultUserActions();
void setDefaultUserActions(bool upgradeOnly = false);
signals:
/** Emitted when commands changed. */
......
/**
* \file ExportAll.qml
* Export all tags of all files to a CSV file.
*
* \b Project: Kid3
* \author Urs Fleisch
* \date 06 Mar 2015
*
* Copyright (C) 2015 Urs Fleisch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Kid3 1.0
Kid3Script {
onRun: {
var rows, names, files = {}
var numRowsImported = 0
function readCsvFile(filePath) {
var filePathCol = -1
var lines = ("" + script.readFile(filePath)).split("\n")
for (var i = 0; i < lines.length; ++i) {
var line = lines[i]
if (line.length > 0) {
var columns = line.split("\t")
if (i > 0) {
if (filePathCol >= 0 && filePathCol < columns.length) {
files[columns[filePathCol]] = i - 1
}
rows.push(columns)
} else {
names = columns
filePathCol = names.indexOf("File Path")
rows = []
}
}
}
}
function doWork() {
var rowNr
if (files) {
var filePath = app.selectionInfo.filePath
rowNr = files[filePath]
} else {
rowNr = numRowsImported
}
if (typeof rowNr !== "undefined" && rowNr >= 0 && rowNr < rows.length) {
var row = rows[rowNr]
for (var i = 0; i < row.length && i < names.length; ++i) {
var frameName = names[i]
var frameValue = row[i]
if (frameName !== "File Path" && frameName !== "Duration" &&
frameValue !== "") {
frameValue = frameValue.replace(/\\n/g, "\n").replace(/\\r/g, "\r").
replace(/\\t/g, "\t")
if (frameName.substr(0, 2) === "v1") {
frameName = frameName.substr(2)
app.setFrame(tagv1, frameName, frameValue)
} else {
app.setFrame(tagv2, frameName, frameValue)
}
}
}
++numRowsImported
} else if (filePath) {
console.log("No data for " + filePath)
}
if (!app.nextFile()) {
console.log("Imported tags for %1 files".arg(numRowsImported))
if (isStandalone()) {
// Save the changes if the script is started stand-alone, not from Kid3.
// app.saveDirectory()
}
Qt.quit()
} else {
setTimeout(doWork, 1)
}
}
function startWork() {
app.expandFileListFinished.disconnect(startWork)
console.log("Setting tags")
app.firstFile()
doWork()
}
var importPath = getArguments()[0]
if (!importPath) {
importPath = script.tempPath() + "/export.csv"
}
readCsvFile(importPath)
if (rows && rows.length > 0 && names && names.length > 1) {
console.log("Read tags for %1 files from %2".
arg(rows.length).arg(importPath))
if (Object.keys(files).length === 0) {
console.log("No File Path column found, importing unconditionally.")
files = undefined
}
if (!isStandalone()) {
console.log("Expanding file list")
app.expandFileListFinished.connect(startWork)
app.requestExpandFileList()
} else {
startWork()
}
} else {
console.log("No data found in %1".arg(importPath))
}
}
}
......@@ -4,6 +4,7 @@ set (script_QML_SRCS
script/QmlConsole.qml
script/ShowTextEncodingV1.qml
script/ExportCsv.qml
script/ImportCsv.qml
script/ExtractAlbumArt.qml
script/EmbedAlbumArt.qml
script/EmbedLyrics.qml
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment