static void OnDownloadFileCompleted(DownloadList saveItems, Exception error) { // notify the Util of the downloaded video that the download has stopped try { if (saveItems.CurrentItem != null && saveItems.CurrentItem.Util != null) { saveItems.CurrentItem.Util.OnDownloadEnded(saveItems.CurrentItem.VideoInfo, saveItems.CurrentItem.Url, (double)saveItems.CurrentItem.PercentComplete / 100.0d, error != null); } } catch (Exception ex) { Log.Warn("Error on Util.OnDownloadEnded: {0}", ex.ToString()); } bool preventMessageDuetoAdult = (saveItems.CurrentItem.Util != null && saveItems.CurrentItem.Util.Settings.ConfirmAge && OnlineVideoSettings.Instance.UseAgeConfirmation && !OnlineVideoSettings.Instance.AgeConfirmed); if (error != null && !saveItems.CurrentItem.Downloader.Cancelled) { if (!preventMessageDuetoAdult) { /* // todo : show download failed notification? * GUIDialogNotify loDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); * if (loDlgNotify != null) * { * loDlgNotify.Reset(); * loDlgNotify.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); * loDlgNotify.SetHeading(Translation.Instance.Error); * loDlgNotify.SetText(string.Format(Translation.Instance.DownloadFailed, saveItems.CurrentItem.Title)); * loDlgNotify.DoModal(GUIWindowManager.ActiveWindow); * }*/ } } else { try { // if the image given was an url -> check if thumb exists otherwise download if (saveItems.CurrentItem.ThumbFile.ToLower().StartsWith("http")) { string thumbFile = Helpers.FileUtils.GetThumbFile(saveItems.CurrentItem.ThumbFile); if (File.Exists(thumbFile)) { saveItems.CurrentItem.ThumbFile = thumbFile; } else if (ImageDownloader.DownloadAndCheckImage(saveItems.CurrentItem.ThumbFile, thumbFile)) { saveItems.CurrentItem.ThumbFile = thumbFile; } } // save thumb for this video as well if it exists if (!saveItems.CurrentItem.ThumbFile.ToLower().StartsWith("http") && File.Exists(saveItems.CurrentItem.ThumbFile)) { string localImageName = Path.Combine( Path.GetDirectoryName(saveItems.CurrentItem.LocalFile), Path.GetFileNameWithoutExtension(saveItems.CurrentItem.LocalFile)) + Path.GetExtension(saveItems.CurrentItem.ThumbFile); File.Copy(saveItems.CurrentItem.ThumbFile, localImageName, true); } } catch (Exception ex) { Log.Warn("Error saving thumbnail for download: {0}", ex.ToString()); } // get file size int fileSize = saveItems.CurrentItem.KbTotal; if (fileSize <= 0) { try { fileSize = (int)((new FileInfo(saveItems.CurrentItem.LocalFile)).Length / 1024); } catch { } } Log.Info("{3} download of '{0}' - {1} KB in {2}", saveItems.CurrentItem.LocalFile, fileSize, (DateTime.Now - saveItems.CurrentItem.Start).ToString(), saveItems.CurrentItem.Downloader.Cancelled ? "Cancelled" : "Finished"); if (!preventMessageDuetoAdult) { /* // todo : show download canceled or completed notification? * GUIDialogNotify loDlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); * if (loDlgNotify != null) * { * loDlgNotify.Reset(); * loDlgNotify.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); * if (saveItems.CurrentItem.Downloader.Cancelled) * loDlgNotify.SetHeading(Translation.Instance.DownloadCancelled); * else * loDlgNotify.SetHeading(Translation.Instance.DownloadComplete); * loDlgNotify.SetText(string.Format("{0}{1}", saveItems.CurrentItem.Title, fileSize > 0 ? " ( " + fileSize.ToString("n0") + " KB)" : "")); * loDlgNotify.DoModal(GUIWindowManager.ActiveWindow); * }*/ } // invoke VideoDownloaded event /*if (VideoDownloaded != null) * { * try * { * VideoDownloaded(saveItems.CurrentItem.LocalFile, saveItems.CurrentItem.Util.Settings.Name, saveItems.CurrentItem.Category != null ? saveItems.CurrentItem.Category.RecursiveName() : "", saveItems.CurrentItem.Title); * } * catch (Exception ex) * { * Log.Warn("Error invoking external VideoDownloaded event handler: {0}", ex.ToString()); * } * }*/ } // download the next if list not empty and not last in list and not cancelled by the user string site = null; if (saveItems.DownloadItems != null && saveItems.DownloadItems.Count > 1 && !saveItems.CurrentItem.Downloader.Cancelled) { int currentDlIndex = saveItems.DownloadItems.IndexOf(saveItems.CurrentItem); if (currentDlIndex >= 0 && currentDlIndex + 1 < saveItems.DownloadItems.Count) { saveItems.CurrentItem = saveItems.DownloadItems[currentDlIndex + 1]; SaveVideo_Step1(saveItems, null); } else { site = DownloadManager.Instance.Remove(saveItems); } } else { site = DownloadManager.Instance.Remove(saveItems); } if (!string.IsNullOrEmpty(site)) { var continuationList = DownloadManager.Instance.GetNext(site); if (continuationList != null) { SaveVideo_Step1(continuationList, null); } } }