private void SaveVideo_Step3(DownloadList saveItems, string url, bool? enque) { // check for valid url and cut off additional parameter if (String.IsNullOrEmpty(url) || !UriUtils.IsValidUri((url.IndexOf(SimpleUrl.ParameterSeparator) > 0) ? url.Substring(0, url.IndexOf(SimpleUrl.ParameterSeparator)) : url)) { notification.Show(Translation.Instance.Error, Translation.Instance.UnableToDownloadVideo); return; } saveItems.CurrentItem.Url = url; if (string.IsNullOrEmpty(saveItems.CurrentItem.Title)) saveItems.CurrentItem.Title = saveItems.CurrentItem.VideoInfo.Title; if (!string.IsNullOrEmpty(saveItems.CurrentItem.OverrideFolder)) { if (!string.IsNullOrEmpty(saveItems.CurrentItem.OverrideFileName)) saveItems.CurrentItem.LocalFile = System.IO.Path.Combine(saveItems.CurrentItem.OverrideFolder, saveItems.CurrentItem.OverrideFileName); else saveItems.CurrentItem.LocalFile = System.IO.Path.Combine(saveItems.CurrentItem.OverrideFolder, saveItems.CurrentItem.Util.GetFileNameForDownload(saveItems.CurrentItem.VideoInfo, saveItems.CurrentItem.Category, url)); } else { saveItems.CurrentItem.LocalFile = System.IO.Path.Combine(System.IO.Path.Combine(OnlineVideoSettings.Instance.DownloadDir, saveItems.CurrentItem.Util.Settings.Name), saveItems.CurrentItem.Util.GetFileNameForDownload(saveItems.CurrentItem.VideoInfo, saveItems.CurrentItem.Category, url)); } if (saveItems.DownloadItems != null && saveItems.DownloadItems.Count > 1) { saveItems.CurrentItem.LocalFile = string.Format(@"{0}\{1} - {2}#{3}{4}", System.IO.Path.GetDirectoryName(saveItems.CurrentItem.LocalFile), System.IO.Path.GetFileNameWithoutExtension(saveItems.CurrentItem.LocalFile), (saveItems.DownloadItems.IndexOf(saveItems.CurrentItem) + 1).ToString().PadLeft((saveItems.DownloadItems.Count).ToString().Length, '0'), (saveItems.DownloadItems.Count).ToString(), System.IO.Path.GetExtension(saveItems.CurrentItem.LocalFile)); } saveItems.CurrentItem.LocalFile = FileUtils.GetNextFileName(saveItems.CurrentItem.LocalFile); saveItems.CurrentItem.ThumbFile = string.IsNullOrEmpty(saveItems.CurrentItem.VideoInfo.ThumbnailImage) ? saveItems.CurrentItem.VideoInfo.Thumb : saveItems.CurrentItem.VideoInfo.ThumbnailImage; // make sure the target dir exists if (!(System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(saveItems.CurrentItem.LocalFile)))) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(saveItems.CurrentItem.LocalFile)); } if (enque == true) DownloadManager.Instance.Add(saveItems.CurrentItem.Util.Settings.Name, saveItems); else if (enque == false) DownloadManager.Instance.Add(null, saveItems); downloadNotifier.GetBindingExpression(TextBlock.TextProperty).UpdateTarget(); downloadNotifier.GetBindingExpression(TextBlock.VisibilityProperty).UpdateTarget(); System.Threading.Thread downloadThread = new System.Threading.Thread((System.Threading.ParameterizedThreadStart)delegate(object o) { DownloadList dlList = o as DownloadList; try { IDownloader dlHelper = null; if (dlList.CurrentItem.Url.ToLower().StartsWith("mms://")) dlHelper = new MMSDownloader(); else dlHelper = new OnlineVideos.MPUrlSourceFilter.Downloader(); dlList.CurrentItem.Downloader = dlHelper; dlList.CurrentItem.Start = DateTime.Now; Log.Info("Starting download of '{0}' to '{1}' from Site '{2}'", dlList.CurrentItem.Url, dlList.CurrentItem.LocalFile, dlList.CurrentItem.Util.Settings.Name); Exception exception = dlHelper.Download(dlList.CurrentItem); if (exception != null) Log.Warn("Error downloading '{0}', Msg: {1}", dlList.CurrentItem.Url, exception.Message); OnDownloadFileCompleted(dlList, exception); } catch (System.Threading.ThreadAbortException) { // the thread was aborted on purpose, let it finish gracefully System.Threading.Thread.ResetAbort(); } catch (Exception ex) { Log.Warn("Error downloading '{0}', Msg: {1}", dlList.CurrentItem.Url, ex.Message); OnDownloadFileCompleted(dlList, ex); } }); downloadThread.IsBackground = true; downloadThread.Name = "OVDownload"; downloadThread.Start(saveItems); }
private void SaveVideo_Step3(DownloadList saveItems, string url, bool? enque) { // check for valid url and cut off additional parameter if (String.IsNullOrEmpty(url) || !Helpers.UriUtils.IsValidUri((url.IndexOf(MPUrlSourceFilter.SimpleUrl.ParameterSeparator) > 0) ? url.Substring(0, url.IndexOf(MPUrlSourceFilter.SimpleUrl.ParameterSeparator)) : url)) { GUIDialogNotify dlg = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); if (dlg != null) { dlg.Reset(); dlg.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); dlg.SetHeading(Translation.Instance.Error); dlg.SetText(Translation.Instance.UnableToDownloadVideo); dlg.DoModal(GUIWindowManager.ActiveWindow); } return; } saveItems.CurrentItem.Url = url; if (string.IsNullOrEmpty(saveItems.CurrentItem.Title)) saveItems.CurrentItem.Title = saveItems.CurrentItem.VideoInfo.Title; if (!string.IsNullOrEmpty(saveItems.CurrentItem.OverrideFolder)) { if (!string.IsNullOrEmpty(saveItems.CurrentItem.OverrideFileName)) saveItems.CurrentItem.LocalFile = Path.Combine(saveItems.CurrentItem.OverrideFolder, saveItems.CurrentItem.OverrideFileName); else saveItems.CurrentItem.LocalFile = Path.Combine(saveItems.CurrentItem.OverrideFolder, saveItems.CurrentItem.Util.GetFileNameForDownload(saveItems.CurrentItem.VideoInfo, saveItems.CurrentItem.Category, url)); } else { saveItems.CurrentItem.LocalFile = Path.Combine(Path.Combine(OnlineVideoSettings.Instance.DownloadDir, saveItems.CurrentItem.Util.Settings.Name), saveItems.CurrentItem.Util.GetFileNameForDownload(saveItems.CurrentItem.VideoInfo, saveItems.CurrentItem.Category, url)); } if (saveItems.DownloadItems != null && saveItems.DownloadItems.Count > 1) { saveItems.CurrentItem.LocalFile = string.Format(@"{0}\{1} - {2}#{3}{4}", Path.GetDirectoryName(saveItems.CurrentItem.LocalFile), Path.GetFileNameWithoutExtension(saveItems.CurrentItem.LocalFile), (saveItems.DownloadItems.IndexOf(saveItems.CurrentItem) + 1).ToString().PadLeft((saveItems.DownloadItems.Count).ToString().Length, '0'), (saveItems.DownloadItems.Count).ToString(), Path.GetExtension(saveItems.CurrentItem.LocalFile)); } saveItems.CurrentItem.LocalFile = Helpers.FileUtils.GetNextFileName(saveItems.CurrentItem.LocalFile); saveItems.CurrentItem.ThumbFile = string.IsNullOrEmpty(saveItems.CurrentItem.VideoInfo.ThumbnailImage) ? saveItems.CurrentItem.VideoInfo.Thumb : saveItems.CurrentItem.VideoInfo.ThumbnailImage; // make sure the target dir exists if (!(Directory.Exists(Path.GetDirectoryName(saveItems.CurrentItem.LocalFile)))) { Directory.CreateDirectory(Path.GetDirectoryName(saveItems.CurrentItem.LocalFile)); } if (enque == true) DownloadManager.Instance.Add(saveItems.CurrentItem.Util.Settings.Name, saveItems); else if (enque == false) DownloadManager.Instance.Add(null, saveItems); GUIPropertyManager.SetProperty("#OnlineVideos.currentDownloads", DownloadManager.Instance.Count.ToString()); System.Threading.Thread downloadThread = new System.Threading.Thread((System.Threading.ParameterizedThreadStart)delegate(object o) { DownloadList dlList = o as DownloadList; try { IDownloader dlHelper = null; if (dlList.CurrentItem.Url.ToLower().StartsWith("mms://")) dlHelper = new MMSDownloader(); else dlHelper = new OnlineVideos.MPUrlSourceFilter.Downloader(); dlList.CurrentItem.Downloader = dlHelper; dlList.CurrentItem.Start = DateTime.Now; Log.Instance.Info("Starting download of '{0}' to '{1}' from Site '{2}'", dlList.CurrentItem.Url, dlList.CurrentItem.LocalFile, dlList.CurrentItem.Util.Settings.Name); Exception exception = dlHelper.Download(dlList.CurrentItem); if (exception != null) Log.Instance.Warn("Error downloading '{0}', Msg: {1}", dlList.CurrentItem.Url, exception.Message); OnDownloadFileCompleted(dlList, exception); } catch (System.Threading.ThreadAbortException) { // the thread was aborted on purpose, let it finish gracefully System.Threading.Thread.ResetAbort(); } catch (Exception ex) { Log.Instance.Warn("Error downloading '{0}', Msg: {1}", dlList.CurrentItem.Url, ex.Message); OnDownloadFileCompleted(dlList, ex); } }); downloadThread.IsBackground = true; downloadThread.Name = "OVDownload"; downloadThread.Start(saveItems); GUIDialogNotify dlgNotify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); if (dlgNotify != null) { dlgNotify.Reset(); dlgNotify.SetImage(SiteImageExistenceCache.GetImageForSite("OnlineVideos", type: "Icon")); dlgNotify.SetHeading(Translation.Instance.DownloadStarted); dlgNotify.SetText(saveItems.CurrentItem.Title); dlgNotify.DoModal(GUIWindowManager.ActiveWindow); } }