Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

add 'CVideoDatabase::GetPreviousEpisodeNotWatched' function #1780

Closed
wants to merge 1 commit into from

3 participants

@ikkemaniac

add check for unwatched episodes hooked in the 'OnPlayMedia' function
to inform the user of unwatched episodes from earlier this or previous
seasons.

wrote this for myself, maybe you find it usefull.

Regards,

ikkemaniac add 'CVideoDatabase::GetPreviousEpisodeNotWatched' function
add check for unwatched episodes hooked in the 'OnPlayMedia' function
to inform the user of unwatched episodes from earlier this or previous
seasons.
74e04ae
@jmarshallnz
Owner

I'm not sure whether we'll take the feature, but in general, please follow XBMC code guidelines ( braces on separate lines, make sure indenting is spaces using 2 spaces). Also, make sure you don't have extraneous comments or extraneous log statements in your patch.

Lastly, please feel free to use multi-line select statements instead of insanely long lines.

Your implementation seems reasonable, though I'd copy the item rather than just the path when you transform, and also eliminate the CFileItemPtr typedef in VideoDatabase.h by just passing a const CFileItem &.

This will be discussed post Frodo, so no need to make any changes should you not have the time etc.

@ikkemaniac

Ok, let me know if there's intrest, I will fix all suggestions then.

@MartijnKaijser

@jmarshallnz
is this something we will take?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 13, 2012
  1. add 'CVideoDatabase::GetPreviousEpisodeNotWatched' function

    ikkemaniac authored
    add check for unwatched episodes hooked in the 'OnPlayMedia' function
    to inform the user of unwatched episodes from earlier this or previous
    seasons.
