static int Main(string[] args) { var ret = 0; if (args.Length == 0) { Write("Invalid command line."); ret = 200; } else { var path = args[0]; var downloader = new LaunchMpeg2DvrmsCommandLine(OnPlaybackReady); var deviceName = Utility.GetDeviceNameFromPath(path); var device = GetDevice(deviceName); if (device == null) { Write("Could not find device: " + deviceName); ret = 101; } else { var item = (AVItem)Utility.GetItemFromPath(device, path); if (item == null) { Write("Could not find path: " + deviceName); ret = 102; } else { var playbackFile = downloader.GetPlaybackFile(); var contentLength = Convert.ToInt64(item.Size) + LaunchMpeg2DvrmsBase.ContentPadding; var commandLineArguments = Factory.CreateRunMpeg2DvrmsCommandLineArguments(item.PlaybackUri.AbsoluteUri, playbackFile.FullName, contentLength, Guid.NewGuid().ToString(), item.Title); Console.Write(commandLineArguments); } } } return ret; }
private void Form1_Load(object sender, EventArgs e) { _playback = new LaunchMpeg2DvrmsCommandLine(OnStartPlayback); txtOutput.Text = _playback.GetPlaybackFile().FullName; gbCredentials.Enabled = chkSpecifyCredentials.Checked; txtUsername.Text = WindowsIdentity.GetCurrent().Name; lblSize.Text = string.Empty; var types = GetPlaybackClasses(); var playbacks = new List<ILaunchDlnaConversion>(); foreach (var playback in types.Select(type => (ILaunchDlnaConversion)Activator.CreateInstance(type, new object[] { null }))) { playback.OnConversionStopped = OnStopLaunchedPlayback; playback.OnUpdateConversionProgress = OnUpdateConversionProgress; playback.OnMessageBox = OnMessageBox; playbacks.Add(playback); } comboBox1.DataSource = playbacks; comboBox1.SelectedIndex = comboBox1.FindString("Conversion Command"); }
/// <summary> /// Downloads the specified <see cref="AVItem"/> path. /// </summary> /// <param name="download">A <see cref="tubeCentric.Shared.Download"/> object that can be redownloaded</param> public void Download(Download download) { var path = download.Path; Write(string.Format(@"Request {0}: " + path, DateTime.Now.ToShortTimeString())); Interrupted = false; var downloader = new LaunchMpeg2DvrmsCommandLine(OnPlaybackReady) { ForStorageOnly = true }; downloader.OnConversionStopped += OnDownloadingStopped; using (var udm = UtilityDataModel.NewContext()) { udm.Attach(download); var downloadAttempts = download.DownloadAttemptedCount + 1; download.Clear(); download.FilePath = downloader.GetPlaybackFile().FullName; download.IsDownloading = true; download.DownloadAttemptedCount = downloadAttempts; udm.SaveAndRefreshDataModel(udm.Downloads); udm.Detach(download); } DownloadInfo.Download = download; var deviceName = Utility.GetDeviceNameFromPath(path); var device = OnGetDevice(deviceName); if (device == null) { var error = "Could not find device: " + deviceName; Write(error); throw new DeviceLocateException(error, deviceName); } var item = (AVItem)Utility.GetItemFromPath(device, path); if (item == null) { var error = "Could not find path: " + path; Write(error); throw new PathLocateException(error, path); } Write(@"Waiting for download to start..."); if (!downloader.StartConversion(item, download)) { Write(@"Start conversion call failed."); throw new tubeCentricException("Could not start the download."); } var start = DateTime.Now; var ts = DateTime.Now - start; while (ts.TotalSeconds < 60 && !downloader.IsConversionActive && !Interrupted) { ts = DateTime.Now - start; Thread.Sleep(100); } if (!Interrupted) { var status = downloader.GetDownloadedStatus(); start = DateTime.Now; ts = DateTime.Now - start; while (ts.TotalSeconds < 60 && status == null) { ts = DateTime.Now - start; Thread.Sleep(100); status = downloader.GetDownloadedStatus(); } Write(string.Format("Waited {0} seconds for download status.", ts.TotalSeconds)); if (status != null) Write(@"Starting download: " + path); while (downloader.IsConversionActive && !Interrupted) { status = downloader.GetDownloadedStatus(); if (status == null) { // download done Write(@"Could not get a status on the file. Might have exited with error.", NotificationLevel.Error); SyncDownloadInfo(status); OnSaveProgress(); break; } download.IsDownloading = downloader.IsConversionActive; SyncDownloadInfo(status); OnSaveProgress(); Write(string.Format(@"{1}/{0}, {2}%, {3} ", status.DownloadTotal, status.DownloadCurrent, status.PercentComplete, status.CurrentFileSize), NotificationLevel.Tip); if (status.PercentComplete > 100) { Logger.TraceWarn("Download of {0} went beyond 100%. Stopping automatically.", download.Path); break; } Thread.Sleep(5000); // give a chance to read the download queue and for listeners to keep up } if (Interrupted) { bool fileDeleted = false; try { File.Delete(downloader.GetPlaybackFile().FullName); fileDeleted = true; } catch (Exception) { Write(@"Could not delete the file after it was interrupted."); } finally { var filePath = DownloadInfo.Download.FilePath; if (fileDeleted) { filePath = string.Empty; } // clear everything except the number of download attempts var downloadAttemptedCount = DownloadInfo.Download.DownloadAttemptedCount; DownloadInfo.Download.Clear(); DownloadInfo.Download.DownloadAttemptedCount = downloadAttemptedCount; DownloadInfo.Download.FilePath = filePath; DownloadInfo.Download.IsDownloading = false; OnSaveProgress(); } } else { OnSaveProgress(); Write(@"Completed " + path); } } else { var message = @"Download was interrupted " + path; Write(message); throw new DownloadInterruptedException(message); } }