public async Task StartScan(List <VideoListItem> selection, CancellationToken cancel)
{
await selection.ForEachAsync(5, cancel, async item => {
Media VideoData = PlayerAccess.GetVideoById(item.MediaId.Value);
if (VideoData != null && !item.IsBusy)
{
try {
// Query the server for media info.
SetStatus(item, VideoListItemStatusEnum.DownloadingInfo);
VideoInfo VInfo = await DownloadManager.GetDownloadInfoAsync(VideoData.DownloadUrl);
if (VInfo != null)
{
// Get the highest resolution format.
BestFormatInfo VideoFormat = DownloadBusiness.SelectBestFormat(VInfo.Streams);
if (VideoFormat == null || VideoFormat.BestVideo == null)
{
SetStatus(item, VideoListItemStatusEnum.Failed);
}
else
{
SetStatus(item, await IsHigherQualityAvailable(VideoFormat, Settings.NaturalGroundingFolder + VideoData.FileName));
}
if (VideoFormat != null && !string.IsNullOrEmpty(VideoFormat.StatusText))
{
SetStatus(item, item.Status, item.StatusText + string.Format(" ({0})", VideoFormat.StatusText));
}
}
else
{
SetStatus(item, VideoListItemStatusEnum.InvalidUrl);
}
}
catch {
SetStatus(item, VideoListItemStatusEnum.Failed);
}
}
});
}