Пример #1
0
 public bool Allowed(Item item)
 {
     if (this.Enabled && item != null)
     {
         //Logger.ReportInfo("Checking parental status on " + item.Name + " "+item.ParentalRating+" "+this.MaxAllowed.ToString());
         return(ratings.Level(item.ParentalRating) <= this.MaxAllowed);
     }
     else
     {
         return(true);
     }
 }
 private bool MatchesCriteria(BaseItem item, string value, bool unwatchedOnly, int rating, int ratingFactor)
 {
     return(item.Name != null &&
            item.Name.ToLower().Contains(value) &&
            (!unwatchedOnly ||
             (item is Media && (item as Media).PlaybackStatus.PlayCount == 0)) &&
            (rating < 0 || (ratingFactor * Ratings.Level(item.OfficialRating)) <= (ratingFactor * rating)));
 }
Пример #3
0
        public int Compare(BaseItem x, BaseItem y)
        {
            int compare = 0;

            switch (order)
            {
            case SortOrder.None:
                return(-1);

            case SortOrder.Date:
                compare = -x.DateCreated.CompareTo(y.DateCreated);
                break;

            case SortOrder.Year:

                var xProductionYear = x.PremierDate != DateTime.MinValue ? x.PremierDate : new DateTime(Convert.ToInt16(x.ProductionYear ?? 1900), 1, 1);
                var yProductionYear = y.PremierDate != DateTime.MinValue ? y.PremierDate : new DateTime(Convert.ToInt16(y.ProductionYear ?? 1900), 1, 1);

                //Logging.Logger.ReportInfo("=========== x.PremierDate: {0} y.PremierDate: {1}", x.PremierDate, y.PremierDate);
                var orderFactor = Config.Instance.YearSortAsc ? -1 : 1;
                compare = orderFactor * yProductionYear.CompareTo(xProductionYear);     //this will reverse the order if that option is set
                break;

            case SortOrder.Rating:

                compare = Ratings.Level(x.OfficialRating).CompareTo(Ratings.Level(y.OfficialRating));
                break;

            case SortOrder.CriticRating:
                // we want a descending sort
                var firstCritic  = y.CriticRating ?? 0;
                var secondCritic = x.CriticRating ?? 0;
                compare = firstCritic.CompareTo(secondCritic);
                break;

            case SortOrder.UserRating:
                // we want a descending sort
                var firstUser  = y.ImdbRating ?? 0;
                var secondUser = x.ImdbRating ?? 0;
                compare = firstUser.CompareTo(secondUser);
                break;

            case SortOrder.Runtime:
                var xRuntime = x is IShow ? (x as IShow).RunningTime : null;
                var yRuntime = y is IShow ? (y as IShow).RunningTime : null;

                xRuntime = xRuntime ?? int.MaxValue;
                yRuntime = yRuntime ?? int.MaxValue;

                compare = xRuntime.Value.CompareTo(yRuntime.Value);
                break;

            case SortOrder.Unwatched:

                compare = ExtractUnwatchedCount(y).CompareTo(ExtractUnwatchedCount(x));
                break;

            case SortOrder.Custom:

                Logging.Logger.ReportVerbose("Sorting on custom field " + propertyName);
                var yProp = y.GetType().GetProperty(propertyName);
                var xProp = x.GetType().GetProperty(propertyName);
                if (yProp == null || xProp == null)
                {
                    break;
                }
                var yVal = yProp.GetValue(y, null);
                var xVal = xProp.GetValue(x, null);
                if (yVal == null && xVal == null)
                {
                    break;
                }
                if (yVal == null)
                {
                    return(1);
                }
                if (xVal == null)
                {
                    return(-1);
                }
                Logging.Logger.ReportVerbose("Value x: " + xVal + " Value y: " + yVal);
                compare = String.Compare(xVal.ToString(), yVal.ToString(), compareCulture);
                break;

            default:
                compare = 0;
                break;
            }

            if (compare == 0)
            {
                var name1 = x.SortName ?? x.Name ?? "";
                var name2 = y.SortName ?? y.Name ?? "";

                if (Config.Instance.EnableAlphanumericSorting)
                {
                    compare = AlphaNumericCompare(name1, name2, compareCulture);
                }
                else
                {
                    compare = String.Compare(name1, name2, compareCulture);
                }
            }

            return(compare);
        }