public ChatDownloadOptions GetOptions(string filename)
        {
            ChatDownloadOptions options = new ChatDownloadOptions();

            options.IsJson      = (bool)radioJson.IsChecked;
            options.Timestamp   = true;
            options.EmbedEmotes = (bool)checkEmbed.IsChecked;
            options.Filename    = filename;
            return(options);
        }
예제 #2
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();
        }
예제 #3
0
 public ChatDownloader(ChatDownloadOptions DownloadOptions)
 {
     downloadOptions = DownloadOptions;
 }
예제 #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);
                }
            }
        }
예제 #5
0
        private void btnQueue_Click(object sender, RoutedEventArgs e)
        {
            if (parentPage != null)
            {
                if (parentPage is PageVodDownload)
                {
                    PageVodDownload vodPage    = (PageVodDownload)parentPage;
                    string          folderPath = textFolder.Text;
                    if (!String.IsNullOrWhiteSpace(folderPath) && Directory.Exists(folderPath))
                    {
                        VodDownloadTask      downloadTask    = new VodDownloadTask();
                        VideoDownloadOptions downloadOptions = vodPage.GetOptions(null, textFolder.Text);
                        downloadTask.DownloadOptions = downloadOptions;
                        downloadTask.Info.Title      = vodPage.textTitle.Text;
                        downloadTask.Info.Thumbnail  = vodPage.imgThumbnail.Source;
                        downloadTask.Status          = TwitchTasks.TwitchTaskStatus.Ready;

                        lock (PageQueue.taskLock)
                        {
                            PageQueue.taskList.Add(downloadTask);
                        }

                        if ((bool)checkChat.IsChecked)
                        {
                            ChatDownloadTask    chatTask    = new ChatDownloadTask();
                            ChatDownloadOptions chatOptions = MainWindow.pageChatDownload.GetOptions(null);
                            chatOptions.Id          = downloadOptions.Id.ToString();
                            chatOptions.IsJson      = (bool)radioJson.IsChecked;
                            chatOptions.EmbedEmotes = (bool)checkEmbed.IsChecked;
                            chatOptions.Filename    = Path.Combine(folderPath, MainWindow.GetFilename(Settings.Default.TemplateChat, downloadTask.Info.Title, chatOptions.Id, vodPage.currentVideoTime, vodPage.textStreamer.Text) + (chatOptions.IsJson ? ".json" : ".txt"));

                            if (downloadOptions.CropBeginning)
                            {
                                chatOptions.CropBeginning     = true;
                                chatOptions.CropBeginningTime = downloadOptions.CropBeginningTime;
                            }

                            if (downloadOptions.CropEnding)
                            {
                                chatOptions.CropEnding     = true;
                                chatOptions.CropEndingTime = downloadOptions.CropEndingTime;
                            }

                            chatTask.DownloadOptions = chatOptions;
                            chatTask.Info.Title      = vodPage.textTitle.Text;
                            chatTask.Info.Thumbnail  = vodPage.imgThumbnail.Source;
                            chatTask.Status          = TwitchTasks.TwitchTaskStatus.Ready;

                            lock (PageQueue.taskLock)
                            {
                                PageQueue.taskList.Add(chatTask);
                            }

                            if ((bool)checkRender.IsChecked && chatOptions.IsJson)
                            {
                                ChatRenderTask    renderTask    = new ChatRenderTask();
                                ChatRenderOptions renderOptions = MainWindow.pageChatRender.GetOptions(Path.ChangeExtension(chatOptions.Filename, ".mp4"));
                                if (renderOptions.OutputFile.Trim() == downloadOptions.Filename.Trim())
                                {
                                    //Just in case VOD and chat paths are the same. Like the previous defaults
                                    renderOptions.OutputFile = Path.ChangeExtension(chatOptions.Filename, " - CHAT.mp4");
                                }
                                renderOptions.InputFile    = chatOptions.Filename;
                                renderTask.DownloadOptions = renderOptions;
                                renderTask.Info.Title      = vodPage.textTitle.Text;
                                renderTask.Info.Thumbnail  = vodPage.imgThumbnail.Source;
                                renderTask.Status          = TwitchTasks.TwitchTaskStatus.Waiting;
                                renderTask.DependantTask   = chatTask;

                                lock (PageQueue.taskLock)
                                {
                                    PageQueue.taskList.Add(renderTask);
                                }
                            }
                        }

                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Invalid folder path (doesn't exist?)", "Invalid Folder Path", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }

                if (parentPage is PageClipDownload)
                {
                    PageClipDownload clipPage   = (PageClipDownload)parentPage;
                    string           folderPath = textFolder.Text;
                    if (!String.IsNullOrWhiteSpace(folderPath) && Directory.Exists(folderPath))
                    {
                        ClipDownloadTask    downloadTask    = new ClipDownloadTask();
                        ClipDownloadOptions downloadOptions = new ClipDownloadOptions();
                        downloadOptions.Filename     = Path.Combine(folderPath, MainWindow.GetFilename(Settings.Default.TemplateClip, clipPage.textTitle.Text, clipPage.clipId, clipPage.currentVideoTime, clipPage.textStreamer.Text) + ".mp4");
                        downloadOptions.Id           = clipPage.clipId;
                        downloadOptions.Quality      = clipPage.comboQuality.Text;
                        downloadTask.DownloadOptions = downloadOptions;
                        downloadTask.Info.Title      = clipPage.textTitle.Text;
                        downloadTask.Info.Thumbnail  = clipPage.imgThumbnail.Source;
                        downloadTask.Status          = TwitchTasks.TwitchTaskStatus.Ready;

                        lock (PageQueue.taskLock)
                        {
                            PageQueue.taskList.Add(downloadTask);
                        }

                        if ((bool)checkChat.IsChecked)
                        {
                            ChatDownloadTask    chatTask    = new ChatDownloadTask();
                            ChatDownloadOptions chatOptions = MainWindow.pageChatDownload.GetOptions(null);
                            chatOptions.Id          = downloadOptions.Id.ToString();
                            chatOptions.IsJson      = (bool)radioJson.IsChecked;
                            chatOptions.TimeFormat  = TimestampFormat.Relative;
                            chatOptions.EmbedEmotes = (bool)checkEmbed.IsChecked;
                            chatOptions.Filename    = Path.Combine(folderPath, MainWindow.GetFilename(Settings.Default.TemplateChat, downloadTask.Info.Title, chatOptions.Id, clipPage.currentVideoTime, clipPage.textStreamer.Text) + (chatOptions.IsJson ? ".json" : ".txt"));

                            chatTask.DownloadOptions = chatOptions;
                            chatTask.Info.Title      = clipPage.textTitle.Text;
                            chatTask.Info.Thumbnail  = clipPage.imgThumbnail.Source;
                            chatTask.Status          = TwitchTasks.TwitchTaskStatus.Ready;

                            lock (PageQueue.taskLock)
                            {
                                PageQueue.taskList.Add(chatTask);
                            }

                            if ((bool)checkRender.IsChecked && chatOptions.IsJson)
                            {
                                ChatRenderTask    renderTask    = new ChatRenderTask();
                                ChatRenderOptions renderOptions = MainWindow.pageChatRender.GetOptions(Path.ChangeExtension(chatOptions.Filename, ".mp4"));
                                if (renderOptions.OutputFile.Trim() == downloadOptions.Filename.Trim())
                                {
                                    //Just in case VOD and chat paths are the same. Like the previous defaults
                                    renderOptions.OutputFile = Path.ChangeExtension(chatOptions.Filename, " - CHAT.mp4");
                                }
                                renderOptions.InputFile    = chatOptions.Filename;
                                renderTask.DownloadOptions = renderOptions;
                                renderTask.Info.Title      = clipPage.textTitle.Text;
                                renderTask.Info.Thumbnail  = clipPage.imgThumbnail.Source;
                                renderTask.Status          = TwitchTasks.TwitchTaskStatus.Waiting;
                                renderTask.DependantTask   = chatTask;

                                lock (PageQueue.taskLock)
                                {
                                    PageQueue.taskList.Add(renderTask);
                                }
                            }
                        }

                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Invalid folder path (doesn't exist?)", "Invalid Folder Path", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }

                if (parentPage is PageChatDownload)
                {
                    PageChatDownload chatPage   = (PageChatDownload)parentPage;
                    string           folderPath = textFolder.Text;
                    if (!String.IsNullOrWhiteSpace(folderPath) && Directory.Exists(folderPath))
                    {
                        ChatDownloadTask    chatTask    = new ChatDownloadTask();
                        ChatDownloadOptions chatOptions = MainWindow.pageChatDownload.GetOptions(null);
                        chatOptions.Id       = chatPage.downloadId;
                        chatOptions.Filename = Path.Combine(folderPath, MainWindow.GetFilename(Settings.Default.TemplateChat, chatPage.textTitle.Text, chatOptions.Id, chatPage.currentVideoTime, chatPage.textStreamer.Text) + (chatOptions.IsJson ? ".json" : ".txt"));

                        chatTask.DownloadOptions = chatOptions;
                        chatTask.Info.Title      = chatPage.textTitle.Text;
                        chatTask.Info.Thumbnail  = chatPage.imgThumbnail.Source;
                        chatTask.Status          = TwitchTasks.TwitchTaskStatus.Ready;

                        lock (PageQueue.taskLock)
                        {
                            PageQueue.taskList.Add(chatTask);
                        }

                        if ((bool)checkRender.IsChecked && chatOptions.IsJson)
                        {
                            ChatRenderTask    renderTask    = new ChatRenderTask();
                            ChatRenderOptions renderOptions = MainWindow.pageChatRender.GetOptions(Path.ChangeExtension(chatOptions.Filename, ".mp4"));
                            renderOptions.InputFile    = chatOptions.Filename;
                            renderTask.DownloadOptions = renderOptions;
                            renderTask.Info.Title      = chatPage.textTitle.Text;
                            renderTask.Info.Thumbnail  = chatPage.imgThumbnail.Source;
                            renderTask.Status          = TwitchTasks.TwitchTaskStatus.Waiting;
                            renderTask.DependantTask   = chatTask;

                            lock (PageQueue.taskLock)
                            {
                                PageQueue.taskList.Add(renderTask);
                            }
                        }

                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Invalid folder path (doesn't exist?)", "Invalid Folder Path", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }

                if (parentPage is PageChatRender)
                {
                    PageChatRender renderPage = (PageChatRender)parentPage;
                    string         folderPath = textFolder.Text;
                    if (!String.IsNullOrWhiteSpace(folderPath) && Directory.Exists(folderPath))
                    {
                        ChatRenderTask    renderTask    = new ChatRenderTask();
                        string            fileFormat    = renderPage.comboFormat.SelectedItem.ToString();
                        string            filePath      = Path.Combine(folderPath, Path.GetFileNameWithoutExtension(renderPage.textJson.Text) + "." + fileFormat.ToLower());
                        ChatRenderOptions renderOptions = MainWindow.pageChatRender.GetOptions(filePath);
                        renderTask.DownloadOptions = renderOptions;
                        renderTask.Info.Title      = Path.GetFileNameWithoutExtension(filePath);
                        renderTask.Status          = TwitchTasks.TwitchTaskStatus.Ready;

                        lock (PageQueue.taskLock)
                        {
                            PageQueue.taskList.Add(renderTask);
                        }

                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Invalid folder path (doesn't exist?)", "Invalid Folder Path", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
            else
            {
                if (dataList.Count > 0)
                {
                    string folderPath = textFolder.Text;
                    if (!String.IsNullOrWhiteSpace(folderPath) && Directory.Exists(folderPath))
                    {
                        for (int i = 0; i < dataList.Count; i++)
                        {
                            if ((bool)checkVideo.IsChecked)
                            {
                                if (dataList[i].Id.All(Char.IsDigit))
                                {
                                    VodDownloadTask      downloadTask    = new VodDownloadTask();
                                    VideoDownloadOptions downloadOptions = new VideoDownloadOptions();
                                    downloadOptions.Oauth           = Settings.Default.OAuth;
                                    downloadOptions.TempFolder      = Settings.Default.TempPath;
                                    downloadOptions.Id              = int.Parse(dataList[i].Id);
                                    downloadOptions.FfmpegPath      = "ffmpeg";
                                    downloadOptions.CropBeginning   = false;
                                    downloadOptions.CropEnding      = false;
                                    downloadOptions.DownloadThreads = Settings.Default.VodDownloadThreads;
                                    downloadOptions.Filename        = Path.Combine(folderPath, MainWindow.GetFilename(Settings.Default.TemplateVod, dataList[i].Title, dataList[i].Id, dataList[i].Time, dataList[i].Streamer) + ".mp4");
                                    downloadTask.DownloadOptions    = downloadOptions;
                                    downloadTask.Info.Title         = dataList[i].Title;
                                    downloadTask.Info.Thumbnail     = dataList[i].Thumbnail;
                                    downloadTask.Status             = TwitchTaskStatus.Ready;

                                    lock (PageQueue.taskLock)
                                    {
                                        PageQueue.taskList.Add(downloadTask);
                                    }
                                }
                                else
                                {
                                    ClipDownloadTask    downloadTask    = new ClipDownloadTask();
                                    ClipDownloadOptions downloadOptions = new ClipDownloadOptions();
                                    downloadOptions.Id           = dataList[i].Id;
                                    downloadOptions.Filename     = Path.Combine(folderPath, MainWindow.GetFilename(Settings.Default.TemplateClip, dataList[i].Title, dataList[i].Id, dataList[i].Time, dataList[i].Streamer) + ".mp4");
                                    downloadTask.DownloadOptions = downloadOptions;
                                    downloadTask.Info.Title      = dataList[i].Title;
                                    downloadTask.Info.Thumbnail  = dataList[i].Thumbnail;
                                    downloadTask.Status          = TwitchTaskStatus.Ready;

                                    lock (PageQueue.taskLock)
                                    {
                                        PageQueue.taskList.Add(downloadTask);
                                    }
                                }
                            }

                            if ((bool)checkChat.IsChecked)
                            {
                                ChatDownloadTask    downloadTask    = new ChatDownloadTask();
                                ChatDownloadOptions downloadOptions = new ChatDownloadOptions();
                                downloadOptions.IsJson        = (bool)radioJson.IsChecked;
                                downloadOptions.EmbedEmotes   = (bool)checkEmbed.IsChecked;
                                downloadOptions.TimeFormat    = TimestampFormat.Relative;
                                downloadOptions.Id            = dataList[i].Id;
                                downloadOptions.CropBeginning = false;
                                downloadOptions.CropEnding    = false;
                                downloadOptions.Filename      = Path.Combine(folderPath, MainWindow.GetFilename(Settings.Default.TemplateChat, dataList[i].Title, dataList[i].Id, dataList[i].Time, dataList[i].Streamer) + (downloadOptions.IsJson ? ".json" : ".txt"));
                                downloadTask.DownloadOptions  = downloadOptions;
                                downloadTask.Info.Title       = dataList[i].Title;
                                downloadTask.Info.Thumbnail   = dataList[i].Thumbnail;
                                downloadTask.Status           = TwitchTaskStatus.Ready;

                                lock (PageQueue.taskLock)
                                {
                                    PageQueue.taskList.Add(downloadTask);
                                }

                                if ((bool)checkRender.IsChecked && downloadOptions.IsJson)
                                {
                                    ChatRenderTask    renderTask    = new ChatRenderTask();
                                    ChatRenderOptions renderOptions = MainWindow.pageChatRender.GetOptions(Path.ChangeExtension(downloadOptions.Filename, ".mp4"));
                                    if (renderOptions.OutputFile.Trim() == downloadOptions.Filename.Trim())
                                    {
                                        //Just in case VOD and chat paths are the same. Like the previous defaults
                                        renderOptions.OutputFile = Path.ChangeExtension(downloadOptions.Filename, " - CHAT.mp4");
                                    }
                                    renderOptions.InputFile    = downloadOptions.Filename;
                                    renderTask.DownloadOptions = renderOptions;
                                    renderTask.Info.Title      = dataList[i].Title;
                                    renderTask.Info.Thumbnail  = dataList[i].Thumbnail;
                                    renderTask.Status          = TwitchTasks.TwitchTaskStatus.Waiting;
                                    renderTask.DependantTask   = downloadTask;

                                    lock (PageQueue.taskLock)
                                    {
                                        PageQueue.taskList.Add(renderTask);
                                    }
                                }
                            }
                        }

                        this.DialogResult = true;
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Invalid folder path (doesn't exist?)", "Invalid Folder Path", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }
            }
        }