Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Music library export empty artist folders #15821

Merged
merged 1 commit into from
Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -20979,8 +20979,9 @@ msgctxt "#38042"
msgid "[Missing]"
msgstr ""

#. Title album artists node
#. Title album artists node, and music item to export output, see #38306
#: system/library/music/musicroles/albumartists.xml
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38043"
msgid "Album artists"
msgstr ""
Expand Down Expand Up @@ -21247,23 +21248,27 @@ msgstr ""

#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38309"
msgid "Output only artwork, not NFO files"
msgid "Output information to NFO files"
msgstr ""

#. See #38309 when NFO and art export disabled so only artist folders
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38310"
msgid "Overwrite existing files"
msgid "Output information to NFO files (currently exporting artist folders only)"
msgstr ""

#empty string with id 38311
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38311"
msgid "Overwrite existing files"
msgstr ""

#. Music item to export output, see #38093
#. Music item to export output, see #38306
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38312"
msgid "Song artists"
msgstr ""

#. Music item to export output, see #38093
#. Music item to export output, see #38306
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38313"
msgid "Other artists"
Expand Down Expand Up @@ -21295,7 +21300,37 @@ msgctxt "#38320"
msgid "Do you have local artist information (NFO) and art files that you want to fetch? Set the location of these artist folders now"
msgstr ""

#empty strings from id 38321 to 38329
#. Kind of export output, see #38304
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38321"
msgid "Artist folders only"
msgstr ""

#. Explanation of what export to library folders means see #38303 when albums and artists selected
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38322"
msgid "Artists exported to Artist Information Folder and albums to music folders"
msgstr ""

#. Explanation of what export to library folders means see #38303 when only albums selected
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38323"
msgid "Albums exported to music folders"
msgstr ""

#. Explanation of what export to library folders means see #38303 when only artists selected
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38324"
msgid "Artists exported to Artist Information Folder"
msgstr ""

#. Explanation of what export artist folders only means see #38304
#: xbmc/settings/dialogs/GUIDialogLibExportSettings.cpp
msgctxt "#38325"
msgid "Artist subfolders created in Artist Information Folder"
msgstr ""

#empty strings from id 38326 to 38329

#. Dialog heading when editing default settings for fetching additional music information
#: xbmc/music/dialogs/GUIDialogInfoProviderSettings.cpp
Expand Down
96 changes: 52 additions & 44 deletions xbmc/music/MusicDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9487,11 +9487,14 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
!settings.IsItemExported(ELIBEXPORT_ALBUMS))
return;

if (!settings.IsSingleFile() && settings.m_skipnfo && !settings.m_artwork)
// Exporting albums either art or NFO (or both) selected
if ((settings.IsToLibFolders() || settings.IsSeparateFiles()) &&
settings.m_skipnfo && !settings.m_artwork &&
settings.IsItemExported(ELIBEXPORT_ALBUMS))
return;

std::string strFolder;
if (!settings.IsToLibFolders())
if (settings.IsSingleFile() || settings.IsSeparateFiles())
{
// Exporting to single file or separate files in a specified location
if (settings.m_strPath.empty())
Expand All @@ -9504,15 +9507,22 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
if (strFolder.empty())
return;
}
else
else if (settings.IsArtistFoldersOnly() || (settings.IsToLibFolders() && settings.IsArtists()))
{
// Separate files with artists to library folder and albums to music folders.
// Without an artist information folder can not export artist NFO files or images
// Exporting artist folders only, or artist NFO or art to library folders
// need Artist Information Folder defined.
// (Album NFO and art goes to music folders)
strFolder = CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_MUSICLIBRARY_ARTISTSFOLDER);
if (!settings.IsItemExported(ELIBEXPORT_ALBUMS) && strFolder.empty())
if (strFolder.empty())
return;
}

//
bool artistfoldersonly;
artistfoldersonly = settings.IsArtistFoldersOnly() ||
((settings.IsToLibFolders() || settings.IsSeparateFiles()) &&
settings.m_skipnfo && !settings.m_artwork);

