Skip to content
Browse files

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

…ry files and use it in LoadVideoInfo()
  • Loading branch information...
1 parent 49b7e5c commit 203e7392b24f54d7fb6ad731f1e8ba964fde495d @Montellese Montellese committed Aug 20, 2012
Showing with 39 additions and 0 deletions.
  1. +38 −0 xbmc/video/VideoDatabase.cpp
  2. +1 −0 xbmc/video/VideoDatabase.h
View
38 xbmc/video/VideoDatabase.cpp
@@ -1539,6 +1539,8 @@ bool CVideoDatabase::LoadVideoInfo(const CStdString& strFilenameAndPath, CVideoI
CLog::Log(LOGDEBUG,"%s, got music video info!", __FUNCTION__);
CLog::Log(LOGDEBUG," Title = %s", details.m_strTitle.c_str());
}
+ else if (GetFileInfo(strFilenameAndPath, details))
+ CLog::Log(LOGDEBUG,"%s, got file info!", __FUNCTION__);
return !details.IsEmpty();
}
@@ -1835,6 +1837,42 @@ bool CVideoDatabase::GetSetInfo(int idSet, CVideoInfoTag& details)
return false;
}
+bool CVideoDatabase::GetFileInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idFile /* = -1 */)
+{
+ try
+ {
+ if (idFile < 0)
+ idFile = GetFileId(strFilenameAndPath);
+ if (idFile < 0)
+ return false;
+
+ CStdString sql = PrepareSQL("SELECT * FROM files "
+ "JOIN path ON path.idPath = files.idPath "
+ "JOIN bookmark ON bookmark.idFile = files.idFile AND bookmark.type = %i "
+ "WHERE files.idFile = %i", CBookmark::RESUME, idFile);
+ if (!m_pDS->query(sql.c_str()))
+ return false;
+
+ details.m_iFileId = m_pDS->fv("files.idFile").get_asInt();
+ details.m_strPath = m_pDS->fv("path.strPath").get_asString();
+ CStdString strFileName = m_pDS->fv("files.strFilename").get_asString();
+ ConstructPath(details.m_strFileNameAndPath, details.m_strPath, strFileName);
+ details.m_playCount = m_pDS->fv("files.playCount").get_asInt();
+ details.m_lastPlayed.SetFromDBDateTime(m_pDS->fv("files.lastPlayed").get_asString());
+ details.m_dateAdded.SetFromDBDateTime(m_pDS->fv("files.dateAdded").get_asString());
+ details.m_resumePoint.timeInSeconds = m_pDS->fv("bookmark.timeInSeconds").get_asInt();
+ details.m_resumePoint.totalTimeInSeconds = m_pDS->fv("bookmark.totalTimeInSeconds").get_asInt();
+ details.m_resumePoint.type = CBookmark::RESUME;
@jmarshallnz
Team Kodi member
jmarshallnz added a note Oct 3, 2012

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.

@Montellese
Team Kodi member
Montellese added a note Oct 3, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ return !details.IsEmpty();
+ }
+ catch (...)
+ {
+ CLog::Log(LOGERROR, "%s (%s) failed", __FUNCTION__, strFilenameAndPath.c_str());
+ }
+ return false;
+}
+
void CVideoDatabase::AddGenreAndDirectorsAndStudios(const CVideoInfoTag& details, vector<int>& vecDirectors, vector<int>& vecGenres, vector<int>& vecStudios)
{
// add all directors
View
1 xbmc/video/VideoDatabase.h
@@ -430,6 +430,7 @@ class CVideoDatabase : public CDatabase
bool GetEpisodeInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idEpisode = -1);
bool GetMusicVideoInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idMVideo=-1);
bool GetSetInfo(int idSet, CVideoInfoTag& details);
+ bool GetFileInfo(const CStdString& strFilenameAndPath, CVideoInfoTag& details, int idFile = -1);
int GetPathId(const CStdString& strPath);
int GetTvShowId(const CStdString& strPath);

0 comments on commit 203e739

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