This page is out of date. Refresh to see the latest.
View
12 language/English/strings.po
@@ -9282,6 +9282,18 @@ msgctxt "#20464"
msgid "Select %s"
msgstr ""
+msgctxt "#20465"
+msgid "Check for previous unwatched episodes"
+msgstr ""
+
+msgctxt "#20466"
+msgid "Unwatched episodes found"
+msgstr ""
+
+msgctxt "#20467"
+msgid "Do you want to play the first unwatched episode?"
+msgstr ""
+
#empty strings from id 20465 to 21329
#up to 21329 is reserved for the video db !! !
View
1  xbmc/settings/GUISettings.cpp
@@ -646,6 +646,7 @@ void CGUISettings::Initialize()
AddBool(vdl, "videolibrary.showunwatchedplots", 20369, true);
AddBool(NULL, "videolibrary.seasonthumbs", 20382, true);
AddBool(vdl, "videolibrary.actorthumbs", 20402, true);
+ AddBool(vdl, "videolibrary.checkpreviousepisodenotwatched", 20465, true);
map<int, int> flattenTVShowOptions;
flattenTVShowOptions.insert(make_pair(20420, 0));
View
59 xbmc/video/VideoDatabase.cpp
@@ -200,6 +200,7 @@ bool CVideoDatabase::CreateTables()
{
CStdString column;
if ( i == VIDEODB_ID_EPISODE_SEASON || i == VIDEODB_ID_EPISODE_EPISODE || i == VIDEODB_ID_EPISODE_BOOKMARK)
+ // why as varchar? columns are defined as INT in 'SDbTableOffsets DbEpisodeOffsets'
column.Format(",c%02d varchar(24)", i);
else
column.Format(",c%02d text", i);
@@ -1201,6 +1202,9 @@ int CVideoDatabase::AddEpisode(int idShow, const CStdString& strFilenameAndPath)
UpdateFileDateAdded(idFile, strFilenameAndPath);
CStdString strSQL=PrepareSQL("insert into episode (idEpisode, idFile, idShow) values (NULL, %i, %i)", idFile, idShow);
+
+ CLog::Log(LOGDEBUG, "%s : strSQL == %s", __FUNCTION__, strSQL.c_str());
+
m_pDS->exec(strSQL.c_str());
return (int)m_pDS->lastinsertid();
}
@@ -2187,6 +2191,9 @@ int CVideoDatabase::SetDetailsForEpisode(const CStdString& strFilenameAndPath, c
// and insert the new row
CStdString sql = "update episode set " + GetValueString(details, VIDEODB_ID_EPISODE_MIN, VIDEODB_ID_EPISODE_MAX, DbEpisodeOffsets);
sql += PrepareSQL(" where idEpisode=%i", idEpisode);
+
+ CLog::Log(LOGDEBUG, "%s : strSQL == %s", __FUNCTION__, sql.c_str());
+
m_pDS->exec(sql.c_str());
CommitTransaction();
@@ -3443,6 +3450,58 @@ void CVideoDatabase::GetCast(const CStdString &table, const CStdString &table_id
}
}
+// Get tvshow's previously broadcasted unwatched episodes
+CFileItem CVideoDatabase::GetPreviousEpisodeNotWatched(CFileItemPtr& pItem)
+{
+ /*
+ CStdString strSQL = PrepareSQL("select episodeview.c%02d
+ from episodeview
+ where idShow = %i
+ and (c%02d < %i or (c%02d = %i and c%02d < %i))
+ and (playCount <1 or playCount isNull)
+ order by CAST (c%02d as INT) asc, CAST (c%02d as INT) asc
+ limit 1",
+ VIDEODB_ID_EPISODE_BASEPATH,
+ pItem->GetVideoInfoTag()->m_iIdShow,
+ VIDEODB_ID_EPISODE_SEASON,
+ pItem->GetVideoInfoTag()->m_iSeason,
+ VIDEODB_ID_EPISODE_SEASON,
+ pItem->GetVideoInfoTag()->m_iSeason,
+ VIDEODB_ID_EPISODE_EPISODE,
+ pItem->GetVideoInfoTag()->m_iEpisode,
+ VIDEODB_ID_EPISODE_SEASON,
+ VIDEODB_ID_EPISODE_EPISODE);
+ */
+ // select unwatched
+ // filter on older seasons, this season but with older episodes, not played yet
+ // need to cast as INT because the column type is VARCHAR... why? column is defined as INT in 'SDbTableOffsets DbEpisodeOffsets'
+ CStdString strSQL = PrepareSQL("select episodeview.c%02d from episodeview where idShow = %i and (c%02d < %i or (c%02d = %i and c%02d < %i)) and (playCount <1 or playCount isNull) order by CAST (c%02d as INT) asc, CAST (c%02d as INT) asc limit 1", VIDEODB_ID_EPISODE_BASEPATH, pItem->GetVideoInfoTag()->m_iIdShow, VIDEODB_ID_EPISODE_SEASON, pItem->GetVideoInfoTag()->m_iSeason, VIDEODB_ID_EPISODE_SEASON, pItem->GetVideoInfoTag()->m_iSeason, VIDEODB_ID_EPISODE_EPISODE, pItem->GetVideoInfoTag()->m_iEpisode, VIDEODB_ID_EPISODE_SEASON, VIDEODB_ID_EPISODE_EPISODE);
+
+ CLog::Log(LOGDEBUG, "%s strSQL: %s", __FUNCTION__, strSQL.c_str());
+
+ // execute query
+ m_pDS->query(strSQL.c_str());
+ CStdString strPath = "";
+ // if there are rows returned
+ if (!m_pDS->eof())
+ {
+ strPath = m_pDS->fv(PrepareSQL("episodeview.c%02d",VIDEODB_ID_EPISODE_BASEPATH)).get_asString();
+ CLog::Log(LOGDEBUG, "%s : First unseen episode = %s", __FUNCTION__, strPath.c_str());
+
+ //no rows returned
+ } else {
+ CLog::Log(LOGDEBUG, "%s : All previous episodes are watched", __FUNCTION__);
+ //strPath = "";
+ }
+ //close dataset
+ m_pDS->close();
+
+ bool bIsFolder = false;
+ CFileItem item(strPath, bIsFolder);
+
+ return item;
+}
+
/// \brief GetVideoSettings() obtains any saved video settings for the current file.
/// \retval Returns true if the settings exist, false otherwise.
bool CVideoDatabase::GetVideoSettings(const CStdString &strFilenameAndPath, CVideoSettings &settings)
View
3  xbmc/video/VideoDatabase.h
@@ -58,6 +58,7 @@ namespace dbiplus
#endif
typedef std::vector<CVideoInfoTag> VECMOVIES;
+typedef boost::shared_ptr<CFileItem> CFileItemPtr;
namespace VIDEO
{
@@ -688,6 +689,8 @@ class CVideoDatabase : public CDatabase
virtual bool GetFilter(CDbUrl &videoUrl, Filter &filter, SortDescription &sorting);
+ CFileItem GetPreviousEpisodeNotWatched(CFileItemPtr& pItem);
+
protected:
friend class CEdenVideoArtUpdater;
int GetMovieId(const CStdString& strFilenameAndPath);
View
45 xbmc/video/windows/GUIWindowVideoBase.cpp
@@ -1542,7 +1542,52 @@ bool CGUIWindowVideoBase::OnPlayMedia(int iItem)
}
}
}
+ else
+ {
+ if(g_guiSettings.GetBool("videolibrary.checkpreviousepisodenotwatched"))
+ {
+ CVideoDatabase db;
+ // open db connection
+ db.Open();
+
+ // get not watched episodes
+ CFileItem nItem(db.GetPreviousEpisodeNotWatched(pItem).GetPath(),false);
+
+ //close db
+ db.Close();
+
+ //if an item is found
+ if(!nItem.GetPath().IsEmpty())
+ {
+ bool bCanceled = false;
+ // user YesNo dialog box, do we want to use the first unseen episode or not?
+ if (CGUIDialogYesNo::ShowAndGetInput(20466,20467,20022,20022,bCanceled))
+ {
+ // user accepted, update item with new episode to play
+ CLog::Log(LOGDEBUG, "%s : user 'yes'", __FUNCTION__);
+
+ item.Reset();
+ item.SetPath(nItem.GetPath());
+ }
+ else
+ {
+ if (bCanceled)
+ {
+ // user canceled, do nothing
+ CLog::Log(LOGDEBUG,"%s : user canceled", __FUNCTION__);
+ return true; //or should I return false?
+ }
+ else
+ {
+ // user declined, don't change the item
+ CLog::Log(LOGDEBUG, "%s : user 'no'", __FUNCTION__);
+ }
+ }
+ }
+ }
+ }
+ //play item
PlayMovie(&item);
return true;
Something went wrong with that request. Please try again.