int iFailCount = 0;
try
{
Expand All @@ -9525,15 +9535,15 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
TiXmlDeclaration decl("1.0", "UTF-8", "yes");
xmlDoc.InsertEndChild(decl);
TiXmlNode *pMain = NULL;
if (!settings.IsSingleFile())
if ((settings.IsToLibFolders() || settings.IsSeparateFiles()) && !artistfoldersonly)
pMain = &xmlDoc;
else
else if (settings.IsSingleFile())
{
TiXmlElement xmlMainElement("musicdb");
pMain = xmlDoc.InsertEndChild(xmlMainElement);
}

if (settings.IsItemExported(ELIBEXPORT_ALBUMS))
if (settings.IsItemExported(ELIBEXPORT_ALBUMS) && !artistfoldersonly)
{
// Find albums to export
std::vector<int> albumIds;
Expand Down Expand Up @@ -9592,8 +9602,8 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
else
{ // Save album.nfo and artwork to subfolder on export path
// strPath = strFolder/<albumartist name>/<albumname>
// where <albumname> is either the same name as the album folder containing the music files (if unique)
// or is craeted using the album name
// where <albumname> is either the same name as the album folder
// containing the music files (if unique) or is created using the album name
std::string strAlbumArtist;
pathfound = GetArtistFolderName(album.GetAlbumArtist()[0], album.GetMusicBrainzAlbumArtistID()[0], strAlbumArtist);
if (pathfound)
Expand Down Expand Up @@ -9674,9 +9684,7 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
}
}

if ((settings.IsItemExported(ELIBEXPORT_ALBUMARTISTS) ||
settings.IsItemExported(ELIBEXPORT_SONGARTISTS) ||
settings.IsItemExported(ELIBEXPORT_OTHERARTISTS)) && !strFolder.empty())
if ((settings.IsArtists() || artistfoldersonly) && !strFolder.empty())
{
// Find artists to export
std::vector<int> artistIds;
Expand All @@ -9695,7 +9703,7 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
else if (settings.IsItemExported(ELIBEXPORT_OTHERARTISTS))
filter.AppendWhere("EXISTS (SELECT 1 FROM song_artist WHERE song_artist.idArtist = artist.idArtist AND song_artist.idRole > 1)", false);

if (!settings.m_unscraped)
if (!settings.m_unscraped && !artistfoldersonly)
filter.AppendWhere("lastScraped IS NOT NULL", true);

std::string strSQL = "SELECT idArtist FROM artist";
Expand All @@ -9716,7 +9724,7 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
for (const auto &artistId : artistIds)
{
CArtist artist;
GetArtist(artistId, artist, true); // include discography
GetArtist(artistId, artist, !artistfoldersonly); // include discography when not folders only
std::string strPath;
std::map<std::string, std::string> artwork;
if (settings.IsSingleFile())
Expand Down Expand Up @@ -9749,38 +9757,41 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
__FUNCTION__, artist.strArtist.c_str(), strPath.c_str());
else
{
if (!settings.m_skipnfo)
if (!artistfoldersonly)
{
artist.Save(pMain, "artist", strPath);
std::string nfoFile = URIUtils::AddFileToFolder(strPath, "artist.nfo");
if (settings.m_overwrite || !CFile::Exists(nfoFile))
if (!settings.m_skipnfo)
{
if (!xmlDoc.SaveFile(nfoFile))
artist.Save(pMain, "artist", strPath);
std::string nfoFile = URIUtils::AddFileToFolder(strPath, "artist.nfo");
if (settings.m_overwrite || !CFile::Exists(nfoFile))
{
CLog::Log(LOGERROR, "CMusicDatabase::%s: Artist nfo export failed! ('%s')", __FUNCTION__, nfoFile.c_str());
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(20302), nfoFile);
iFailCount++;
if (!xmlDoc.SaveFile(nfoFile))
{
CLog::Log(LOGERROR, "CMusicDatabase::%s: Artist nfo export failed! ('%s')", __FUNCTION__, nfoFile.c_str());
CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Error, g_localizeStrings.Get(20302), nfoFile);
iFailCount++;
}
}
}
}
if (settings.m_artwork)
{
std::string savedArtfile;
if (GetArtForItem(artist.idArtist, MediaTypeArtist, artwork))
if (settings.m_artwork)
{
for (const auto &art : artwork)
std::string savedArtfile;
if (GetArtForItem(artist.idArtist, MediaTypeArtist, artwork))
{
if (art.first == "thumb")
savedArtfile = URIUtils::AddFileToFolder(strPath, "folder");
else
savedArtfile = URIUtils::AddFileToFolder(strPath, art.first);
CTextureCache::GetInstance().Export(art.second, savedArtfile, settings.m_overwrite);
for (const auto &art : artwork)
{
if (art.first == "thumb")
savedArtfile = URIUtils::AddFileToFolder(strPath, "folder");
else
savedArtfile = URIUtils::AddFileToFolder(strPath, art.first);
CTextureCache::GetInstance().Export(art.second, savedArtfile, settings.m_overwrite);
}
}
}
xmlDoc.Clear();
TiXmlDeclaration decl("1.0", "UTF-8", "yes");
xmlDoc.InsertEndChild(decl);
}
xmlDoc.Clear();
TiXmlDeclaration decl("1.0", "UTF-8", "yes");
xmlDoc.InsertEndChild(decl);
}
}
if ((current % 50) == 0 && progressDialog)
Expand All @@ -9802,12 +9813,9 @@ void CMusicDatabase::ExportToXML(const CLibExportSettings& settings, CGUIDialog
xmlDoc.SaveFile(xmlFile);

CVariant data;
if (settings.IsSingleFile())
{
data["file"] = xmlFile;
if (iFailCount > 0)
data["failcount"] = iFailCount;
}
data["file"] = xmlFile;
if (iFailCount > 0)
data["failcount"] = iFailCount;
CServiceBroker::GetAnnouncementManager()->Announce(ANNOUNCEMENT::AudioLibrary, "xbmc", "OnExport", data);
}
}
Expand Down
12 changes: 12 additions & 0 deletions xbmc/settings/LibExportSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ bool CLibExportSettings::IsItemExported(ELIBEXPORTOPTIONS item) const
return (m_itemstoexport & item);
}

