Skip to content
This repository
Browse code

videodb: introduce GetFileInfo() to retrieve basic info for non-libra…

…ry files and use it in LoadVideoInfo()
  • Loading branch information...
commit 203e7392b24f54d7fb6ad731f1e8ba964fde495d 1 parent 49b7e5c
Sascha Montellese Montellese authored

Showing 2 changed files with 39 additions and 0 deletions. Show diff stats Hide diff stats

  1. +38 0 xbmc/video/VideoDatabase.cpp
  2. +1 0  xbmc/video/VideoDatabase.h
38 xbmc/video/VideoDatabase.cpp
@@ -1539,6 +1539,8 @@ bool CVideoDatabase::LoadVideoInfo(const CStdString& strFilenameAndPath, CVideoI
1539 1539 CLog::Log(LOGDEBUG,"%s, got music video info!", __FUNCTION__);
1540 1540 CLog::Log(LOGDEBUG," Title = %s", details.m_strTitle.c_str());
1541 1541 }
  1542 + else if (GetFileInfo(strFilenameAndPath, details))
  1543 + CLog::Log(LOGDEBUG,"%s, got file info!", __FUNCTION__);
1542 1544
1543 1545 return !details.IsEmpty();
1544 1546 }
@@ -1835,6 +1837,42 @@ bool CVideoDatabase::GetSetInfo(int idSet, CVideoInfoTag& details)
1835 1837 return false;
1836 1838 }
1837 1839
  1840 +bool CVideoDatabase::GetFileInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idFile /* = -1 */)
  1841 +{
  1842 + try
  1843 + {
  1844 + if (idFile < 0)
  1845 + idFile = GetFileId(strFilenameAndPath);
  1846 + if (idFile < 0)
  1847 + return false;
  1848 +
  1849 + CStdString sql = PrepareSQL("SELECT * FROM files "
  1850 + "JOIN path ON path.idPath = files.idPath "
  1851 + "JOIN bookmark ON bookmark.idFile = files.idFile AND bookmark.type = %i "
  1852 + "WHERE files.idFile = %i", CBookmark::RESUME, idFile);
  1853 + if (!m_pDS->query(sql.c_str()))
  1854 + return false;
  1855 +
  1856 + details.m_iFileId = m_pDS->fv("files.idFile").get_asInt();
  1857 + details.m_strPath = m_pDS->fv("path.strPath").get_asString();
  1858 + CStdString strFileName = m_pDS->fv("files.strFilename").get_asString();
  1859 + ConstructPath(details.m_strFileNameAndPath, details.m_strPath, strFileName);
  1860 + details.m_playCount = m_pDS->fv("files.playCount").get_asInt();
  1861 + details.m_lastPlayed.SetFromDBDateTime(m_pDS->fv("files.lastPlayed").get_asString());
  1862 + details.m_dateAdded.SetFromDBDateTime(m_pDS->fv("files.dateAdded").get_asString());
  1863 + details.m_resumePoint.timeInSeconds = m_pDS->fv("bookmark.timeInSeconds").get_asInt();
  1864 + details.m_resumePoint.totalTimeInSeconds = m_pDS->fv("bookmark.totalTimeInSeconds").get_asInt();
  1865 + details.m_resumePoint.type = CBookmark::RESUME;
  1866 +
  1867 + return !details.IsEmpty();
  1868 + }
  1869 + catch (...)
  1870 + {
  1871 + CLog::Log(LOGERROR, "%s (%s) failed", __FUNCTION__, strFilenameAndPath.c_str());
  1872 + }
  1873 + return false;
  1874 +}
  1875 +
1838 1876 void CVideoDatabase::AddGenreAndDirectorsAndStudios(const CVideoInfoTag& details, vector<int>& vecDirectors, vector<int>& vecGenres, vector<int>& vecStudios)
1839 1877 {
1840 1878 // add all directors
1  xbmc/video/VideoDatabase.h
@@ -430,6 +430,7 @@ class CVideoDatabase : public CDatabase
430 430 bool GetEpisodeInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1);
431 431 bool GetMusicVideoInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idMVideo=-1);
432 432 bool GetSetInfo(int idSet, CVideoInfoTag& details);
  433 + bool GetFileInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idFile = -1);
433 434
434 435 int GetPathId(const CStdString& strPath);
435 436 int GetTvShowId(const CStdString& strPath);

0 comments on commit 203e739

jmarshallnz

This, coupled with the recent changes in firing off messages for each and every addition to the playlist player (which then calls LoadVideoInfo here from the announcemanager) means that if the resume point has been set from a plugin (or other VFS source) it's promptly overwritten again here.

The same would happen with playcounts, date added, last played and so on.

A potential solution is not filling these fields in when they're already set. In addition, taking a copy of the item to pass to the announcemanager (or, alternatively, passing a copy into the playlist player to begin with) might be wise - you don't really want to be messing around with the item shared in the UI necessarily.

Sascha Montellese

Darn I didn't consider that use case.

While taking a copy of the item to pass to the announcement manager would work, it would result in a new db lookup on every notification for that item. To avoid that the announcement manager stores a property in the CFileItem that it has already done the db lookup and that it doesn't have to be done again on the next announcement.

The only "easy" fix I can think of right now is to only set those properties if they haven't already been set. This works fine for lastplayed, dateadded and resumepoint but can be a bit tricky for playcount as a plugin might intentionally set the playcount to 0 even if the playcount in the db is bigger than 0.

The ideal solution would be to retrieve this information once whenever an item is starting to play in xbmc or handed to the playlist player or whatever. Then the announcement manager wouldn't have to care about it anymore and mess around with the CFileItem object from the GUI thread.

Please sign in to comment.
Something went wrong with that request. Please try again.