//////////////////////////////////////// //// Metadata //////////////////////////////////////// VideoMetadata::SortKey VideoMetadata::GenerateDefaultSortKey(const VideoMetadata &m, bool ignore_case) { QString title(ignore_case ? m.GetTitle().toLower() : m.GetTitle()); title = TrimTitle(title, ignore_case); return SortKey(SortData(title, m.GetFilename(), QString().sprintf("%.7d", m.GetID()))); }
/// Compares two VideoMetadata instances bool VideoFilterSettings::meta_less_than(const VideoMetadata &lhs, const VideoMetadata &rhs, bool sort_ignores_case) const { bool ret = false; switch (orderby) { case kOrderByTitle: { VideoMetadata::SortKey lhs_key; VideoMetadata::SortKey rhs_key; if (lhs.HasSortKey() && rhs.HasSortKey()) { lhs_key = lhs.GetSortKey(); rhs_key = rhs.GetSortKey(); } else { lhs_key = VideoMetadata::GenerateDefaultSortKey(lhs, sort_ignores_case); rhs_key = VideoMetadata::GenerateDefaultSortKey(rhs, sort_ignores_case); } ret = lhs_key < rhs_key; break; } case kOrderBySeasonEp: { if ((lhs.GetSeason() == rhs.GetSeason()) && (lhs.GetEpisode() == rhs.GetEpisode()) && (lhs.GetSeason() == 0) && (rhs.GetSeason() == 0) && (lhs.GetEpisode() == 0) && (rhs.GetEpisode() == 0)) { VideoMetadata::SortKey lhs_key; VideoMetadata::SortKey rhs_key; if (lhs.HasSortKey() && rhs.HasSortKey()) { lhs_key = lhs.GetSortKey(); rhs_key = rhs.GetSortKey(); } else { lhs_key = VideoMetadata::GenerateDefaultSortKey(lhs, sort_ignores_case); rhs_key = VideoMetadata::GenerateDefaultSortKey(rhs, sort_ignores_case); } ret = lhs_key < rhs_key; } else if (lhs.GetSeason() == rhs.GetSeason() && lhs.GetTitle() == rhs.GetTitle()) ret = lhs.GetEpisode() < rhs.GetEpisode(); else ret = lhs.GetSeason() < rhs.GetSeason(); break; } case kOrderByYearDescending: { ret = lhs.GetYear() > rhs.GetYear(); break; } case kOrderByUserRatingDescending: { ret = lhs.GetUserRating() > rhs.GetUserRating(); break; } case kOrderByLength: { ret = lhs.GetLength() < rhs.GetLength(); break; } case kOrderByFilename: { QString lhsfn(sort_ignores_case ? lhs.GetFilename().toLower() : lhs.GetFilename()); QString rhsfn(sort_ignores_case ? rhs.GetFilename().toLower() : rhs.GetFilename()); ret = QString::localeAwareCompare(lhsfn, rhsfn) < 0; break; } case kOrderByID: { ret = lhs.GetID() < rhs.GetID(); break; } case kOrderByDateAddedDescending: { ret = lhs.GetInsertdate() > rhs.GetInsertdate(); break; } default: { LOG(VB_GENERAL, LOG_ERR, QString("Error: unknown sort type %1") .arg(orderby)); } } return ret; }