public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { MediaItemState state = (MediaItemState)value; string iconPath = String.Empty; switch (state) { case MediaItemState.Remote: iconPath = "../Resources/MediaItemIcons/small_remote_content_icon.png"; break; case MediaItemState.Downloading: iconPath = "../Resources/MediaItemIcons/download_in_progress.png"; break; case MediaItemState.Local: iconPath = "../Resources/MediaItemIcons/small_local_content_icon.png"; break; default: System.Diagnostics.Debug.Assert(false, "Could not determine MediaItemControl icon due to unknown item state"); break; } return(iconPath); }
private async Task <bool> ShouldScanItem( PlexLibrary library, List <PlexPathReplacement> pathReplacements, List <PlexItemEtag> existingEpisodes, PlexEpisode incoming, bool deepScan) { // deep scan will pull every episode individually from the plex api if (!deepScan) { Option <PlexItemEtag> maybeExisting = existingEpisodes.Find(ie => ie.Key == incoming.Key); string existingTag = await maybeExisting .Map(e => e.Etag ?? string.Empty) .IfNoneAsync(string.Empty); MediaItemState existingState = await maybeExisting .Map(e => e.State) .IfNoneAsync(MediaItemState.Normal); string plexPath = incoming.MediaVersions.Head().MediaFiles.Head().Path; string localPath = _plexPathReplacementService.GetReplacementPlexPath( pathReplacements, plexPath, false); // if media is unavailable, only scan if file now exists if (existingState == MediaItemState.Unavailable) { if (!_localFileSystem.FileExists(localPath)) { return(false); } } else if (existingTag == incoming.Etag) { if (!_localFileSystem.FileExists(localPath)) { foreach (int id in await _plexTelevisionRepository.FlagUnavailable(library, incoming)) { await _searchIndex.RebuildItems(_searchRepository, new List <int> { id }); } } // _logger.LogDebug("NOOP: etag has not changed for plex episode with key {Key}", incoming.Key); return(false); } // _logger.LogDebug( // "UPDATE: Etag has changed for episode {Episode}", // $"s{season.SeasonNumber}e{incoming.EpisodeMetadata.Head().EpisodeNumber}"); } return(true); }
private async Task <bool> ShouldScanItem( IMediaServerMovieRepository <TLibrary, TMovie, TEtag> movieRepository, TLibrary library, List <TEtag> existingMovies, TMovie incoming, string localPath, bool deepScan) { // deep scan will always pull every movie if (deepScan) { return(true); } Option <TEtag> maybeExisting = existingMovies.Find(m => m.MediaServerItemId == MediaServerItemId(incoming)); string existingItemId = await maybeExisting.Map(e => e.MediaServerItemId).IfNoneAsync(string.Empty); MediaItemState existingState = await maybeExisting.Map(e => e.State).IfNoneAsync(MediaItemState.Normal); if (existingState == MediaItemState.Unavailable) { // skip scanning unavailable items that still don't exist locally if (!_localFileSystem.FileExists(localPath)) { return(false); } } else if (existingItemId == MediaServerItemId(incoming)) { // item is unchanged, but file does not exist // don't scan, but mark as unavailable if (!_localFileSystem.FileExists(localPath)) { foreach (int id in await movieRepository.FlagUnavailable(library, incoming)) { await _searchIndex.RebuildItems(_searchRepository, new List <int> { id }); } } return(false); } if (maybeExisting.IsNone) { _logger.LogDebug("INSERT: new movie {Movie}", incoming.MovieMetadata.Head().Title); } else { _logger.LogDebug("UPDATE: Etag has changed for movie {Movie}", incoming.MovieMetadata.Head().Title); } return(true); }
protected MediaItem(String location, String name = null, MediaItemState state = MediaItemState.EMPTY, bool isReadOnly = false) { rwLock = new ReaderWriterLockSlim(); eventQueue = new ConcurrentQueue <string>(); this.id = Id; this.location = location; this.itemState = state; this.name = name; this.isReadOnly = isReadOnly; id = Guid.NewGuid(); }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { MediaItemState state = (MediaItemState)value; bool isLoading = false; if (state == MediaItemState.LOADING || state == MediaItemState.EMPTY || state == MediaItemState.TIMED_OUT || state == MediaItemState.RELOAD) { isLoading = true; } return(isLoading); }
protected MediaFileItem(String location, MediaItemState state = MediaItemState.EMPTY) : base(location, Path.GetFileName(location), state) { }
public MediaStreamedItem(String location, String name = null, MediaItemState state = MediaItemState.EMPTY, bool isReadOnly = true) : base(location, name, state, isReadOnly) { }
public override void readMetadata_URLock(MetadataFactory.ReadOptions options, CancellationToken token) { if (ItemState == MediaItemState.RELOAD) { reloadFromDisk_URLock(token); return; } EnterWriteLock(); ItemState = MediaItemState.LOADING; ExitWriteLock(false); MediaItemState itemState = MediaItemState.ERROR; BaseMetadata metadata = null; try { metadata = MetadataFactory.read(Location, options, token); if (metadata == null || metadata is UnknownMetadata) { itemState = MediaItemState.ERROR; } else { if (metadata.MetadataReadError != null) { if (metadata.MetadataReadError is FileNotFoundException) { itemState = MediaItemState.FILE_NOT_FOUND; } else { itemState = MediaItemState.ERROR; } } else { itemState = MediaItemState.LOADED; } } } catch (TimeoutException) { itemState = MediaItemState.TIMED_OUT; } catch (Exception e) { itemState = MediaItemState.ERROR; Logger.Log.Info("Error loading Metadata:" + Location, e); } finally { EnterWriteLock(); Metadata = metadata; ItemState = itemState; if (Metadata != null) { IsReadOnly = Metadata.IsReadOnly; checkVariables(Metadata); } ExitWriteLock(false); } }