示例#1
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);
                    }
                }
            }
        }
示例#2
0
        private async void btnQueue_Click(object sender, RoutedEventArgs e)
        {
            btnQueue.IsEnabled = false;
            List <string>               idList      = new List <string>();
            List <string>               urlList     = new List <string>(textList.Text.Split('\n').Where(x => x.Trim() != ""));
            List <string>               invalidList = new List <string>();
            List <string>               errorList   = new List <string>();
            List <TaskData>             dataList    = new List <TaskData>();
            Dictionary <string, string> idDict      = new Dictionary <string, string>();

            foreach (var url in urlList)
            {
                string id = PageChatDownload.ValidateUrl(url);

                if (id == "")
                {
                    invalidList.Add(url);
                }
                else
                {
                    idList.Add(id);
                    idDict[id] = url;
                }
            }

            if (invalidList.Count > 0)
            {
                MessageBox.Show("Please double check the VOD/Clip link", "Unable to parse inputs\n" + String.Join("\n", invalidList.ToArray()), MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            Dictionary <int, string>        taskDict      = new Dictionary <int, string>();
            List <Task <GqlVideoResponse> > taskVideoList = new List <Task <GqlVideoResponse> >();
            List <Task <GqlClipResponse> >  taskClipList  = new List <Task <GqlClipResponse> >();

            foreach (var id in idList)
            {
                if (id.All(Char.IsDigit))
                {
                    Task <GqlVideoResponse> task = TwitchHelper.GetVideoInfo(int.Parse(id));
                    taskVideoList.Add(task);
                    taskDict[task.Id] = id;
                }
                else
                {
                    Task <GqlClipResponse> task = TwitchHelper.GetClipInfo(id);
                    taskClipList.Add(task);
                    taskDict[task.Id] = id;
                }
            }

            try
            {
                await Task.WhenAll(taskVideoList.ToArray());
            }
            catch { }
            try
            {
                await Task.WhenAll(taskClipList.ToArray());
            }
            catch { }

            for (int i = 0; i < taskVideoList.Count; i++)
            {
                if (taskVideoList[i].IsCompleted)
                {
                    string id = taskDict[taskVideoList[i].Id];
                    if (!taskVideoList[i].IsFaulted)
                    {
                        GqlVideoResponse data    = taskVideoList[i].Result;
                        TaskData         newData = new TaskData();
                        newData.Id = id;
                        try
                        {
                            string thumbUrl    = data.data.video.thumbnailURLs.FirstOrDefault();
                            var    bitmapImage = new BitmapImage();
                            bitmapImage.BeginInit();
                            bitmapImage.UriSource = new Uri(thumbUrl);
                            bitmapImage.EndInit();
                            newData.Thumbnail = bitmapImage;
                        }
                        catch { }
                        newData.Title    = data.data.video.title;
                        newData.Streamer = data.data.video.owner.displayName;
                        newData.Time     = data.data.video.createdAt.ToLocalTime();
                        dataList.Add(newData);
                    }
                    else
                    {
                        errorList.Add(idDict[id]);
                    }
                }
            }

            for (int i = 0; i < taskClipList.Count; i++)
            {
                if (taskClipList[i].IsCompleted)
                {
                    string id = taskDict[taskClipList[i].Id];
                    if (!taskClipList[i].IsFaulted)
                    {
                        GqlClipResponse data    = taskClipList[i].Result;
                        TaskData        newData = new TaskData();
                        newData.Id = id;
                        try
                        {
                            string thumbUrl    = data.data.clip.thumbnailURL;
                            var    bitmapImage = new BitmapImage();
                            bitmapImage.BeginInit();
                            bitmapImage.UriSource = new Uri(thumbUrl);
                            bitmapImage.EndInit();
                            newData.Thumbnail = bitmapImage;
                        }
                        catch { }
                        newData.Title    = data.data.clip.title;
                        newData.Streamer = data.data.clip.broadcaster.displayName;
                        newData.Time     = data.data.clip.createdAt.ToLocalTime();
                        dataList.Add(newData);
                    }
                    else
                    {
                        errorList.Add(idDict[id]);
                    }
                }
            }

            if (errorList.Count > 0)
            {
                MessageBox.Show("Error getting VOD/Clip information", "Unable to get info for these VODs/Clips\n" + String.Join("\n", errorList.ToArray()), MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            WindowQueueOptions queue = new WindowQueueOptions(dataList);
            bool?queued = queue.ShowDialog();

            if (queued != null && (bool)queued)
            {
                this.Close();
            }

            btnQueue.IsEnabled = true;
        }