Exemple #1
0
        public async Task RunAsync()
        {
            var searchClient = new YouTubeSearchClient(youtubeApiKey);
            var result       = await searchClient.SearchAsync(SearchWord);

            var tableClient = new YouTubeTableClient(storageAccount, tableName);

            var savedLatestItem   = tableClient.GetLatestItem();
            var latestPublishedAt = savedLatestItem?.PublishedAt ?? DateTime.UtcNow.AddHours(-6);

            var newItems = result
                           .Where(x => x.Snippet.PublishedAt.Value.ToUniversalTime() > latestPublishedAt)
                           .ToList();

            foreach (var item in newItems)
            {
                var tableEntity = item.ToEntity();
                try
                {
                    await tableClient.InsertAsync(tableEntity);
                    await Notify2DiscordAsync(tableEntity);
                }
                catch (Exception e)
                {
                    // TODO: log
                    Debug.WriteLine($"{e.Message} {e.StackTrace}");
                }
            }
        }
        public async Task SearchAsyncTest()
        {
            var apiKey       = ConfigurationManager.AppSettings["YouTubeApiKey"];
            var searchClient = new YouTubeSearchClient(apiKey);
            var result       = await searchClient.SearchAsync("アビゲイル");

            result.Count().IsNot(0);
        }