bool CLibExportSettings::IsArtists() const
{
return (m_itemstoexport & ELIBEXPORT_ALBUMARTISTS) ||
(m_itemstoexport & ELIBEXPORT_SONGARTISTS) ||
(m_itemstoexport & ELIBEXPORT_OTHERARTISTS);
}

std::vector<int> CLibExportSettings::GetExportItems() const
{
std::vector<int> values;
Expand Down Expand Up @@ -82,3 +89,8 @@ bool CLibExportSettings::IsToLibFolders() const
{
return (m_exporttype == ELIBEXPORT_TOLIBRARYFOLDER);
}

bool CLibExportSettings::IsArtistFoldersOnly() const
{
return (m_exporttype == ELIBEXPORT_ARTISTFOLDERS);
}
5 changes: 4 additions & 1 deletion xbmc/settings/LibExportSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ enum ELIBEXPORTOPTIONS
ELIBEXPORT_OTHERARTISTS = 0x0080,
ELIBEXPORT_ARTWORK = 0x0100,
ELIBEXPORT_NFOFILES = 0x0200,
ELIBEXPORT_ACTORTHUMBS = 0x0400
ELIBEXPORT_ACTORTHUMBS = 0x0400,
ELIBEXPORT_ARTISTFOLDERS = 0x0800
};

class CLibExportSettings
Expand All @@ -40,6 +41,7 @@ class CLibExportSettings

bool operator!=(const CLibExportSettings &right) const;
bool IsItemExported(ELIBEXPORTOPTIONS item) const;
bool IsArtists() const;
std::vector<int> GetExportItems() const;
void ClearItems() { m_itemstoexport = 0; }
void AddItem(ELIBEXPORTOPTIONS item) { m_itemstoexport += item; }
Expand All @@ -50,6 +52,7 @@ class CLibExportSettings
bool IsSingleFile() const;
bool IsSeparateFiles() const;
bool IsToLibFolders() const;
bool IsArtistFoldersOnly() const;

std::string m_strPath;
bool m_overwrite;
Expand Down
Loading