/// <summary> /// Sets the image path. /// </summary> /// <param name="item">The item.</param> /// <param name="imageType">Type of the image.</param> /// <param name="file">The file.</param> public static void SetImagePath(this BaseItem item, ImageType imageType, FileSystemMetadata file) { item.SetImagePath(imageType, 0, file); }
/// <summary> /// Gets the image path. /// </summary> /// <param name="item">The item.</param> /// <param name="imageType">Type of the image.</param> /// <returns>System.String.</returns> public static string GetImagePath(this BaseItem item, ImageType imageType) { return(item.GetImagePath(imageType, 0)); }
public static bool HasImage(this BaseItem item, ImageType imageType) { return(item.HasImage(imageType, 0)); }
private UserView GetUserView(string type, string localizationKey, string sortName, BaseItem parent) { return(_userViewManager.GetUserSubView(parent.Id, type, localizationKey, sortName)); }
private UserView GetUserViewWithName(string name, string type, string sortName, BaseItem parent) { return(_userViewManager.GetUserSubView(parent.Id, parent.Id.ToString("N", CultureInfo.InvariantCulture), type, sortName)); }
public static bool Filter(BaseItem item, User user, InternalItemsQuery query, IUserDataManager userDataManager, ILibraryManager libraryManager) { if (query.MediaTypes.Length > 0 && !query.MediaTypes.Contains(item.MediaType ?? string.Empty, StringComparer.OrdinalIgnoreCase)) { return(false); } if (query.IncludeItemTypes.Length > 0 && !query.IncludeItemTypes.Contains(item.GetClientTypeName(), StringComparer.OrdinalIgnoreCase)) { return(false); } if (query.ExcludeItemTypes.Length > 0 && query.ExcludeItemTypes.Contains(item.GetClientTypeName(), StringComparer.OrdinalIgnoreCase)) { return(false); } if (query.IsVirtualItem.HasValue && item.IsVirtualItem != query.IsVirtualItem.Value) { return(false); } if (query.IsFolder.HasValue && query.IsFolder.Value != item.IsFolder) { return(false); } UserItemData userData = null; if (query.IsLiked.HasValue) { userData = userDataManager.GetUserData(user, item); if (!userData.Likes.HasValue || userData.Likes != query.IsLiked.Value) { return(false); } } if (query.IsFavoriteOrLiked.HasValue) { userData = userData ?? userDataManager.GetUserData(user, item); var isFavoriteOrLiked = userData.IsFavorite || (userData.Likes ?? false); if (isFavoriteOrLiked != query.IsFavoriteOrLiked.Value) { return(false); } } if (query.IsFavorite.HasValue) { userData = userData ?? userDataManager.GetUserData(user, item); if (userData.IsFavorite != query.IsFavorite.Value) { return(false); } } if (query.IsResumable.HasValue) { userData = userData ?? userDataManager.GetUserData(user, item); var isResumable = userData.PlaybackPositionTicks > 0; if (isResumable != query.IsResumable.Value) { return(false); } } if (query.IsPlayed.HasValue) { if (item.IsPlayed(user) != query.IsPlayed.Value) { return(false); } } // Filter by Video3DFormat if (query.Is3D.HasValue) { var val = query.Is3D.Value; var video = item as Video; if (video == null || val != video.Video3DFormat.HasValue) { return(false); } } /* * f**k - fix this * if (query.IsHD.HasValue) * { * if (item.IsHD != query.IsHD.Value) * { * return false; * } * } */ if (query.IsLocked.HasValue) { var val = query.IsLocked.Value; if (item.IsLocked != val) { return(false); } } if (query.HasOverview.HasValue) { var filterValue = query.HasOverview.Value; var hasValue = !string.IsNullOrEmpty(item.Overview); if (hasValue != filterValue) { return(false); } } if (query.HasImdbId.HasValue) { var filterValue = query.HasImdbId.Value; var hasValue = !string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Imdb)); if (hasValue != filterValue) { return(false); } } if (query.HasTmdbId.HasValue) { var filterValue = query.HasTmdbId.Value; var hasValue = !string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tmdb)); if (hasValue != filterValue) { return(false); } } if (query.HasTvdbId.HasValue) { var filterValue = query.HasTvdbId.Value; var hasValue = !string.IsNullOrEmpty(item.GetProviderId(MetadataProviders.Tvdb)); if (hasValue != filterValue) { return(false); } } if (query.HasOfficialRating.HasValue) { var filterValue = query.HasOfficialRating.Value; var hasValue = !string.IsNullOrEmpty(item.OfficialRating); if (hasValue != filterValue) { return(false); } } if (query.IsPlaceHolder.HasValue) { var filterValue = query.IsPlaceHolder.Value; var isPlaceHolder = false; var hasPlaceHolder = item as ISupportsPlaceHolders; if (hasPlaceHolder != null) { isPlaceHolder = hasPlaceHolder.IsPlaceHolder; } if (isPlaceHolder != filterValue) { return(false); } } if (query.HasSpecialFeature.HasValue) { var filterValue = query.HasSpecialFeature.Value; var movie = item as IHasSpecialFeatures; if (movie != null) { var ok = filterValue ? movie.SpecialFeatureIds.Length > 0 : movie.SpecialFeatureIds.Length == 0; if (!ok) { return(false); } } else { return(false); } } if (query.HasSubtitles.HasValue) { var val = query.HasSubtitles.Value; var video = item as Video; if (video == null || val != video.HasSubtitles) { return(false); } } if (query.HasParentalRating.HasValue) { var val = query.HasParentalRating.Value; var rating = item.CustomRating; if (string.IsNullOrEmpty(rating)) { rating = item.OfficialRating; } if (val) { if (string.IsNullOrEmpty(rating)) { return(false); } } else { if (!string.IsNullOrEmpty(rating)) { return(false); } } } if (query.HasTrailer.HasValue) { var val = query.HasTrailer.Value; var trailerCount = 0; var hasTrailers = item as IHasTrailers; if (hasTrailers != null) { trailerCount = hasTrailers.GetTrailerIds().Count; } var ok = val ? trailerCount > 0 : trailerCount == 0; if (!ok) { return(false); } } if (query.HasThemeSong.HasValue) { var filterValue = query.HasThemeSong.Value; var themeCount = item.ThemeSongIds.Length; var ok = filterValue ? themeCount > 0 : themeCount == 0; if (!ok) { return(false); } } if (query.HasThemeVideo.HasValue) { var filterValue = query.HasThemeVideo.Value; var themeCount = item.ThemeVideoIds.Length; var ok = filterValue ? themeCount > 0 : themeCount == 0; if (!ok) { return(false); } } // Apply genre filter if (query.Genres.Length > 0 && !query.Genres.Any(v => item.Genres.Contains(v, StringComparer.OrdinalIgnoreCase))) { return(false); } // Filter by VideoType if (query.VideoTypes.Length > 0) { var video = item as Video; if (video == null || !query.VideoTypes.Contains(video.VideoType)) { return(false); } } if (query.ImageTypes.Length > 0 && !query.ImageTypes.Any(item.HasImage)) { return(false); } // Apply studio filter if (query.StudioIds.Length > 0 && !query.StudioIds.Any(id => { var studioItem = libraryManager.GetItemById(id); return(studioItem != null && item.Studios.Contains(studioItem.Name, StringComparer.OrdinalIgnoreCase)); })) { return(false); } // Apply genre filter if (query.GenreIds.Length > 0 && !query.GenreIds.Any(id => { var genreItem = libraryManager.GetItemById(id); return(genreItem != null && item.Genres.Contains(genreItem.Name, StringComparer.OrdinalIgnoreCase)); })) { return(false); } // Apply year filter if (query.Years.Length > 0) { if (!(item.ProductionYear.HasValue && query.Years.Contains(item.ProductionYear.Value))) { return(false); } } // Apply official rating filter if (query.OfficialRatings.Length > 0 && !query.OfficialRatings.Contains(item.OfficialRating ?? string.Empty)) { return(false); } if (query.ItemIds.Length > 0) { if (!query.ItemIds.Contains(item.Id)) { return(false); } } // Apply tag filter var tags = query.Tags; if (tags.Length > 0) { if (!tags.Any(v => item.Tags.Contains(v, StringComparer.OrdinalIgnoreCase))) { return(false); } } if (query.MinCommunityRating.HasValue) { var val = query.MinCommunityRating.Value; if (!(item.CommunityRating.HasValue && item.CommunityRating >= val)) { return(false); } } if (query.MinCriticRating.HasValue) { var val = query.MinCriticRating.Value; if (!(item.CriticRating.HasValue && item.CriticRating >= val)) { return(false); } } if (query.MinIndexNumber.HasValue) { var val = query.MinIndexNumber.Value; if (!(item.IndexNumber.HasValue && item.IndexNumber.Value >= val)) { return(false); } } if (query.MinPremiereDate.HasValue) { var val = query.MinPremiereDate.Value; if (!(item.PremiereDate.HasValue && item.PremiereDate.Value >= val)) { return(false); } } if (query.MaxPremiereDate.HasValue) { var val = query.MaxPremiereDate.Value; if (!(item.PremiereDate.HasValue && item.PremiereDate.Value <= val)) { return(false); } } if (query.ParentIndexNumber.HasValue) { var filterValue = query.ParentIndexNumber.Value; if (item.ParentIndexNumber.HasValue && item.ParentIndexNumber.Value != filterValue) { return(false); } } if (query.SeriesStatuses.Length > 0) { var ok = new[] { item }.OfType <Series>().Any(p => p.Status.HasValue && query.SeriesStatuses.Contains(p.Status.Value)); if (!ok) { return(false); } } if (query.AiredDuringSeason.HasValue) { var episode = item as Episode; if (episode == null) { return(false); } if (!Series.FilterEpisodesBySeason(new[] { episode }, query.AiredDuringSeason.Value, true).Any()) { return(false); } } return(true); }
public static bool FilterItem(BaseItem item, InternalItemsQuery query) { return(Filter(item, query.User, query, BaseItem.UserDataManager, BaseItem.LibraryManager)); }
/// <summary> /// Compare our current children (presumably just read from the repo) with the current state of the file system and adjust for any changes /// ***Currently does not contain logic to maintain items that are unavailable in the file system*** /// </summary> /// <param name="progress">The progress.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <param name="recursive">if set to <c>true</c> [recursive].</param> /// <param name="forceRefreshMetadata">if set to <c>true</c> [force refresh metadata].</param> /// <returns>Task.</returns> protected async virtual Task ValidateChildrenInternal(IProgress <double> progress, CancellationToken cancellationToken, bool?recursive = null, bool forceRefreshMetadata = false) { var locationType = LocationType; // Nothing to do here if (locationType == LocationType.Remote || locationType == LocationType.Virtual) { return; } cancellationToken.ThrowIfCancellationRequested(); IEnumerable <BaseItem> nonCachedChildren; try { nonCachedChildren = GetNonCachedChildren(); } catch (IOException ex) { nonCachedChildren = new BaseItem[] { }; Logger.ErrorException("Error getting file system entries for {0}", ex, Path); } if (nonCachedChildren == null) { return; //nothing to validate } progress.Report(5); //build a dictionary of the current children we have now by Id so we can compare quickly and easily var currentChildren = ActualChildren; //create a list for our validated children var validChildren = new ConcurrentBag <Tuple <BaseItem, bool> >(); var newItems = new ConcurrentBag <BaseItem>(); cancellationToken.ThrowIfCancellationRequested(); var options = new ParallelOptions { MaxDegreeOfParallelism = 20 }; Parallel.ForEach(nonCachedChildren, options, child => { BaseItem currentChild; if (currentChildren.TryGetValue(child.Id, out currentChild)) { currentChild.ResolveArgs = child.ResolveArgs; //existing item - check if it has changed if (currentChild.HasChanged(child)) { EntityResolutionHelper.EnsureDates(currentChild, child.ResolveArgs); validChildren.Add(new Tuple <BaseItem, bool>(currentChild, true)); } else { validChildren.Add(new Tuple <BaseItem, bool>(currentChild, false)); } currentChild.IsOffline = false; } else { //brand new item - needs to be added newItems.Add(child); validChildren.Add(new Tuple <BaseItem, bool>(child, true)); } }); // If any items were added or removed.... if (!newItems.IsEmpty || currentChildren.Count != validChildren.Count) { var newChildren = validChildren.Select(c => c.Item1).ToList(); //that's all the new and changed ones - now see if there are any that are missing var itemsRemoved = currentChildren.Values.Except(newChildren).ToList(); foreach (var item in itemsRemoved) { if (IsRootPathAvailable(item.Path)) { item.IsOffline = false; BaseItem removed; if (!_children.TryRemove(item.Id, out removed)) { Logger.Error("Failed to remove {0}", item.Name); } else { LibraryManager.ReportItemRemoved(item); } } else { item.IsOffline = true; validChildren.Add(new Tuple <BaseItem, bool>(item, false)); } } await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false); foreach (var item in newItems) { if (!_children.TryAdd(item.Id, item)) { Logger.Error("Failed to add {0}", item.Name); } else { Logger.Debug("** " + item.Name + " Added to library."); } } await ItemRepository.SaveChildren(Id, _children.Values.ToList().Select(i => i.Id), cancellationToken).ConfigureAwait(false); //force the indexes to rebuild next time IndexCache.Clear(); } progress.Report(10); cancellationToken.ThrowIfCancellationRequested(); await RefreshChildren(validChildren, progress, cancellationToken, recursive, forceRefreshMetadata).ConfigureAwait(false); progress.Report(100); }