コード例 #1
0
        private void Browser_TitleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Title = Browser.Title.Replace("- YouTube", "");

            DisplayDjMode();

            Dispatcher.BeginInvoke((Action)(() =>
            {
                if (Browser.IsLoaded)
                {
                    // Save the last video that was played from either request or personal playlist by ID
                    CefSharpCache loadedCefSharpCache = CefSharpCache.Load();
                    loadedCefSharpCache.Url = Browser.Address;

                    if (Browser.Address.Contains($"list={YoutubeClient.SongRequestSetting.RequestPlaylistId}") &&
                        Browser.Address.Contains("v="))
                    {
                        loadedCefSharpCache.LastRequestPlaylistVideoId = _youTubeClientInstance.GetYouTubeVideoId(Browser.Address);
                    }
                    else if (Browser.Address.Contains($"list={YoutubeClient.SongRequestSetting.PersonalPlaylistId}") &&
                             Browser.Address.Contains("v="))
                    {
                        loadedCefSharpCache.LastPersonalPlaylistVideoId = _youTubeClientInstance.GetYouTubeVideoId(Browser.Address);
                    }

                    CefSharpCache.Save(loadedCefSharpCache);
                }
            }));
        }
コード例 #2
0
        private bool LookForNextVideo(YoutubePlaylistInfo youtubePlaylistInfo)
        {
            lock (_findNextVideoLock)
            {
                // Check if the YouTube progress bar is showing
                const string script = @"
                    (function() 
                    {
                        return !!(document.getElementsByTagName('yt-page-navigation-progress').offsetParent);
                    })();";

                var  response = Browser.EvaluateScriptAsync(script).Result;
                bool valid    = bool.TryParse(response.Result?.ToString(), out bool isProgressBarVisible);

                if (response.Message == null && response.Success && valid && isProgressBarVisible)
                {
                    return(false); // don't look until the progress bar is gone
                }

                CefSharpCache loadedCefSharpCache = CefSharpCache.Load();

                // Check if request playlist ID has been reset
                // If so, reset the last requested video ID
                if (loadedCefSharpCache.RequestPlaylistId != YoutubeClient.SongRequestSetting.RequestPlaylistId)
                {
                    loadedCefSharpCache.RequestPlaylistId          = YoutubeClient.SongRequestSetting.RequestPlaylistId;
                    loadedCefSharpCache.LastRequestPlaylistVideoId = null;
                    CefSharpCache.Save(loadedCefSharpCache);
                }

                /* Check if a video from the request playlist was played at all */
                if (string.IsNullOrEmpty(loadedCefSharpCache.LastRequestPlaylistVideoId))
                {
                    LoadFirstPlaylistVideo(YoutubeClient.SongRequestSetting.RequestPlaylistId);
                }
                else
                {
                    if (LoadNextPlaylistVideo(YoutubeClient.SongRequestSetting.RequestPlaylistId, loadedCefSharpCache.LastRequestPlaylistVideoId))
                    {
                        return(true);
                    }
                    else if (!string.IsNullOrEmpty(YoutubeClient.SongRequestSetting.PersonalPlaylistId))
                    {
                        /* Check if a video from the personal playlist was played at all */
                        if (string.IsNullOrEmpty(loadedCefSharpCache.LastPersonalPlaylistVideoId))
                        {
                            LoadFirstPlaylistVideo(YoutubeClient.SongRequestSetting.PersonalPlaylistId);
                        }
                        else
                        {
                            LoadNextPlaylistVideo(YoutubeClient.SongRequestSetting.PersonalPlaylistId, loadedCefSharpCache.LastPersonalPlaylistVideoId);
                        }
                    }
                }

                return(true);
            }
        }
コード例 #3
0
        private void Browser_IsBrowserInitializedChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            Dispatcher.BeginInvoke((Action)(async() =>
            {
                YoutubePlaylistInfo youtubePlaylistInfo = YoutubePlaylistInfo.Load();

                YoutubeClient.SongRequestSetting = await ApiBotRequest.GetExecuteTaskAsync <SongRequestSetting>(
                    youtubePlaylistInfo.TwitchBotApiLink + $"songrequestsettings/get/{youtubePlaylistInfo.BroadcasterId}");

                // reset cache file from last runtime
                CefSharpCache.Save(new CefSharpCache {
                    RequestPlaylistId = YoutubeClient.SongRequestSetting.RequestPlaylistId
                });

                if (!string.IsNullOrEmpty(YoutubeClient.SongRequestSetting.RequestPlaylistId))
                {
                    Browser.Load($"https://www.youtube.com/playlist?list={YoutubeClient.SongRequestSetting.RequestPlaylistId}");
                }
                else
                {
                    Browser.Load("https://www.youtube.com/");
                }
            }));
        }