Exemple #1
0
        private static void RenderChat(Options inputOptions)
        {
            ChatRenderOptions renderOptions = new ChatRenderOptions();

            renderOptions.InputFile       = inputOptions.InputFile;
            renderOptions.OutputFile      = inputOptions.OutputFile;
            renderOptions.BackgroundColor = SKColor.Parse(inputOptions.BackgroundColor);
            renderOptions.MessageColor    = SKColor.Parse(inputOptions.MessageColor);
            renderOptions.ChatHeight      = inputOptions.ChatHeight;
            renderOptions.ChatWidth       = inputOptions.ChatWidth;
            renderOptions.BttvEmotes      = inputOptions.BttvEmotes;
            renderOptions.FfzEmotes       = inputOptions.FfzEmotes;
            renderOptions.Outline         = inputOptions.Outline;
            renderOptions.OutlineSize     = inputOptions.OutlineSize;
            renderOptions.Font            = inputOptions.Font;
            renderOptions.FontSize        = inputOptions.FontSize;

            switch (inputOptions.MessageFontStyle.ToLower())
            {
            case "normal":
                renderOptions.MessageFontStyle = SKFontStyle.Normal;
                break;

            case "bold":
                renderOptions.MessageFontStyle = SKFontStyle.Bold;
                break;

            case "italic":
                renderOptions.MessageFontStyle = SKFontStyle.Italic;
                break;
            }

            switch (inputOptions.UsernameFontStyle.ToLower())
            {
            case "normal":
                renderOptions.UsernameFontStyle = SKFontStyle.Normal;
                break;

            case "bold":
                renderOptions.UsernameFontStyle = SKFontStyle.Bold;
                break;

            case "italic":
                renderOptions.UsernameFontStyle = SKFontStyle.Italic;
                break;
            }

            renderOptions.UpdateRate  = inputOptions.UpdateRate;
            renderOptions.PaddingLeft = inputOptions.PaddingLeft;
            renderOptions.Framerate   = inputOptions.Framerate;
            renderOptions.InputArgs   = inputOptions.InputArgs;
            renderOptions.OutputArgs  = inputOptions.OutputArgs;
            renderOptions.FfmpegPath  = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : inputOptions.FfmpegPath;

            ChatRenderer chatDownloader        = new ChatRenderer(renderOptions);
            Progress <ProgressReport> progress = new Progress <ProgressReport>();

            progress.ProgressChanged += Progress_ProgressChanged;
            chatDownloader.RenderVideoAsync(progress, new CancellationToken()).Wait();
        }
        public ChatRenderOptions GetOptions(string filename)
        {
            ChatRenderOptions options         = new ChatRenderOptions();
            SKColor           backgroundColor = new SKColor(colorBackground.SelectedColor.Value.R, colorBackground.SelectedColor.Value.G, colorBackground.SelectedColor.Value.B, colorBackground.SelectedColor.Value.A);
            SKColor           messageColor    = new SKColor(colorFont.SelectedColor.Value.R, colorFont.SelectedColor.Value.G, colorFont.SelectedColor.Value.B);

            options.OutputFile        = filename;
            options.InputFile         = textJson.Text;
            options.BackgroundColor   = backgroundColor;
            options.ChatHeight        = Int32.Parse(textHeight.Text);
            options.ChatWidth         = Int32.Parse(textWidth.Text);
            options.BttvEmotes        = (bool)checkBTTV.IsChecked;
            options.FfzEmotes         = (bool)checkFFZ.IsChecked;
            options.StvEmotes         = (bool)checkSTV.IsChecked;
            options.Outline           = (bool)checkOutline.IsChecked;
            options.Font              = (string)comboFont.SelectedItem;
            options.FontSize          = Double.Parse(textFontSize.Text);
            options.UpdateRate        = Double.Parse(textUpdateTime.Text);
            options.Timestamp         = (bool)checkTimestamp.IsChecked;
            options.MessageColor      = messageColor;
            options.Framerate         = Int32.Parse(textFramerate.Text);
            options.InputArgs         = Settings.Default.FfmpegInputArgs;
            options.OutputArgs        = Settings.Default.FfmpegOutputArgs;
            options.MessageFontStyle  = SKFontStyle.Normal;
            options.UsernameFontStyle = SKFontStyle.Bold;
            options.GenerateMask      = (bool)checkMask.IsChecked;
            options.OutlineSize       = 4;
            options.FfmpegPath        = "ffmpeg";
            options.TempFolder        = Settings.Default.TempPath;
            options.SubMessages       = (bool)checkSub.IsChecked;
            options.ChatBadges        = (bool)checkBadge.IsChecked;
            options.PaddingLeft       = (int)Math.Floor(2 * options.EmoteScale);
            return(options);
        }
        private async void btnRender_Click(object sender, RoutedEventArgs e)
        {
            bool validInputs = ValidateInputs();

            if (validInputs)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                string fileFormat = comboFormat.SelectedItem.ToString();
                saveFileDialog.Filter           = $"{fileFormat} Files | *.{fileFormat.ToLower()}";
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.FileName         = Path.GetFileNameWithoutExtension(textJson.Text) + "." + fileFormat.ToLower();

                if (saveFileDialog.ShowDialog() == true)
                {
                    SKColor backgroundColor = new SKColor(colorBackground.SelectedColor.Value.R, colorBackground.SelectedColor.Value.G, colorBackground.SelectedColor.Value.B, colorBackground.SelectedColor.Value.A);
                    SKColor messageColor    = new SKColor(colorFont.SelectedColor.Value.R, colorFont.SelectedColor.Value.G, colorFont.SelectedColor.Value.B);
                    SaveSettings();

                    ChatRenderOptions options = GetOptions(saveFileDialog.FileName);

                    SetImage("Images/ppOverheat.gif", true);
                    btnRender.IsEnabled = false;

                    ChatRenderer currentRender = new ChatRenderer(options);
                    Progress <ProgressReport> renderProgress = new Progress <ProgressReport>(OnProgressChanged);

                    try
                    {
                        await currentRender.RenderVideoAsync(renderProgress, 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);
                    }
                    statusProgressBar.Value = 0;
                    btnRender.IsEnabled     = true;
                }
            }
            else
            {
                MessageBox.Show("Please double check your inputs are valid", "Unable to parse inputs", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private SKBitmap DrawBadges(SKBitmap sectionImage, List<SKBitmap> imageList, ChatRenderOptions renderOptions, System.Drawing.Size canvasSize, ref System.Drawing.Point drawPos, PreviewComment previewComment)
        {
            foreach (string badgeString in previewComment.badges)
            {
                byte[] imageBytes = Convert.FromBase64String(badgeString);
                SKBitmap badgeImage = SKBitmap.Decode(imageBytes);
                using (SKCanvas sectionImageCanvas = new SKCanvas(sectionImage))
                {
                    float imageRatio = (float)(renderOptions.EmoteScale);
                    float imageSize = badgeImage.Width * imageRatio;
                    float left = (float)drawPos.X;
                    float right = imageSize + left;
                    float top = (float)((sectionImage.Height - imageSize) / 2);
                    float bottom = imageSize + top;
                    SKRect drawBox = new SKRect(left, top, right, bottom);
                    sectionImageCanvas.DrawBitmap(badgeImage, drawBox, imagePaint);
                    drawPos.X += (int)Math.Floor(20 * renderOptions.EmoteScale);
                }
            }

            return sectionImage;
        }
        public void Update(PageChatRender pageChatRender)
        {
            try
            {
                this.Width        = Int32.Parse(pageChatRender.textWidth.Text) + 10;
                this.Height       = Int32.Parse(pageChatRender.textHeight.Text) + 38;
                imgPreview.Height = Int32.Parse(pageChatRender.textHeight.Text);
                imgPreview.Width  = Int32.Parse(pageChatRender.textWidth.Text);
                PreviewData previewData = JsonConvert.DeserializeObject <PreviewData>(File.ReadAllText("preview_data.json"));
                BlockingCollection <TwitchCommentPreview> finalComments = new BlockingCollection <TwitchCommentPreview>();
                SKBitmap previewBitmap   = new SKBitmap((int)this.Width, (int)imgPreview.Height);
                SKColor  backgroundColor = new SKColor(pageChatRender.colorBackground.SelectedColor.Value.R, pageChatRender.colorBackground.SelectedColor.Value.G, pageChatRender.colorBackground.SelectedColor.Value.B);
                SKColor  messageColor    = new SKColor(pageChatRender.colorFont.SelectedColor.Value.R, pageChatRender.colorFont.SelectedColor.Value.G, pageChatRender.colorFont.SelectedColor.Value.B);

                ChatRenderOptions renderOptions = new ChatRenderOptions()
                {
                    InputFile         = pageChatRender.textJson.Text,
                    OutputFile        = "",
                    BackgroundColor   = backgroundColor,
                    ChatHeight        = Int32.Parse(pageChatRender.textHeight.Text),
                    ChatWidth         = Int32.Parse(pageChatRender.textWidth.Text),
                    BttvEmotes        = (bool)pageChatRender.checkBTTV.IsChecked,
                    FfzEmotes         = (bool)pageChatRender.checkFFZ.IsChecked,
                    Outline           = (bool)pageChatRender.checkOutline.IsChecked,
                    Font              = (string)pageChatRender.comboFont.SelectedItem,
                    FontSize          = Double.Parse(pageChatRender.textFontSize.Text),
                    UpdateRate        = Double.Parse(pageChatRender.textUpdateTime.Text),
                    Timestamp         = (bool)pageChatRender.checkTimestamp.IsChecked,
                    MessageColor      = messageColor,
                    Framerate         = Int32.Parse(pageChatRender.textFramerate.Text),
                    InputArgs         = Settings.Default.FfmpegInputArgs,
                    OutputArgs        = Settings.Default.FfmpegOutputArgs,
                    MessageFontStyle  = SKFontStyle.Normal,
                    UsernameFontStyle = SKFontStyle.Bold
                };
                System.Drawing.Size canvasSize = new System.Drawing.Size(renderOptions.ChatWidth, renderOptions.SectionHeight);
                SKPaint             nameFont   = new SKPaint()
                {
                    Typeface = SKTypeface.FromFamilyName(renderOptions.Font, renderOptions.UsernameFontStyle), LcdRenderText = true, SubpixelText = true, TextSize = (float)renderOptions.FontSize, IsAntialias = true, HintingLevel = SKPaintHinting.Full, FilterQuality = SKFilterQuality.High
                };
                SKPaint messageFont = new SKPaint()
                {
                    Typeface = SKTypeface.FromFamilyName(renderOptions.Font, renderOptions.MessageFontStyle), LcdRenderText = true, SubpixelText = true, TextSize = (float)renderOptions.FontSize, IsAntialias = true, HintingLevel = SKPaintHinting.Full, FilterQuality = SKFilterQuality.High, Color = renderOptions.MessageColor
                };
                List <ThirdPartyEmote>        thirdPartyEmotes = new List <ThirdPartyEmote>();
                Dictionary <string, SKBitmap> chatEmotes       = new Dictionary <string, SKBitmap>();
                Dictionary <string, SKBitmap> emojiCache       = new Dictionary <string, SKBitmap>();

                using (SKCanvas previewCanvas = new SKCanvas(previewBitmap))
                {
                    previewCanvas.Clear(backgroundColor);

                    foreach (PreviewEmote previewDataEmote in previewData.emotes)
                    {
                        byte[]   imageBytes  = Convert.FromBase64String(previewDataEmote.image);
                        SKBitmap emoteBitmap = SKBitmap.Decode(imageBytes);
                        SKCodec  emoteCodec;
                        using (MemoryStream ms = new MemoryStream(imageBytes))
                            emoteCodec = SKCodec.Create(ms);

                        ThirdPartyEmote emote = new ThirdPartyEmote(new List <SKBitmap>()
                        {
                            emoteBitmap
                        }, emoteCodec, previewDataEmote.name, ".png", "0", 1, imageBytes);
                        thirdPartyEmotes.Add(emote);
                    }

                    foreach (PreviewComment previewComment in previewData.comments)
                    {
                        int default_x = 2;
                        System.Drawing.Point drawPos        = new System.Drawing.Point(default_x, 0);
                        string            userName          = previewComment.name;
                        SKColor           userColor         = new SKColor(Convert.ToByte(previewComment.color.Substring(0, 2), 16), Convert.ToByte(previewComment.color.Substring(2, 2), 16), Convert.ToByte(previewComment.color.Substring(4, 2), 16));
                        List <SKBitmap>   imageList         = new List <SKBitmap>();
                        SKBitmap          sectionImage      = new SKBitmap(canvasSize.Width, canvasSize.Height);
                        List <GifEmote>   currentGifEmotes  = new List <GifEmote>();
                        List <SKBitmap>   emoteList         = new List <SKBitmap>();
                        List <CheerEmote> cheerEmotes       = new List <CheerEmote>();
                        List <SKRect>     emotePositionList = new List <SKRect>();
                        new SKCanvas(sectionImage).Clear(renderOptions.BackgroundColor);
                        Comment comment = new Comment();
                        comment.message = new Message();
                        Fragment msg = new Fragment();
                        msg.text = previewComment.message;
                        comment.message.fragments = new List <Fragment>();
                        comment.message.fragments.Add(msg);
                        if (renderOptions.Timestamp)
                        {
                            sectionImage = ChatRenderer.DrawTimestamp(sectionImage, imageList, messageFont, renderOptions, comment, canvasSize, ref drawPos, ref default_x);
                        }
                        if (previewComment.badges != null)
                        {
                            sectionImage = DrawBadges(sectionImage, imageList, renderOptions, canvasSize, ref drawPos, previewComment);
                        }
                        sectionImage = ChatRenderer.DrawUsername(sectionImage, imageList, renderOptions, nameFont, userName, userColor, canvasSize, ref drawPos);
                        sectionImage = ChatRenderer.DrawMessage(sectionImage, imageList, renderOptions, currentGifEmotes, messageFont, emojiCache, chatEmotes, thirdPartyEmotes, cheerEmotes, comment, canvasSize, ref drawPos, ref default_x, emoteList, emotePositionList);

                        int finalHeight = 0;
                        foreach (var img in imageList)
                        {
                            finalHeight += img.Height;
                        }
                        SKBitmap finalImage       = new SKBitmap(canvasSize.Width, finalHeight);
                        SKCanvas finalImageCanvas = new SKCanvas(finalImage);
                        finalHeight = 0;
                        foreach (var img in imageList)
                        {
                            finalImageCanvas.DrawBitmap(img, 0, finalHeight);
                            finalHeight += img.Height;
                            img.Dispose();
                        }

                        finalComments.Add(new TwitchCommentPreview(finalImage, Double.Parse(comment.content_offset_seconds.ToString()), currentGifEmotes, emoteList, emotePositionList));
                    }

                    int y          = 0;
                    int tempHeight = 0;
                    foreach (TwitchCommentPreview twitchCommentPreview in finalComments)
                    {
                        tempHeight += twitchCommentPreview.section.Height;
                    }
                    SKBitmap tempBitmap = new SKBitmap((int)this.Width, tempHeight);

                    using (SKCanvas tempCanvas = new SKCanvas(tempBitmap))
                    {
                        foreach (TwitchCommentPreview twitchCommentPreview in finalComments)
                        {
                            tempCanvas.DrawBitmap(twitchCommentPreview.section, 0, y, imagePaint);

                            for (int i = 0; i < twitchCommentPreview.normalEmotes.Count; i++)
                            {
                                SKRect refrenceRect = twitchCommentPreview.normalEmotesPositions[i];
                                tempCanvas.DrawBitmap(twitchCommentPreview.normalEmotes[i], new SKRect(refrenceRect.Left, refrenceRect.Top + y, refrenceRect.Right, refrenceRect.Bottom + y), imagePaint);
                            }

                            y += twitchCommentPreview.section.Height;
                        }
                    }

                    previewCanvas.DrawBitmap(tempBitmap, 0, previewBitmap.Height - tempBitmap.Height);
                }

                using (var stream = new MemoryStream())
                {
                    SKImage.FromBitmap(previewBitmap).Encode(SKEncodedImageFormat.Png, 100).SaveTo(stream);
                    var bitmap = new BitmapImage();
                    bitmap.BeginInit();
                    bitmap.StreamSource = stream;
                    bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmap.EndInit();
                    bitmap.Freeze();
                    imgPreview.Source = bitmap;
                }
            }
            catch
            {
                try
                {
                    this.Width        = 500;
                    this.Height       = 338;
                    imgPreview.Width  = 500;
                    imgPreview.Height = 300;

                    SKBitmap errorBitmap = new SKBitmap(500, 300);
                    using (SKCanvas skCanvas = new SKCanvas(errorBitmap))
                    {
                        skCanvas.DrawText("ERROR, UNABLE TO RENDER CHAT", 40, 150,
                                          new SKPaint()
                        {
                            Typeface    = SKTypeface.FromFamilyName("Arial", SKFontStyle.Bold), TextSize = 18,
                            IsAntialias = true, FilterQuality = SKFilterQuality.High
                        });
                        SKBitmap peepo = SKBitmap.Decode(Application
                                                         .GetResourceStream(new Uri("pack://application:,,,/Images/peepoSad.png")).Stream);
                        skCanvas.DrawBitmap(peepo, 370, 132);
                    }

                    using (var stream = new MemoryStream())
                    {
                        SKImage.FromBitmap(errorBitmap).Encode(SKEncodedImageFormat.Png, 100).SaveTo(stream);
                        var bitmap = new BitmapImage();
                        bitmap.BeginInit();
                        bitmap.StreamSource = stream;
                        bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                        bitmap.EndInit();
                        bitmap.Freeze();
                        imgPreview.Source = bitmap;
                    }
                }
                catch
                {
                }
            }
        }
Exemple #6
0
        private async void btnRender_Click(object sender, RoutedEventArgs e)
        {
            bool validInputs = ValidateInputs();

            if (validInputs)
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();

                string fileFormat = comboFormat.SelectedItem.ToString();
                saveFileDialog.Filter           = $"{fileFormat} Files | *.{fileFormat.ToLower()}";
                saveFileDialog.RestoreDirectory = true;
                saveFileDialog.FileName         = Path.GetFileNameWithoutExtension(textJson.Text) + "." + fileFormat.ToLower();

                if (saveFileDialog.ShowDialog() == true)
                {
                    SKColor backgroundColor = new SKColor(colorBackground.SelectedColor.Value.R, colorBackground.SelectedColor.Value.G, colorBackground.SelectedColor.Value.B, colorBackground.SelectedColor.Value.A);
                    SKColor messageColor    = new SKColor(colorFont.SelectedColor.Value.R, colorFont.SelectedColor.Value.G, colorFont.SelectedColor.Value.B);
                    SaveSettings();

                    ChatRenderOptions options = new ChatRenderOptions()
                    {
                        InputFile         = textJson.Text,
                        OutputFile        = saveFileDialog.FileName,
                        BackgroundColor   = backgroundColor,
                        ChatHeight        = Int32.Parse(textHeight.Text),
                        ChatWidth         = Int32.Parse(textWidth.Text),
                        BttvEmotes        = (bool)checkBTTV.IsChecked,
                        FfzEmotes         = (bool)checkFFZ.IsChecked,
                        Outline           = (bool)checkOutline.IsChecked,
                        Font              = (string)comboFont.SelectedItem,
                        FontSize          = Double.Parse(textFontSize.Text),
                        UpdateRate        = Double.Parse(textUpdateTime.Text),
                        Timestamp         = (bool)checkTimestamp.IsChecked,
                        MessageColor      = messageColor,
                        Framerate         = Int32.Parse(textFramerate.Text),
                        InputArgs         = Settings.Default.FfmpegInputArgs,
                        OutputArgs        = Settings.Default.FfmpegOutputArgs,
                        MessageFontStyle  = SKFontStyle.Normal,
                        UsernameFontStyle = SKFontStyle.Bold,
                        GenerateMask      = (bool)checkMask.IsChecked,
                        OutlineSize       = 4,
                        FfmpegPath        = "ffmpeg",
                        TempFolder        = Settings.Default.TempPath,
                        SubMessages       = (bool)checkSub.IsChecked
                    };
                    options.PaddingLeft = (int)Math.Floor(2 * options.EmoteScale);

                    SetImage("Images/ppOverheat.gif", true);
                    btnRender.IsEnabled = false;

                    ChatRenderer currentRender = new ChatRenderer(options);
                    Progress <ProgressReport> renderProgress = new Progress <ProgressReport>(OnProgressChanged);

                    try
                    {
                        await currentRender.RenderVideoAsync(renderProgress, 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);
                    }
                    statusProgressBar.Value = 0;
                    btnRender.IsEnabled     = true;
                }
            }
            else
            {
                MessageBox.Show("Please double check your inputs are valid", "Unable to parse inputs", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #7
0
        private static void RenderChat(Options inputOptions)
        {
            ChatRenderOptions renderOptions = new ChatRenderOptions();

            renderOptions.InputFile       = inputOptions.InputFile;
            renderOptions.OutputFile      = inputOptions.OutputFile;
            renderOptions.BackgroundColor = SKColor.Parse(inputOptions.BackgroundColor);
            renderOptions.MessageColor    = SKColor.Parse(inputOptions.MessageColor);
            renderOptions.ChatHeight      = inputOptions.ChatHeight;
            renderOptions.ChatWidth       = inputOptions.ChatWidth;
            renderOptions.BttvEmotes      = inputOptions.BttvEmotes;
            renderOptions.FfzEmotes       = inputOptions.FfzEmotes;
            renderOptions.Outline         = inputOptions.Outline;
            renderOptions.OutlineSize     = inputOptions.OutlineSize;
            renderOptions.Font            = inputOptions.Font;
            renderOptions.FontSize        = inputOptions.FontSize;

            switch (inputOptions.MessageFontStyle.ToLower())
            {
            case "normal":
                renderOptions.MessageFontStyle = SKFontStyle.Normal;
                break;

            case "bold":
                renderOptions.MessageFontStyle = SKFontStyle.Bold;
                break;

            case "italic":
                renderOptions.MessageFontStyle = SKFontStyle.Italic;
                break;
            }

            switch (inputOptions.UsernameFontStyle.ToLower())
            {
            case "normal":
                renderOptions.UsernameFontStyle = SKFontStyle.Normal;
                break;

            case "bold":
                renderOptions.UsernameFontStyle = SKFontStyle.Bold;
                break;

            case "italic":
                renderOptions.UsernameFontStyle = SKFontStyle.Italic;
                break;
            }

            renderOptions.UpdateRate   = inputOptions.UpdateRate;
            renderOptions.PaddingLeft  = inputOptions.PaddingLeft;
            renderOptions.Framerate    = inputOptions.Framerate;
            renderOptions.GenerateMask = inputOptions.GenerateMask;
            renderOptions.InputArgs    = inputOptions.InputArgs;
            renderOptions.OutputArgs   = inputOptions.OutputArgs;
            renderOptions.FfmpegPath   = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : Path.GetFullPath(inputOptions.FfmpegPath);
            renderOptions.TempFolder   = inputOptions.TempFolder;
            renderOptions.SubMessages  = inputOptions.SubMessages;

            if (renderOptions.GenerateMask && renderOptions.BackgroundColor.Alpha == 255)
            {
                Console.WriteLine("[WARNING] - Generate mask option has been selected with an opaque background. You most likely want to set a transparent background with --background-color \"#00000000\"");
            }

            ChatRenderer chatDownloader        = new ChatRenderer(renderOptions);
            Progress <ProgressReport> progress = new Progress <ProgressReport>();

            progress.ProgressChanged += Progress_ProgressChanged;
            chatDownloader.RenderVideoAsync(progress, new CancellationToken()).Wait();
        }
Exemple #8
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);
                    }
                }
            }
        }