Skip to content

Commit

Permalink
Improved continuation of sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
LazyTarget committed Jun 11, 2015
1 parent 8871b76 commit 69c0453
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions PollingEngine/Implementations/XbmcPoller/XbmcPoller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@ public async Task<WatchSessionInfo> GetLastSession()
sessionVideo.EndTime = record2.GetDateTime(cEndTime2);
sessionVideo.SessionVideoCreated = true;
session.Videos.Add(sessionVideo);
session.ActiveVideo = sessionVideo;
sessionVideo.Video = await GetVideo(sessionVideo.ViewedVideoID);
}
}
}
Expand All @@ -826,6 +828,56 @@ public async Task<WatchSessionInfo> GetLastSession()
}


public async Task<VideoItemInfo> GetVideo(long videoID)
{
try
{
var connectionString = _settings.ConnString;
var odbc = new OdbcConnection(connectionString);
if (odbc.State != ConnectionState.Open)
odbc.Open();

var cmd = odbc.CreateCommand();
cmd.CommandText = "SELECT * FROM Kodi_ViewedVideos " +
"WHERE ID = ?";
cmd.Parameters.AddWithValue("@VideoID", videoID);
VideoItemInfo video = null;
using (OdbcDataReader reader = cmd.ExecuteReader())
{
//var cVideoID = reader.GetOrdinal("ID");
var cType = reader.GetOrdinal("Type");
var cTitle = reader.GetOrdinal("Title");
var cShowtitle = reader.GetOrdinal("Showtitle");
var cLabel = reader.GetOrdinal("Label");
var cRuntime = reader.GetOrdinal("Runtime");
var cSeason = reader.GetOrdinal("Season");
var cEpisode = reader.GetOrdinal("Episode");
var cThumbnail = reader.GetOrdinal("Thumbnail");
foreach (IDataRecord record in reader)
{
// todo: null protection
video = new VideoItemInfo();
video.Type = record.GetString(cType);
video.Title = record.GetString(cTitle);
video.Showtitle = record.GetString(cShowtitle);
video.Label = record.GetString(cLabel);
video.Runtime = TimeSpan.FromSeconds(record.GetInt32(cRuntime));
video.Season = record.GetInt32(cSeason);
video.Episode = record.GetInt32(cEpisode);
video.Thumbnail = record.GetString(cThumbnail);
return video;
}
}
return video;
}
catch (Exception ex)
{
Console.WriteLine("Failed to create odbc entry, Error: " + ex.Message);
throw;
}
}


public async Task StoreSessionVideo(CrSessionVideo sessionVideo)
{
try
Expand Down

0 comments on commit 69c0453

Please sign in to comment.