public static List<Media> SelectVideo(IQueryable<Media> data, SearchSettings settings, int count, Media maintainCurrent) {
if (settings == null)
settings = new SearchSettings();
if (settings.ExcludeVideos == null)
settings.ExcludeVideos = new List<Guid>();
// Exclude currently selected video so that it doesn't get randomly re-reselected.
if (maintainCurrent != null) {
settings.ExcludeVideos = new List<Guid>(settings.ExcludeVideos);
settings.ExcludeVideos.Add(maintainCurrent.MediaId);
count--;
}
var Query = (from v in data
where (settings.AllowDownloading || v.FileName != null) &&
(v.FileName != null || v.DownloadUrl != "") &&
(v.Length == null || ((v.EndPos != null ? v.EndPos.Value : v.Length.Value) - (v.StartPos != null ? v.StartPos.Value : 0)) <= 12 * 60) && // Don't get videos longer than 12 minutes
!settings.ExcludeVideos.Contains(v.MediaId) // Don't repeat same videos
select v);
// Apply search filters.
Query = SearchVideoAccess.ApplySearchFilters(Query, settings, null);
// Return random result
int TotalFound = 0;
List<Guid> ResultId = SelectRandomId(Query, count, out TotalFound);
List<Media> Result = new List<Media>();
if (maintainCurrent != null)
Result.Add(maintainCurrent);
settings.TotalFound = TotalFound;
if (TotalFound > 0 && ResultId.Count() > 0) {
if (TotalFound <= count)
Result.AddRange(Query.Take(count).ToList());
else
Result.AddRange(data.Where(v => ResultId.Contains(v.MediaId)).ToList());
}
return Result;
}