diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs index d8b7ce2ef3..d75b8947a8 100644 --- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs +++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs @@ -347,7 +347,7 @@ namespace MediaBrowser.Api.Playback.Progressive outputHeaders[item.Key] = item.Value; } - Func streamWriter = stream => new ProgressiveFileCopier(FileSystem, job, Logger).StreamFile(outputPath, stream); + Func streamWriter = stream => new ProgressiveFileCopier(FileSystem, job, Logger).StreamFile(outputPath, stream, CancellationToken.None); return ResultFactory.GetAsyncStreamWriter(streamWriter, outputHeaders); } diff --git a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs index bf543579f7..13d59240f5 100644 --- a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs +++ b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs @@ -3,88 +3,12 @@ using ServiceStack.Web; using System; using System.Collections.Generic; using System.IO; +using System.Threading; using System.Threading.Tasks; using CommonIO; namespace MediaBrowser.Api.Playback.Progressive { - public class ProgressiveStreamWriter : IStreamWriter, IHasOptions - { - private string Path { get; set; } - private ILogger Logger { get; set; } - private readonly IFileSystem _fileSystem; - private readonly TranscodingJob _job; - - /// - /// The _options - /// - private readonly IDictionary _options = new Dictionary(); - /// - /// Gets the options. - /// - /// The options. - public IDictionary Options - { - get { return _options; } - } - - /// - /// Initializes a new instance of the class. - /// - /// The path. - /// The logger. - /// The file system. - public ProgressiveStreamWriter(string path, ILogger logger, IFileSystem fileSystem, TranscodingJob job) - { - Path = path; - Logger = logger; - _fileSystem = fileSystem; - _job = job; - } - - /// - /// Writes to. - /// - /// The response stream. - public void WriteTo(Stream responseStream) - { - var task = WriteToAsync(responseStream); - Task.WaitAll(task); - } - - /// - /// Writes to. - /// - /// The response stream. - public async Task WriteToAsync(Stream responseStream) - { - try - { - await new ProgressiveFileCopier(_fileSystem, _job, Logger).StreamFile(Path, responseStream).ConfigureAwait(false); - } - catch (IOException) - { - // These error are always the same so don't dump the whole stack trace - Logger.Error("Error streaming media. The client has most likely disconnected or transcoding has failed."); - - throw; - } - catch (Exception ex) - { - Logger.ErrorException("Error streaming media. The client has most likely disconnected or transcoding has failed.", ex); - - throw; - } - finally - { - if (_job != null) - { - ApiEntryPoint.Instance.OnTranscodeEndRequest(_job); - } - } - } - } - public class ProgressiveFileCopier { private readonly IFileSystem _fileSystem; @@ -103,22 +27,18 @@ namespace MediaBrowser.Api.Playback.Progressive _logger = logger; } - public async Task StreamFile(string path, Stream outputStream) + public async Task StreamFile(string path, Stream outputStream, CancellationToken cancellationToken) { var eofCount = 0; - long position = 0; using (var fs = _fileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true)) { while (eofCount < 15) { - await CopyToInternal(fs, outputStream, BufferSize).ConfigureAwait(false); + var bytesRead = await CopyToAsyncInternal(fs, outputStream, BufferSize, cancellationToken).ConfigureAwait(false); - var fsPosition = fs.Position; - - var bytesRead = fsPosition - position; - - //Logger.Debug("Streamed {0} bytes from file {1}", bytesRead, path); + //var position = fs.Position; + //_logger.Debug("Streamed {0} bytes to position {1} from file {2}", bytesRead, position, path); if (bytesRead == 0) { @@ -126,57 +46,36 @@ namespace MediaBrowser.Api.Playback.Progressive { eofCount++; } - await Task.Delay(100).ConfigureAwait(false); + await Task.Delay(100, cancellationToken).ConfigureAwait(false); } else { eofCount = 0; } - - position = fsPosition; } } } - private async Task CopyToInternal(Stream source, Stream destination, int bufferSize) + private async Task CopyToAsyncInternal(Stream source, Stream destination, Int32 bufferSize, CancellationToken cancellationToken) { - var array = new byte[bufferSize]; - int count; - while ((count = await source.ReadAsync(array, 0, array.Length).ConfigureAwait(false)) != 0) + byte[] buffer = new byte[bufferSize]; + int bytesRead; + int totalBytesRead = 0; + + while ((bytesRead = await source.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0) { - //if (_job != null) - //{ - // var didPause = false; - // var totalPauseTime = 0; + await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false); - // if (_job.IsUserPaused) - // { - // _logger.Debug("Pausing writing to network stream while user has paused playback."); - - // while (_job.IsUserPaused && totalPauseTime < 30000) - // { - // didPause = true; - // var pauseTime = 500; - // totalPauseTime += pauseTime; - // await Task.Delay(pauseTime).ConfigureAwait(false); - // } - // } - - // if (didPause) - // { - // _logger.Debug("Resuming writing to network stream due to user unpausing playback."); - // } - //} - - await destination.WriteAsync(array, 0, count).ConfigureAwait(false); - - _bytesWritten += count; + _bytesWritten += bytesRead; + totalBytesRead += bytesRead; if (_job != null) { _job.BytesDownloaded = Math.Max(_job.BytesDownloaded ?? _bytesWritten, _bytesWritten); } } + + return totalBytesRead; } } } diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index b3df34c4dc..1897511af7 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -46,6 +46,12 @@ namespace MediaBrowser.Controller.Entities.Audio } } + [IgnoreDataMember] + public override bool EnableForceSaveOnDateModifiedChange + { + get { return true; } + } + public Audio() { Artists = new List(); diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 0860cb61cb..c7a6b75ff2 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -455,7 +455,10 @@ namespace MediaBrowser.Controller.Entities public DateTime DateLastRefreshed { get; set; } [IgnoreDataMember] - public DateTime? DateModifiedDuringLastRefresh { get; set; } + public virtual bool EnableForceSaveOnDateModifiedChange + { + get { return false; } + } /// /// The logger diff --git a/MediaBrowser.Controller/Entities/Book.cs b/MediaBrowser.Controller/Entities/Book.cs index 2ca56bc706..59ab954378 100644 --- a/MediaBrowser.Controller/Entities/Book.cs +++ b/MediaBrowser.Controller/Entities/Book.cs @@ -34,6 +34,12 @@ namespace MediaBrowser.Controller.Entities return SeriesName; } + [IgnoreDataMember] + public override bool EnableForceSaveOnDateModifiedChange + { + get { return true; } + } + public Guid? FindSeriesId() { return SeriesId; diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 89b9479e7b..0397e9a88e 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -373,13 +373,6 @@ namespace MediaBrowser.Controller.Entities if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child)) { - var currentChildLocationType = currentChild.LocationType; - if (currentChildLocationType != LocationType.Remote && - currentChildLocationType != LocationType.Virtual) - { - currentChild.DateModified = child.DateModified; - } - await UpdateIsOffline(currentChild, false).ConfigureAwait(false); validChildren.Add(currentChild); diff --git a/MediaBrowser.Controller/Entities/Game.cs b/MediaBrowser.Controller/Entities/Game.cs index 317c71529e..54386a1795 100644 --- a/MediaBrowser.Controller/Entities/Game.cs +++ b/MediaBrowser.Controller/Entities/Game.cs @@ -4,6 +4,7 @@ using MediaBrowser.Model.Entities; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; namespace MediaBrowser.Controller.Entities { @@ -32,6 +33,12 @@ namespace MediaBrowser.Controller.Entities locationType != LocationType.Virtual; } + [IgnoreDataMember] + public override bool EnableForceSaveOnDateModifiedChange + { + get { return true; } + } + /// /// Gets or sets the remote trailers. /// @@ -42,6 +49,7 @@ namespace MediaBrowser.Controller.Entities /// Gets the type of the media. /// /// The type of the media. + [IgnoreDataMember] public override string MediaType { get { return Model.Entities.MediaType.Game; } diff --git a/MediaBrowser.Controller/Entities/IHasImages.cs b/MediaBrowser.Controller/Entities/IHasImages.cs index 897250caa1..2267480985 100644 --- a/MediaBrowser.Controller/Entities/IHasImages.cs +++ b/MediaBrowser.Controller/Entities/IHasImages.cs @@ -207,8 +207,6 @@ namespace MediaBrowser.Controller.Entities /// The image. /// The index. void SetImage(ItemImageInfo image, int index); - - DateTime? DateModifiedDuringLastRefresh { get; set; } } public static class HasImagesExtensions diff --git a/MediaBrowser.Controller/Entities/IHasMetadata.cs b/MediaBrowser.Controller/Entities/IHasMetadata.cs index c7940c8a97..378c4a390b 100644 --- a/MediaBrowser.Controller/Entities/IHasMetadata.cs +++ b/MediaBrowser.Controller/Entities/IHasMetadata.cs @@ -17,7 +17,7 @@ namespace MediaBrowser.Controller.Entities /// Gets the date modified. /// /// The date modified. - DateTime DateModified { get; } + DateTime DateModified { get; set; } /// /// Gets or sets the date last saved. @@ -51,5 +51,7 @@ namespace MediaBrowser.Controller.Entities bool SupportsPeople { get; } bool RequiresRefresh(); + + bool EnableForceSaveOnDateModifiedChange { get; } } } diff --git a/MediaBrowser.Controller/Entities/Photo.cs b/MediaBrowser.Controller/Entities/Photo.cs index de756563d8..804ea04a59 100644 --- a/MediaBrowser.Controller/Entities/Photo.cs +++ b/MediaBrowser.Controller/Entities/Photo.cs @@ -51,6 +51,12 @@ namespace MediaBrowser.Controller.Entities } } + [IgnoreDataMember] + public override bool EnableForceSaveOnDateModifiedChange + { + get { return true; } + } + public override bool CanDownload() { return true; diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 73c893dd6e..eba1e466a2 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -58,6 +58,12 @@ namespace MediaBrowser.Controller.Entities } } + [IgnoreDataMember] + public override bool EnableForceSaveOnDateModifiedChange + { + get { return true; } + } + public int? TotalBitrate { get; set; } public ExtraType? ExtraType { get; set; } diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.cs index c057c97071..e7e3323c2b 100644 --- a/MediaBrowser.Controller/Providers/DirectoryService.cs +++ b/MediaBrowser.Controller/Providers/DirectoryService.cs @@ -102,6 +102,12 @@ namespace MediaBrowser.Controller.Providers { var directory = Path.GetDirectoryName(path); + if (string.IsNullOrWhiteSpace(directory)) + { + _logger.Debug("Parent path is null for {0}", path); + return null; + } + var dict = GetFileSystemDictionary(directory, false); FileSystemMetadata entry; diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index 678d495cbc..9776c4e2f5 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -143,6 +143,22 @@ namespace MediaBrowser.Providers.Manager var beforeSaveResult = await BeforeSave(itemOfType, isFirstRefresh || refreshOptions.ReplaceAllMetadata || refreshOptions.MetadataRefreshMode == MetadataRefreshMode.FullRefresh || requiresRefresh, updateType).ConfigureAwait(false); updateType = updateType | beforeSaveResult; + if (item.LocationType == LocationType.FileSystem) + { + var file = refreshOptions.DirectoryService.GetFile(item.Path); + if (file != null) + { + var fileLastWriteTime = file.LastWriteTimeUtc; + if (item.EnableForceSaveOnDateModifiedChange && fileLastWriteTime != item.DateModified) + { + Logger.Debug("Date modified for {0}. Old date {1} new date {2} Id {3}", item.Path, item.DateModified, fileLastWriteTime, item.Id); + requiresRefresh = true; + } + + item.DateModified = fileLastWriteTime; + } + } + // Save if changes were made, or it's never been saved before if (refreshOptions.ForceSave || updateType > ItemUpdateType.None || isFirstRefresh || refreshOptions.ReplaceAllMetadata || requiresRefresh) { @@ -155,12 +171,10 @@ namespace MediaBrowser.Providers.Manager if (hasRefreshedMetadata && hasRefreshedImages) { item.DateLastRefreshed = DateTime.UtcNow; - item.DateModifiedDuringLastRefresh = item.DateModified; } else { item.DateLastRefreshed = default(DateTime); - item.DateModifiedDuringLastRefresh = null; } // Save to database diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index bec9280b3a..6c79189887 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -167,9 +167,10 @@ namespace MediaBrowser.Providers.MediaInfo public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) { - if (item.DateModifiedDuringLastRefresh.HasValue) + var file = directoryService.GetFile(item.Path); + if (file != null && file.LastWriteTimeUtc != item.DateModified) { - return item.DateModifiedDuringLastRefresh.Value != item.DateModified; + return true; } return false; diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs index b89b0b9256..11280cff21 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeProvider.cs @@ -171,12 +171,10 @@ namespace MediaBrowser.Providers.MediaInfo public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) { - if (item.DateModifiedDuringLastRefresh.HasValue) + var file = directoryService.GetFile(item.Path); + if (file != null && file.LastWriteTimeUtc != item.DateModified) { - if (item.DateModifiedDuringLastRefresh.Value != item.DateModified) - { - return true; - } + return true; } if (item.SupportsLocalMetadata) diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index 9a1f072cd2..5fc3630627 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -195,12 +195,10 @@ namespace MediaBrowser.Providers.MediaInfo public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) { - if (item.DateModifiedDuringLastRefresh.HasValue) + var file = directoryService.GetFile(item.Path); + if (file != null && file.LastWriteTimeUtc != item.DateModified) { - if (item.DateModifiedDuringLastRefresh.Value != item.DateModified) - { - return true; - } + return true; } return false; diff --git a/MediaBrowser.Providers/Photos/PhotoProvider.cs b/MediaBrowser.Providers/Photos/PhotoProvider.cs index 882363b2f8..619b726368 100644 --- a/MediaBrowser.Providers/Photos/PhotoProvider.cs +++ b/MediaBrowser.Providers/Photos/PhotoProvider.cs @@ -154,9 +154,10 @@ namespace MediaBrowser.Providers.Photos public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) { - if (item.DateModifiedDuringLastRefresh.HasValue) + var file = directoryService.GetFile(item.Path); + if (file != null && file.LastWriteTimeUtc != item.DateModified) { - return item.DateModifiedDuringLastRefresh.Value != item.DateModified; + return true; } return false; diff --git a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs index 60e7e2df33..9f949db92a 100644 --- a/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs +++ b/MediaBrowser.Server.Implementations/Library/ResolverHelper.cs @@ -44,7 +44,6 @@ namespace MediaBrowser.Server.Implementations.Library // Make sure DateCreated and DateModified have values var fileInfo = directoryService.GetFile(item.Path); - item.DateModified = fileSystem.GetLastWriteTimeUtc(fileInfo); SetDateCreated(item, fileSystem, fileInfo); EnsureName(item, fileInfo); @@ -80,7 +79,7 @@ namespace MediaBrowser.Server.Implementations.Library item.GetParents().Any(i => i.IsLocked); // Make sure DateCreated and DateModified have values - EnsureDates(fileSystem, item, args, true); + EnsureDates(fileSystem, item, args); } /// @@ -125,8 +124,7 @@ namespace MediaBrowser.Server.Implementations.Library /// The file system. /// The item. /// The args. - /// if set to true [include creation time]. - private static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args, bool includeCreationTime) + private static void EnsureDates(IFileSystem fileSystem, BaseItem item, ItemResolveArgs args) { if (fileSystem == null) { @@ -148,12 +146,7 @@ namespace MediaBrowser.Server.Implementations.Library if (childData != null) { - if (includeCreationTime) - { - SetDateCreated(item, fileSystem, childData); - } - - item.DateModified = fileSystem.GetLastWriteTimeUtc(childData); + SetDateCreated(item, fileSystem, childData); } else { @@ -161,21 +154,13 @@ namespace MediaBrowser.Server.Implementations.Library if (fileData.Exists) { - if (includeCreationTime) - { - SetDateCreated(item, fileSystem, fileData); - } - item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData); + SetDateCreated(item, fileSystem, fileData); } } } else { - if (includeCreationTime) - { - SetDateCreated(item, fileSystem, args.FileInfo); - } - item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo); + SetDateCreated(item, fileSystem, args.FileInfo); } } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 7f556cfb06..63dd29e0dd 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -257,7 +257,6 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "TrailerTypes", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "CriticRating", "Float"); _connection.AddColumn(Logger, "TypedBaseItems", "CriticRatingSummary", "Text"); - _connection.AddColumn(Logger, "TypedBaseItems", "DateModifiedDuringLastRefresh", "DATETIME"); _connection.AddColumn(Logger, "TypedBaseItems", "InheritedTags", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "CleanName", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "PresentationUniqueKey", "Text"); @@ -402,7 +401,6 @@ namespace MediaBrowser.Server.Implementations.Persistence "Tags", "SourceType", "TrailerTypes", - "DateModifiedDuringLastRefresh", "OriginalTitle", "PrimaryVersionId", "DateLastMediaAdded", @@ -523,7 +521,6 @@ namespace MediaBrowser.Server.Implementations.Persistence "TrailerTypes", "CriticRating", "CriticRatingSummary", - "DateModifiedDuringLastRefresh", "InheritedTags", "CleanName", "PresentationUniqueKey", @@ -902,15 +899,6 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.CriticRating; _saveItemCommand.GetParameter(index++).Value = item.CriticRatingSummary; - if (!item.DateModifiedDuringLastRefresh.HasValue || item.DateModifiedDuringLastRefresh.Value == default(DateTime)) - { - _saveItemCommand.GetParameter(index++).Value = null; - } - else - { - _saveItemCommand.GetParameter(index++).Value = item.DateModifiedDuringLastRefresh.Value; - } - var inheritedTags = item.GetInheritedTags(); if (inheritedTags.Count > 0) { @@ -1370,88 +1358,101 @@ namespace MediaBrowser.Server.Implementations.Persistence } } - if (!reader.IsDBNull(51)) - { - item.DateModifiedDuringLastRefresh = reader.GetDateTime(51).ToUniversalTime(); - } + var index = 51; - if (!reader.IsDBNull(52)) + if (!reader.IsDBNull(index)) { - item.OriginalTitle = reader.GetString(52); + item.OriginalTitle = reader.GetString(index); } + index++; var video = item as Video; if (video != null) { - if (!reader.IsDBNull(53)) + if (!reader.IsDBNull(index)) { - video.PrimaryVersionId = reader.GetString(53); + video.PrimaryVersionId = reader.GetString(index); } } + index++; var folder = item as Folder; - if (folder != null && !reader.IsDBNull(54)) + if (folder != null && !reader.IsDBNull(index)) { - folder.DateLastMediaAdded = reader.GetDateTime(54).ToUniversalTime(); + folder.DateLastMediaAdded = reader.GetDateTime(index).ToUniversalTime(); } + index++; - if (!reader.IsDBNull(55)) + if (!reader.IsDBNull(index)) { - item.Album = reader.GetString(55); + item.Album = reader.GetString(index); } + index++; - if (!reader.IsDBNull(56)) + if (!reader.IsDBNull(index)) { - item.CriticRating = reader.GetFloat(56); + item.CriticRating = reader.GetFloat(index); } + index++; - if (!reader.IsDBNull(57)) + if (!reader.IsDBNull(index)) { - item.CriticRatingSummary = reader.GetString(57); + item.CriticRatingSummary = reader.GetString(index); } + index++; - if (!reader.IsDBNull(58)) + if (!reader.IsDBNull(index)) { - item.IsVirtualItem = reader.GetBoolean(58); + item.IsVirtualItem = reader.GetBoolean(index); } + index++; var hasSeries = item as IHasSeries; if (hasSeries != null) { - if (!reader.IsDBNull(59)) + if (!reader.IsDBNull(index)) { - hasSeries.SeriesName = reader.GetString(59); + hasSeries.SeriesName = reader.GetString(index); } } + index++; var episode = item as Episode; if (episode != null) { - if (!reader.IsDBNull(60)) + if (!reader.IsDBNull(index)) { - episode.SeasonName = reader.GetString(60); + episode.SeasonName = reader.GetString(index); } - if (!reader.IsDBNull(61)) + index++; + if (!reader.IsDBNull(index)) { - episode.SeasonId = reader.GetGuid(61); + episode.SeasonId = reader.GetGuid(index); } } + else + { + index++; + } + index++; if (hasSeries != null) { - if (!reader.IsDBNull(62)) + if (!reader.IsDBNull(index)) { - hasSeries.SeriesId = reader.GetGuid(62); + hasSeries.SeriesId = reader.GetGuid(index); } } + index++; if (hasSeries != null) { - if (!reader.IsDBNull(63)) + if (!reader.IsDBNull(index)) { - hasSeries.SeriesSortName = reader.GetString(63); + hasSeries.SeriesSortName = reader.GetString(index); } } + index++; return item; }