Ejemplo n.º 1
0
        public static async Task <Channel> GetMyChannel(YouTubeConnection connection)
        {
            Channel channel = await connection.Channels.GetMyChannel();

            Assert.IsNotNull(channel);
            Assert.IsNotNull(channel.Id);

            return(channel);
        }
        public void ConnectWithOldOAuthToken()
        {
            TestWrapper(async(YouTubeConnection connection) =>
            {
                YouTubeConnection connection2 = await YouTubeConnection.ConnectViaOAuthToken(connection.GetOAuthTokenCopy());

                YouTubeConnection connection3 = await YouTubeConnection.ConnectViaOAuthToken(connection2.GetOAuthTokenCopy());
            });
        }
 public void GetAuthorizationCodeURLForOAuth()
 {
     TestWrapper((YouTubeConnection connection) =>
     {
         string url = YouTubeConnection.GetAuthorizationCodeURLForOAuthBrowser(UnitTestBase.clientID, UnitTestBase.scopes, YouTubeConnection.DEFAULT_OAUTH_LOCALHOST_URL).Result;
         Assert.IsNotNull(url);
         return(Task.FromResult(0));
     });
 }
Ejemplo n.º 4
0
        public static YouTubeConnection GetYouTubeLiveClient()
        {
            if (UnitTestBase.connection == null)
            {
                UnitTestBase.connection = YouTubeConnection.ConnectViaLocalhostOAuthBrowser(clientID, clientSecret, scopes).Result;
            }

            Assert.IsNotNull(UnitTestBase.connection);
            return(UnitTestBase.connection);
        }
        public static void Main(string[] args)
        {
            Logger.SetLogLevel(LogLevel.Debug);

            Logger.LogOccurred += Logger_LogOccurred;
            Task.Run(async () =>
            {
                try
                {
                    System.Console.WriteLine("Initializing connection");

                    YouTubeConnection connection = await YouTubeConnection.ConnectViaLocalhostOAuthBrowser(clientID, clientSecret, scopes);
                    if (connection != null)
                    {
                        Channel channel = await connection.Channels.GetMyChannel();

                        //Channel channel = await connection.Channels.GetChannelByID("");

                        if (channel != null)
                        {
                            System.Console.WriteLine("Connection successful. Logged in as: " + channel.Snippet.Title);

                            LiveBroadcast broadcast = await connection.LiveBroadcasts.GetChannelActiveBroadcast(channel);

                            System.Console.WriteLine("Connecting chat client!");

                            ChatClient client = new ChatClient(connection);
                            client.OnMessagesReceived += Client_OnMessagesReceived;

                            if (await client.Connect(broadcast))
                            {
                                System.Console.WriteLine("Live chat connection successful!");

                                if (await connection.LiveBroadcasts.GetMyActiveBroadcast() != null)
                                {
                                    await client.SendMessage("Hello World!");
                                }

                                while (true) { }
                            }
                            else
                            {
                                System.Console.WriteLine("Failed to connect to live chat");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            });

            System.Console.ReadLine();
        }
Ejemplo n.º 6
0
        internal static IEnumerator InitGlobalChatHandlers()
        {
            Twitch  = new ChatIntegration <ITwitchIntegration>();
            YouTube = new ChatIntegration <IYouTubeIntegration>();
            Mixer   = new ChatIntegration <IMixerIntegration>();
            Global  = new ChatIntegration <IGlobalChatIntegration>();

            bool initTwitch = false, initYouTube = false, initMixer = false;

            // Iterate through all the message handlers that were registered
            foreach (var instance in registeredInstances)
            {
                var instanceType = instance.Value.GetType();
                var typeName     = instanceType.Name;

                // Wait for all the registered handlers to be ready
                if (!instance.Value.IsPluginReady)
                {
                    Plugin.Log($"Instance of type {typeName} wasn't ready! Waiting until it is...");
                    yield return(new WaitUntil(() => instance.Value.IsPluginReady));

                    Plugin.Log($"Instance of type {typeName} is ready!");
                }

                bool isGlobalIntegration = typeof(IGlobalChatIntegration).IsAssignableFrom(instanceType);
                // Mark the correct services for initialization based on type
                if (typeof(ITwitchIntegration).IsAssignableFrom(instanceType) || isGlobalIntegration)
                {
                    initTwitch = true;
                }
                if (typeof(IYouTubeIntegration).IsAssignableFrom(instanceType) || isGlobalIntegration)
                {
                    initYouTube = true;
                }
                if (typeof(IMixerIntegration).IsAssignableFrom(instanceType) || isGlobalIntegration)
                {
                    initMixer = true;
                }
            }

            // Initialize the appropriate streaming services
            if (initTwitch)
            {
                TwitchWebSocketClient.Initialize_Internal();
            }
            if (initYouTube)
            {
                YouTubeConnection.Initialize_Internal();
            }
            if (initMixer)
            {
                MixerClient.Initialize_Internal();
            }
        }
Ejemplo n.º 7
0
        public void OnApplicationQuit()
        {
            SceneManager.activeSceneChanged -= SceneManager_activeSceneChanged;
            SceneManager.sceneLoaded        -= SceneManager_sceneLoaded;

            Globals.IsApplicationExiting = true;

            // Cancel all running tasks
            TaskHelper.CancelAllTasks();

            // Shutdown our twitch client if it's initialized
            TwitchWebSocketClient.Shutdown();
            YouTubeConnection.Stop();
        }
Ejemplo n.º 8
0
        internal static IEnumerator CreateGlobalMessageHandlers()
        {
            // Attempt to initialize message handlers for each of our chat services
            TwitchMessageHandler.Instance.InitializeMessageHandlers();
            YouTubeMessageHandler.Instance.InitializeMessageHandlers();
            GlobalMessageHandler.Instance.InitializeMessageHandlers();

            bool initTwitch = false, initYouTube = false;

            // Iterate through all the message handlers that were registered
            foreach (var instance in GlobalMessageHandler.registeredInstances)
            {
                var instanceType = instance.Value.GetType();
                var typeName     = instanceType.Name;

                // Wait for all the registered handlers to be ready
                if (!instance.Value.ChatCallbacksReady)
                {
                    Plugin.Log($"Instance of type {typeName} wasn't ready! Waiting until it is...");
                    yield return(new WaitUntil(() => instance.Value.ChatCallbacksReady));

                    Plugin.Log($"Instance of type {typeName} is ready!");
                }

                // Mark the correct services for initialization based on type
                if (typeof(ITwitchMessageHandler).IsAssignableFrom(instanceType))
                {
                    initTwitch = true;
                }
                if (typeof(IYouTubeMessageHandler).IsAssignableFrom(instanceType))
                {
                    initYouTube = true;
                }
                if (typeof(IGlobalMessageHandler).IsAssignableFrom(instanceType))
                {
                    initTwitch  = true;
                    initYouTube = true;
                }
            }

            // Initialize the appropriate streaming services
            if (initTwitch)
            {
                TwitchWebSocketClient.Initialize_Internal();
            }
            if (initYouTube)
            {
                YouTubeConnection.Initialize_Internal();
            }
        }
Ejemplo n.º 9
0
        public void OnApplicationStart()
        {
            if (Instance != null)
            {
                return;
            }
            Instance   = this;
            ChatConfig = new ChatConfig();

            TwitchWebSocketClient.Initialize();
            YouTubeConnection.Initialize();

            SharedCoroutineStarter.instance.StartCoroutine(DelayedStartup());
        }
Ejemplo n.º 10
0
        public static void Main(string[] args)
        {
            Logger.LogOccurred += Logger_LogOccurred;
            Task.Run(async() =>
            {
                try
                {
                    if (string.IsNullOrEmpty(clientID) || string.IsNullOrEmpty(clientSecret))
                    {
                        throw new InvalidOperationException("Client ID and/or Client Secret are not set in the UnitTestBase class");
                    }

                    System.Console.WriteLine("Initializing connection");

                    YouTubeConnection connection = await YouTubeConnection.ConnectViaLocalhostOAuthBrowser(clientID, clientSecret, scopes);
                    if (connection != null)
                    {
                        Channel channel = await connection.Channels.GetMyChannel();
                        if (channel != null)
                        {
                            System.Console.WriteLine("Connection successful. Logged in as: " + channel.Snippet.Title);

                            System.Console.WriteLine("Connecting chat client!");

                            ChatClient client          = new ChatClient(connection);
                            client.OnMessagesReceived += Client_OnMessagesReceived;
                            if (await client.Connect())
                            {
                                System.Console.WriteLine("Live chat connection successful!");

                                while (true)
                                {
                                }
                            }
                            else
                            {
                                System.Console.WriteLine("Failed to connect to live chat");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            });

            System.Console.ReadLine();
        }
Ejemplo n.º 11
0
        protected static void TestWrapper(Func <YouTubeConnection, Task> function)
        {
            if (string.IsNullOrEmpty(clientID) || string.IsNullOrEmpty(clientSecret))
            {
                throw new InvalidOperationException("Client ID and/or Client Secret are not set in the UnitTestBase class");
            }

            try
            {
                YouTubeConnection connection = UnitTestBase.GetYouTubeLiveClient();
                function(connection).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
Ejemplo n.º 12
0
        public YouTubeBot(YouTubeSettings settings, PokeTradeHub <PK8> hub)
        {
            Hub                 = hub;
            Settings            = settings;
            Logger.LogOccurred += Logger_LogOccurred;

            try
            {
                Task.Run(async() =>
                {
                    var connection = await YouTubeConnection.ConnectViaLocalhostOAuthBrowser(Settings.ClientID, Settings.ClientSecret, Scopes.scopes, true);
                    if (connection != null)
                    {
                        channel = await connection.Channels.GetChannelByID(Settings.ChannelID);
                        if (channel != null)
                        {
                            client = new ChatClient(connection);

                            client.OnMessagesReceived += Client_OnMessagesReceived;
                            if (await client.Connect())
                            {
                                await Task.Delay(-1);
                            }
                            else
                            {
                            }
                        }
                    }
                    EchoUtil.Forwarders.Add(msg => client.SendMessage(msg));
                });
            }
            catch (Exception ex)
            {
                LogUtil.LogError(ex.Message, "YouTubeBot");
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Creates an instance of the ChannelsService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public ChannelsService(YouTubeConnection connection) : base(connection)
 {
 }
Ejemplo n.º 14
0
 /// <summary>
 /// Creates an instance of the VideosService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public VideosService(YouTubeConnection connection) : base(connection)
 {
 }
 /// <summary>
 /// Creates an instance of the YouTubeServiceBase.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 /// <param name="baseAddress">The base address to use</param>
 public YouTubeServiceBase(YouTubeConnection connection, string baseAddress)
 {
     Validator.ValidateVariable(connection, "connection");
     this.connection  = connection;
     this.baseAddress = baseAddress;
 }
 /// <summary>
 /// Creates an instance of the CommentsService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public CommentsService(YouTubeConnection connection) : base(connection)
 {
 }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates an instance of the OAuthService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public OAuthService(YouTubeConnection connection) : base(connection, OAuthBaseAddress)
 {
 }
 /// <summary>
 /// Creates an instance of the YouTubeServiceBase.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public YouTubeServiceBase(YouTubeConnection connection) : this(connection, YouTubeRestAPIBaseAddressFormat)
 {
 }
 /// <summary>
 /// Creates an instance of the SubscriptionsService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public SubscriptionsService(YouTubeConnection connection) : base(connection)
 {
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Creates a new instance of the ChatClient class.
 /// </summary>
 /// <param name="connection">The connection to YouTube</param>
 public ChatClient(YouTubeConnection connection) : base(connection)
 {
 }
Ejemplo n.º 21
0
        public static void Main(string[] args)
        {
            Logger.LogOccurred += Logger_LogOccurred;
            Task.Run(async() =>
            {
                try
                {
                    if (string.IsNullOrEmpty(clientID) || string.IsNullOrEmpty(clientSecret))
                    {
                        throw new InvalidOperationException("Client ID and/or Client Secret are not set in the UnitTestBase class");
                    }

                    System.Console.WriteLine("Initializing connection");

                    YouTubeConnection connection = await YouTubeConnection.ConnectViaLocalhostOAuthBrowser(clientID, clientSecret, scopes);
                    if (connection != null)
                    {
                        Channel channel = await connection.Channels.GetMyChannel();
                        if (channel != null)
                        {
                            System.Console.WriteLine("Connection successful. Logged in as: " + channel.Snippet.Title);

                            System.Console.WriteLine("Performing video upload...");

                            var video                  = new Video();
                            video.Snippet              = new VideoSnippet();
                            video.Snippet.Title        = "Test Video - " + DateTimeOffset.Now.ToString("yyyy-MM-dd-HH-mm");
                            video.Snippet.Description  = "Test Video Description";
                            video.Snippet.Tags         = new string[] { "tag1", "tag2" };
                            video.Snippet.CategoryId   = "22";
                            video.Status               = new VideoStatus();
                            video.Status.PrivacyStatus = "unlisted"; // or "private" or "public"

                            bool uploadFailureOccurred = false;
                            do
                            {
                                using (var fileStream = new FileStream("video.mp4", FileMode.Open))
                                {
                                    var videosInsertRequest = connection.GoogleYouTubeService.Videos.Insert(video, "snippet,status", fileStream, "video/*");

                                    videosInsertRequest.ProgressChanged += (IUploadProgress progress) =>
                                    {
                                        switch (progress.Status)
                                        {
                                        case UploadStatus.Uploading:
                                            System.Console.WriteLine("{0} bytes sent.", progress.BytesSent);
                                            break;

                                        case UploadStatus.Failed:
                                            uploadFailureOccurred = true;
                                            System.Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
                                            break;
                                        }
                                    };

                                    videosInsertRequest.ResponseReceived += (Video uploadedVideo) =>
                                    {
                                        video = uploadedVideo;
                                        System.Console.WriteLine("Video id '{0}' was successfully uploaded.", uploadedVideo.Id);
                                    };

                                    if (uploadFailureOccurred)
                                    {
                                        uploadFailureOccurred = false;
                                        await videosInsertRequest.ResumeAsync();
                                    }
                                    else
                                    {
                                        await videosInsertRequest.UploadAsync();
                                    }
                                }
                            } while (uploadFailureOccurred);

                            using (var fileStream = new FileStream("thumbnail.jpg", FileMode.Open))
                            {
                                ThumbnailsResource.SetMediaUpload thumbnailSetRequest = connection.GoogleYouTubeService.Thumbnails.Set(video.Id, fileStream, "image/jpeg");

                                thumbnailSetRequest.ProgressChanged += (IUploadProgress progress) =>
                                {
                                    switch (progress.Status)
                                    {
                                    case UploadStatus.Uploading:
                                        System.Console.WriteLine("{0} bytes sent.", progress.BytesSent);
                                        break;

                                    case UploadStatus.Failed:
                                        System.Console.WriteLine("An error prevented the upload from completing.\n{0}", progress.Exception);
                                        break;
                                    }
                                };

                                thumbnailSetRequest.ResponseReceived += (ThumbnailSetResponse uploadedThumbnail) =>
                                {
                                    if (uploadedThumbnail.Items.Count > 0)
                                    {
                                        System.Console.WriteLine("Thumbnail was successfully uploaded.");
                                    }
                                };

                                await thumbnailSetRequest.UploadAsync();
                            }

                            System.Console.WriteLine("Uploads completed!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.ToString());
                }
            });

            System.Console.ReadLine();
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Creates an instance of the LiveChatService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public LiveChatService(YouTubeConnection connection) : base(connection)
 {
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates an instance of the SearchService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public SearchService(YouTubeConnection connection) : base(connection)
 {
 }
 /// <summary>
 /// Creates an instance of the LiveBroadcastsService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public LiveBroadcastsService(YouTubeConnection connection) : base(connection)
 {
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Creates an instance of the PlaylistsService.
 /// </summary>
 /// <param name="connection">The YouTube connection to use</param>
 public PlaylistsService(YouTubeConnection connection) : base(connection)
 {
 }