コード例 #1
0
        public async Task RunAsync()
        {
            ChatDownloader            downloader = new ChatDownloader(DownloadOptions);
            Progress <ProgressReport> progress   = new Progress <ProgressReport>();

            progress.ProgressChanged += Progress_ProgressChanged;
            Status = TwitchTaskStatus.Running;
            OnPropertyChanged("Status");
            try
            {
                await downloader.DownloadAsync(progress, TokenSource.Token);

                if (TokenSource.IsCancellationRequested)
                {
                    Status = TwitchTaskStatus.Cancelled;
                    OnPropertyChanged("Status");
                }
                else
                {
                    Progress = 100;
                    OnPropertyChanged("Progress");
                    Status = TwitchTaskStatus.Finished;
                    OnPropertyChanged("Status");
                }
            }
            catch
            {
                Status = TwitchTaskStatus.Failed;
                OnPropertyChanged("Status");
            }
        }
コード例 #2
0
        private void GetChats()
        {
            ChatDownloader chatsDownloader = new ChatDownloader();

            chatsDownloader.Attach(this);
            chatsDownloader.GetChats(Program.UserId);
            labelWating.Visible = true;
        }
コード例 #3
0
        private static void DownloadChat(Options inputOptions)
        {
            ChatDownloadOptions downloadOptions = new ChatDownloadOptions();

            if (inputOptions.Id == "")
            {
                Console.WriteLine("[ERROR] - Invalid ID, unable to parse.");
                Environment.Exit(1);
            }

            //If output file doesn't end in .txt, assume JSON
            if (Path.GetFileName(inputOptions.OutputFile).Contains('.'))
            {
                string extension = Path.GetFileName(inputOptions.OutputFile).Split('.').Last();
                if (extension.ToLower() == "json")
                {
                    downloadOptions.IsJson = true;
                }
                else
                {
                    downloadOptions.IsJson = false;
                }
            }
            else
            {
                downloadOptions.IsJson = true;
            }

            downloadOptions.Id                = inputOptions.Id;
            downloadOptions.CropBeginning     = inputOptions.CropBeginningTime == 0.0 ? false : true;
            downloadOptions.CropBeginningTime = inputOptions.CropBeginningTime;
            downloadOptions.CropEnding        = inputOptions.CropEndingTime == 0.0 ? false : true;
            downloadOptions.CropEndingTime    = inputOptions.CropEndingTime;
            downloadOptions.Timestamp         = inputOptions.Timestamp;
            downloadOptions.EmbedEmotes       = inputOptions.EmbedEmotes;
            downloadOptions.Filename          = inputOptions.OutputFile;
            downloadOptions.TimeFormat        = inputOptions.TimeFormat;

            ChatDownloader            chatDownloader = new ChatDownloader(downloadOptions);
            Progress <ProgressReport> progress       = new Progress <ProgressReport>();

            progress.ProgressChanged += Progress_ProgressChanged;
            chatDownloader.DownloadAsync(progress, new CancellationToken()).Wait();
        }
コード例 #4
0
        private async void btnDownload_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            if (radioJson.IsChecked == true)
            {
                saveFileDialog.Filter = "JSON Files | *.json";
            }
            else
            {
                saveFileDialog.Filter = "TXT Files | *.txt";
            }

            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName         = MainWindow.GetFilename(Settings.Default.TemplateChat, textTitle.Text, downloadId, currentVideoTime, textStreamer.Text);

            if (saveFileDialog.ShowDialog() == true)
            {
                try
                {
                    ChatDownloadOptions downloadOptions = new ChatDownloadOptions()
                    {
                        IsJson = (bool)radioJson.IsChecked, Filename = saveFileDialog.FileName, Timestamp = true, EmbedEmotes = (bool)checkEmbed.IsChecked
                    };
                    if (downloadType == DownloadType.Video)
                    {
                        int startTime = 0;
                        int endTime   = 0;

                        if (checkStart.IsChecked == true)
                        {
                            downloadOptions.CropBeginning = true;
                            TimeSpan start = new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value);
                            startTime = (int)Math.Round(start.TotalSeconds);
                            downloadOptions.CropBeginningTime = startTime;
                        }

                        if (checkEnd.IsChecked == true)
                        {
                            downloadOptions.CropEnding = true;
                            TimeSpan end = new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value);
                            endTime = (int)Math.Round(end.TotalSeconds);
                            downloadOptions.CropEndingTime = endTime;
                        }

                        downloadOptions.Id = videoData["_id"].ToString().Substring(1);
                    }
                    else
                    {
                        downloadOptions.Id = downloadId;
                    }

                    ChatDownloader currentDownload = new ChatDownloader(downloadOptions);

                    btnGetInfo.IsEnabled = false;
                    SetEnabled(false, false);
                    SetImage("Images/ppOverheat.gif", true);
                    statusMessage.Text = "Downloading";

                    Progress <ProgressReport> downloadProgress = new Progress <ProgressReport>(OnProgressChanged);

                    try
                    {
                        await currentDownload.DownloadAsync(downloadProgress, new CancellationToken());

                        statusMessage.Text = "Done";
                        SetImage("Images/ppHop.gif", true);
                    }
                    catch (Exception ex)
                    {
                        statusMessage.Text = "ERROR";
                        SetImage("Images/peepoSad.png", false);
                        AppendLog("ERROR: " + ex.Message);
                    }
                    btnGetInfo.IsEnabled    = true;
                    statusProgressBar.Value = 0;
                }
                catch (Exception ex)
                {
                    AppendLog("ERROR: " + ex.Message);
                }
            }
        }