public async Task When_getting_videos_then_they_are_saved(
            [Frozen] IYouTubeServiceWrapper youtubeServiceWrapper,
            YouTubeApi youTubeApi
            )
        {
            // Setup
            youtubeServiceWrapper.GetPlaylists().Returns(new List <Playlist>());

            // Act
            await foreach (var _ in youTubeApi.GetVideos(new List <string>()))
            {
            }
        }
        private async Task <IYouTubeServiceWrapper> CreateYouTubeService(bool getNewToken)
        {
            if (_youTubeServiceWrapper != null && !getNewToken)
            {
                return(_youTubeServiceWrapper);
            }

            //var entropy = _entropyService.GetEntropy();
            //var decryptedApiKey = _dpapiService.Decrypt(_appSettings.ApiKey);

            // TODO: if requesting new scopes, delete %appdata%\_youTubeServiceCreatorOptions.FileDataStoreName\.* - this is where the refresh/accesstoken/scopes are stored
            UserCredential credential;

            using (var stream = new FileStream(_youTubeServiceCreatorOptions.ClientSecretPath, FileMode.Open, FileAccess.Read))
            {
                var installedApp = new AuthorizationCodeInstalledApp(
                    new GoogleAuthorizationCodeFlow(
                        new GoogleAuthorizationCodeFlow.Initializer
                {
                    ClientSecrets = GoogleClientSecrets.Load(stream).Secrets,
                    // Console app should only need ReadOnly. the UI needs write access
                    Scopes = new List <string> {
                        YouTubeService.Scope.YoutubeReadonly, YouTubeService.Scope.Youtube
                    },
                    DataStore = new FileDataStore(_youTubeServiceCreatorOptions.FileDataStoreName)
                }),
                    new LocalServerCodeReceiver());
                credential = await installedApp.AuthorizeAsync("user", CancellationToken.None);
            }

            if (getNewToken)
            {
                await credential.RefreshTokenAsync(CancellationToken.None);
            }

            // Create the service.
            _youTubeServiceWrapper = new YouTubeServiceWrapper(new BaseClientService.Initializer()
            {
                ApiKey = _appSettings.ApiKey,
                HttpClientInitializer = credential,
                ApplicationName       = "YouTube cleanup tool",
            });
            return(_youTubeServiceWrapper);
        }
示例#3
0
 public YouTubeController(ILogger <YouTubeController> logger, IYouTubeServiceWrapper youTubeServiceWrapper)
 {
     _logger = logger;
     _youTubeServiceWrapper = youTubeServiceWrapper;
 }