public override int Compare(MediaItem x, MediaItem y) { MediaItemAspect aspectX = null; MediaItemAspect aspectY = null; MediaItemAspectMetadata.AttributeSpecification attrX = null; MediaItemAspectMetadata.AttributeSpecification attrY = null; if (_sortAttrs != null) { attrX = GetAttributeSpecification(x, _sortAttrs, out aspectX); attrY = GetAttributeSpecification(y, _sortAttrs, out aspectY); } else if (_sortMultiAttrs != null) { attrX = GetAttributeSpecification(x, _sortMultiAttrs, out aspectX); attrY = GetAttributeSpecification(y, _sortMultiAttrs, out aspectY); } T?valX = null; T?valY = null; if (attrX != null) { valX = (T?)aspectX.GetAttributeValue(attrX); } if (attrY != null) { valY = (T?)aspectY.GetAttributeValue(attrY); } return(ObjectUtils.Compare(valX, valY)); }
protected int CompareDiscNumbers(int?discIdX, int?discIdY) { //Treat empty or 0 disc number as equal to disc number 1 when sorting if ((discIdX.HasValue && discIdX.Value == 1 && (!discIdY.HasValue || discIdY.Value == 0)) || (discIdY.HasValue && discIdY.Value == 1 && (!discIdX.HasValue || discIdX.Value == 0))) { return(0); } return(ObjectUtils.Compare(discIdX, discIdY)); }
public override int Compare(MediaItem x, MediaItem y) { long?durationX = null; long?durationY = null; Dictionary <int, long> videoLengthX = new Dictionary <int, long>(); Dictionary <int, long> videoLengthY = new Dictionary <int, long>(); IList <MultipleMediaItemAspect> videoAspectsX; IList <MultipleMediaItemAspect> videoAspectsY; if (MediaItemAspect.TryGetAspects(x.Aspects, VideoStreamAspect.Metadata, out videoAspectsX)) { foreach (MultipleMediaItemAspect videoAspect in videoAspectsX) { long?duration = (long?)videoAspect[VideoStreamAspect.ATTR_DURATION]; int? partSet = (int?)videoAspect[VideoStreamAspect.ATTR_VIDEO_PART_SET]; if (partSet.HasValue && duration.HasValue) { if (!videoLengthX.ContainsKey(partSet.Value)) { videoLengthX.Add(partSet.Value, 0); } videoLengthX[partSet.Value] += duration.Value; } } if (videoLengthX.Count > 0) { durationX = videoLengthX.First().Value; } } if (MediaItemAspect.TryGetAspects(y.Aspects, VideoStreamAspect.Metadata, out videoAspectsY)) { foreach (MultipleMediaItemAspect videoAspect in videoAspectsY) { long?duration = (long?)videoAspect[VideoStreamAspect.ATTR_DURATION]; int? partSet = (int?)videoAspect[VideoStreamAspect.ATTR_VIDEO_PART_SET]; if (partSet.HasValue && duration.HasValue) { if (!videoLengthY.ContainsKey(partSet.Value)) { videoLengthY.Add(partSet.Value, 0); } videoLengthY[partSet.Value] += duration.Value; } } if (videoLengthY.Count > 0) { durationY = videoLengthY.First().Value; } } return(ObjectUtils.Compare(durationX, durationY)); }
public override int Compare(MediaItem x, MediaItem y) { MediaItemAspect mediaAspectX; MediaItemAspect mediaAspectY; if (x.Aspects.TryGetValue(MediaAspect.ASPECT_ID, out mediaAspectX) && y.Aspects.TryGetValue(MediaAspect.ASPECT_ID, out mediaAspectY)) { DateTime?recordingTimeX = (DateTime?)mediaAspectX.GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME); DateTime?recordingTimeY = (DateTime?)mediaAspectY.GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME); return(ObjectUtils.Compare(recordingTimeX, recordingTimeY)); } return(base.Compare(x, y)); }
public override int Compare(MediaItem x, MediaItem y) { SingleMediaItemAspect episodeAspectX; SingleMediaItemAspect episodeAspectY; if (MediaItemAspect.TryGetAspect(x.Aspects, MediaAspect.Metadata, out episodeAspectX) && MediaItemAspect.TryGetAspect(y.Aspects, MediaAspect.Metadata, out episodeAspectY)) { DateTime?firstAiredX = (DateTime?)episodeAspectX.GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME); DateTime?firstAiredY = (DateTime?)episodeAspectY.GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME); return(ObjectUtils.Compare(firstAiredX, firstAiredY)); } return(base.Compare(x, y)); }
public override int Compare(MediaItem x, MediaItem y) { SingleMediaItemAspect mediaAspectX; SingleMediaItemAspect mediaAspectY; if (MediaItemAspect.TryGetAspect(x.Aspects, MediaAspect.Metadata, out mediaAspectX) && MediaItemAspect.TryGetAspect(y.Aspects, MediaAspect.Metadata, out mediaAspectY)) { DateTime?recordingTimeX = (DateTime?)mediaAspectX.GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME); DateTime?recordingTimeY = (DateTime?)mediaAspectY.GetAttributeValue(MediaAspect.ATTR_RECORDINGTIME); return(ObjectUtils.Compare(recordingTimeX, recordingTimeY)); } return(base.Compare(x, y)); }
public override int Compare(MediaItem x, MediaItem y) { MediaItemAspect seriesAspectX; MediaItemAspect seriesAspectY; if (x.Aspects.TryGetValue(SeriesAspect.ASPECT_ID, out seriesAspectX) && y.Aspects.TryGetValue(SeriesAspect.ASPECT_ID, out seriesAspectY)) { DateTime?firstAiredX = (DateTime?)seriesAspectX.GetAttributeValue(SeriesAspect.ATTR_FIRSTAIRED); DateTime?firstAiredY = (DateTime?)seriesAspectY.GetAttributeValue(SeriesAspect.ATTR_FIRSTAIRED); return(ObjectUtils.Compare(firstAiredX, firstAiredY)); } return(base.Compare(x, y)); }
public override int Compare(MediaItem x, MediaItem y) { MediaItemAspect aspectX; MediaItemAspect aspectY; Guid aspectId = _sortAttr.ParentMIAM.AspectId; if (x.Aspects.TryGetValue(aspectId, out aspectX) && y.Aspects.TryGetValue(aspectId, out aspectY)) { T valX = (T)aspectX.GetAttributeValue(_sortAttr); T valY = (T)aspectY.GetAttributeValue(_sortAttr); return(ObjectUtils.Compare(valX, valY)); } return(0); }
public override int Compare(MediaItem x, MediaItem y) { SingleMediaItemAspect mediaAspectX; SingleMediaItemAspect mediaAspectY; DateTime?recordingTimeX = null; DateTime?recordingTimeY = null; if (MediaItemAspect.TryGetAspect(x.Aspects, ImporterAspect.Metadata, out mediaAspectX)) { recordingTimeX = (DateTime?)mediaAspectX.GetAttributeValue(ImporterAspect.ATTR_DATEADDED); } if (MediaItemAspect.TryGetAspect(y.Aspects, ImporterAspect.Metadata, out mediaAspectY)) { recordingTimeY = (DateTime?)mediaAspectY.GetAttributeValue(ImporterAspect.ATTR_DATEADDED); } return(ObjectUtils.Compare(recordingTimeY, recordingTimeX)); }
public override int Compare(MediaItem x, MediaItem y) { MediaItemAspect aspectX; MediaItemAspect aspectY; Guid aspectId = _attr.ParentMIAM.AspectId; if (x.Aspects.TryGetValue(aspectId, out aspectX) && y.Aspects.TryGetValue(aspectId, out aspectY)) { List <string> valuesX = new List <string>(aspectX.GetCollectionAttribute <string>(_attr)); valuesX.Sort(); string firstValueX = valuesX.FirstOrDefault(); List <string> valuesY = new List <string>(aspectY.GetCollectionAttribute <string>(_attr)); valuesY.Sort(); string firstValueY = valuesY.FirstOrDefault(); return(ObjectUtils.Compare(firstValueX, firstValueY)); } return(base.Compare(x, y)); }
public override int Compare(MediaItem x, MediaItem y) { MediaItemAspect audioAspectX; MediaItemAspect audioAspectY; if (x.Aspects.TryGetValue(AudioAspect.ASPECT_ID, out audioAspectX) && y.Aspects.TryGetValue(AudioAspect.ASPECT_ID, out audioAspectY)) { string albumX = (string)audioAspectX.GetAttributeValue(AudioAspect.ATTR_ALBUM); string albumY = (string)audioAspectY.GetAttributeValue(AudioAspect.ATTR_ALBUM); int res = string.Compare(albumX, albumY); if (res != 0) { return(res); } int?trackX = (int?)audioAspectX.GetAttributeValue(AudioAspect.ATTR_TRACK); int?trackY = (int?)audioAspectY.GetAttributeValue(AudioAspect.ATTR_TRACK); return(ObjectUtils.Compare(trackX, trackY)); } // Fallback if the items to be compared are no audio items: Compare by title return(base.Compare(x, y)); }
protected int CompareAttributes(MediaItem x, MediaItemAspect aspectX, MediaItemAspectMetadata.AttributeSpecification attrX, MediaItem y, MediaItemAspect aspectY, MediaItemAspectMetadata.AttributeSpecification attrY) { string firstValueX = null; string firstValueY = null; if (attrX.IsCollectionAttribute) { IEnumerable <string> collectionX = aspectX.GetCollectionAttribute <string>(attrX); if (collectionX != null) { List <string> valuesX = new List <string>(collectionX); if (_preSortAttributes) { valuesX.Sort(); } firstValueX = valuesX.FirstOrDefault(); } } else { IList <MultipleMediaItemAspect> aspectsX; MultipleMediaItemAspectMetadata metadata = attrX.ParentMIAM as MultipleMediaItemAspectMetadata; if (metadata != null && MediaItemAspect.TryGetAspects(x.Aspects, metadata, out aspectsX)) { List <string> valuesX = new List <string>(); foreach (MultipleMediaItemAspect aspect in aspectsX) { if (!string.IsNullOrEmpty(aspect.GetAttributeValue <string>(attrX))) { valuesX.Add(aspect.GetAttributeValue <string>(attrX)); } } if (valuesX.Count > 0) { if (_preSortAttributes) { valuesX.Sort(); } firstValueX = valuesX.FirstOrDefault(); } } } if (attrY.IsCollectionAttribute) { IEnumerable <string> collectionY = aspectY.GetCollectionAttribute <string>(attrY); if (collectionY != null) { List <string> valuesY = new List <string>(collectionY); if (_preSortAttributes) { valuesY.Sort(); } firstValueY = valuesY.FirstOrDefault(); } } else { IList <MultipleMediaItemAspect> aspectsY; MultipleMediaItemAspectMetadata metadata = attrY.ParentMIAM as MultipleMediaItemAspectMetadata; if (metadata != null && MediaItemAspect.TryGetAspects(y.Aspects, metadata, out aspectsY)) { List <string> valuesY = new List <string>(); foreach (MultipleMediaItemAspect aspect in aspectsY) { if (!string.IsNullOrEmpty(aspect.GetAttributeValue <string>(attrY))) { valuesY.Add(aspect.GetAttributeValue <string>(attrY)); } } if (valuesY.Count > 0) { if (_preSortAttributes) { valuesY.Sort(); } firstValueY = valuesY.FirstOrDefault(); } } } return(ObjectUtils.Compare(firstValueX, firstValueY)); }