예제 #1
0
        public override void Execute()
        {
            base.Execute();

            try
            {
                var program = _drNuClient.GetProgram(_downloadUri);
                if (!string.IsNullOrWhiteSpace(program.Title))
                {
                    System.Console.WriteLine("Henter \"{0}\" fra DR NU.", program.Title);
                    System.Console.WriteLine();
                }

                TimeSpan duration = TimeSpan.MinValue;
                program.Duration += (sender, eventArgs) =>
                {
                    duration = eventArgs.Duration;
                    WriteProgressBar(duration, TimeSpan.MinValue, 0);
                };

                long bytesDownloaded = 0;
                program.Elapsed += (sender, eventArgs) =>
                {
                    bytesDownloaded = eventArgs.Bytes;

                    System.Console.CursorLeft = 0;
                    System.Console.CursorTop -= 2;
                    WriteProgressBar(duration, eventArgs.Elapsed, eventArgs.Bytes);
                };

                string sanitizedTitle = _fileNameSanitizer.Sanitize(program.Title);
                if (string.IsNullOrWhiteSpace(sanitizedTitle))
                {
                    sanitizedTitle = "Program";
                }

                program.Download(string.Format("{0}.flv", sanitizedTitle));

                System.Console.CursorLeft = 0;
                System.Console.CursorTop -= 2;
                WriteProgressBar(duration, duration, bytesDownloaded);
            }
            catch (ScraperException)
            {
                System.Console.WriteLine("Der blev ikke fundet noget TV-program på den pågældende URL.");
            }
        }
예제 #2
0
        private void Download()
        {
            var program = _drNuClient.GetProgram(Uri);

            string sanitizedTitle = _fileNameSanitizer.Sanitize(program.Title);

            if (string.IsNullOrWhiteSpace(sanitizedTitle))
            {
                sanitizedTitle = "Video";
            }

            var saveFileDialog = new SaveFileDialog
            {
                AddExtension = true,
                FileName     = sanitizedTitle,
                DefaultExt   = ".flv",
                Filter       = "Flash Video (.flv)|*.flv"
            };
            var result = saveFileDialog.ShowDialog();

            if (result == true)
            {
                _downloadThread = new Thread(() =>
                {
                    program.Duration += (sender, args) =>
                    {
                        Duration = args.Duration;
                    };

                    program.Elapsed += (sender, args) =>
                    {
                        BytesDownloaded = args.Bytes;
                        Elapsed         = args.Elapsed;

                        Progress = Convert.ToUInt16((double)args.Elapsed.Ticks / Duration.Ticks * 100);
                    };

                    program.Download(saveFileDialog.FileName);

                    Progress = 0;
                    MessageBox.Show("Videoen er nu downloadet.", "Download færdig",
                                    MessageBoxButton.OK, MessageBoxImage.Information);
                });

                _downloadThread.Start();
            }
        }