diff options
author | jmarshallnz <jcmarsha@gmail.com> | 2013-06-08 01:36:47 -0700 |
---|---|---|
committer | jmarshallnz <jcmarsha@gmail.com> | 2013-06-08 01:36:47 -0700 |
commit | e9aed1d645158647aa2006ac4b2d2d18a3d1ecbf (patch) | |
tree | 8fa38ed143c881655339ed201a56172929bb27ff | |
parent | 65e437850f964e121df87e097395d19fb0313dfa (diff) | |
parent | c4ffa77367d1715f7381b54eff3a9d1e483a7ea6 (diff) |
Merge pull request #2806 from Fice/rip_to_dp
Add ripped CDs automatically to database
-rw-r--r-- | xbmc/cdrip/CDDARipJob.h | 1 | ||||
-rw-r--r-- | xbmc/cdrip/CDDARipper.cpp | 19 | ||||
-rw-r--r-- | xbmc/music/MusicDatabase.cpp | 6 | ||||
-rw-r--r-- | xbmc/music/MusicDatabase.h | 4 | ||||
-rw-r--r-- | xbmc/utils/JobManager.cpp | 7 | ||||
-rw-r--r-- | xbmc/utils/JobManager.h | 7 |
6 files changed, 44 insertions, 0 deletions
diff --git a/xbmc/cdrip/CDDARipJob.h b/xbmc/cdrip/CDDARipJob.h index adb2c08631..865165f102 100644 --- a/xbmc/cdrip/CDDARipJob.h +++ b/xbmc/cdrip/CDDARipJob.h @@ -52,6 +52,7 @@ public: virtual const char* GetType() const { return "cdrip"; }; virtual bool operator==(const CJob *job) const; virtual bool DoWork(); + CStdString GetOutput() const { return m_output; } protected: //! \brief Setup the audio encoder CEncoder* SetupEncoder(XFILE::CFile& reader); diff --git a/xbmc/cdrip/CDDARipper.cpp b/xbmc/cdrip/CDDARipper.cpp index 6cae00ebc5..7c4728e197 100644 --- a/xbmc/cdrip/CDDARipper.cpp +++ b/xbmc/cdrip/CDDARipper.cpp @@ -44,6 +44,9 @@ #include "utils/log.h" #include "utils/TimeUtils.h" #include "utils/URIUtils.h" +#include "settings/MediaSourceSettings.h" +#include "Application.h" +#include "music/MusicDatabase.h" using namespace std; using namespace XFILE; @@ -56,6 +59,7 @@ CCDDARipper& CCDDARipper::GetInstance() } CCDDARipper::CCDDARipper() + : CJobQueue(false, 1) //enforce fifo and non-parallel processing { } @@ -303,7 +307,22 @@ CStdString CCDDARipper::GetTrackName(CFileItem *item) void CCDDARipper::OnJobComplete(unsigned int jobID, bool success, CJob* job) { if (success) + { + if(CJobQueue::QueueEmpty()) + { + CStdString dir; + URIUtils::GetDirectory(((CCDDARipJob*)job)->GetOutput(), dir); + bool unimportant; + int source = CUtil::GetMatchingSource(dir, *CMediaSourceSettings::Get().CMediaSourceSettings::GetSources("music"), unimportant); + + CMusicDatabase database; + database.Open(); + if(source>=0 && database.InsideScannedPath(dir)); + g_application.StartMusicScan(dir); + database.Close(); + } return CJobQueue::OnJobComplete(jobID, success, job); + } CancelJobs(); } diff --git a/xbmc/music/MusicDatabase.cpp b/xbmc/music/MusicDatabase.cpp index 6730316024..212302d3f6 100644 --- a/xbmc/music/MusicDatabase.cpp +++ b/xbmc/music/MusicDatabase.cpp @@ -2193,6 +2193,12 @@ bool CMusicDatabase::CleanupPaths() return false; } +bool CMusicDatabase::InsideScannedPath(const CStdString& path) +{ + CStdString sql = PrepareSQL("select idPath from path where SUBSTR(strPath,1,%i)='%s' LIMIT 1", path.size(), path.c_str()); + return !GetSingleValue(sql).empty(); +} + bool CMusicDatabase::CleanupArtists() { try diff --git a/xbmc/music/MusicDatabase.h b/xbmc/music/MusicDatabase.h index 1819794e53..dfe79fd360 100644 --- a/xbmc/music/MusicDatabase.h +++ b/xbmc/music/MusicDatabase.h @@ -171,6 +171,10 @@ public: bool GetAlbum(int idAlbum, CAlbum& album); int UpdateAlbum(int idAlbum, const CAlbum &album); bool DeleteAlbum(int idAlbum); + /*! \brief Checks if the given path is inside a folder that has already been scanned into the library + \param path the path we want to check + */ + bool InsideScannedPath(const CStdString& path); //// Misc Album int GetAlbumIdByPath(const CStdString& path); diff --git a/xbmc/utils/JobManager.cpp b/xbmc/utils/JobManager.cpp index c7a90e02cd..5399097574 100644 --- a/xbmc/utils/JobManager.cpp +++ b/xbmc/utils/JobManager.cpp @@ -158,6 +158,13 @@ void CJobQueue::CancelJobs() m_processing.clear(); } + +bool CJobQueue::QueueEmpty() const +{ + CSingleLock lock(m_section); + return m_jobQueue.empty(); +} + CJobManager &CJobManager::GetInstance() { static CJobManager sJobManager; diff --git a/xbmc/utils/JobManager.h b/xbmc/utils/JobManager.h index c53ea68edc..626d77c66c 100644 --- a/xbmc/utils/JobManager.h +++ b/xbmc/utils/JobManager.h @@ -135,6 +135,13 @@ public: */ virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job); +protected: + /*! + \brief Returns if we still have jobs waiting to be processed + NOTE: This function does not take into account the jobs that are currently processing + */ + bool QueueEmpty() const; + private: void QueueNextJob(); |