コード例 #1
0
 public void Dispose()
 {
     if (YouTubeService != null)
     {
         YouTubeService.Dispose();
     }
     YouTubeService = null;
 }
コード例 #2
0
 public void Dispose()
 {
     _sr = null;
     _youtubeService.Dispose();
     _youtubeService = null;
     _logger.Log("Youtube song searcher disposed", Category.Info, Priority.Low);
 }
コード例 #3
0
        /// <summary>
        /// 유튜브에서 노래 검색
        /// </summary>
        public async void Search()
        {
            YoutubeSearch.Clear();

            string apiKey  = Environment.GetEnvironmentVariable("YOUTUBE_API_KEY", EnvironmentVariableTarget.User);
            string appName = Environment.GetEnvironmentVariable("YOUTUBE_Application", EnvironmentVariableTarget.User);

            var youtube = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = apiKey,
                ApplicationName = appName
            });

            var request = youtube.Search.List("snippet");

            request.Q          = SearchText;
            request.MaxResults = 100;

            var result = await request.ExecuteAsync();

            foreach (var item in result.Items)
            {
                if (item.Id.Kind == "youtube#video")
                {
                    YoutubeSearch.Add(new YoutubeSearch()
                    {
                        id              = item.Id.VideoId,
                        title           = item.Snippet.Title,
                        downloadCommand = DownloadCommand,
                    });
                }
            }

            youtube.Dispose();
        }
コード例 #4
0
 public void Disconnect()
 {
     IsAuthorized = false;
     _credential  = null;
     _youtubeService.Dispose();
     _youtubeService = null;
 }
コード例 #5
0
        /// <summary>
        /// Retrieves the information about the YouTube video.
        /// </summary>
        /// <param name="videoId"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <bool> GetVideoAsync(string videoId, CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(false);
            }

            YouTubeService youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = Settings.Default.YouTubeApiKey,  // "AIzaSyBvZfGSa9NUidAMyvT73Kja3ShotaI9VO0",
                ApplicationName = Settings.Default.YouTubeClientId // "YouTubeClient"
            });

            _log.Info("successfully init youtubeService in GetVideoAsync");
            try
            {
                string part   = "snippet";
                string fields = "items(id, snippet(title, description))";
                if (_extendedProps)
                {
                    part   = "snippet, statistics, contentDetails";
                    fields = "items(id, snippet(title, channelTitle, channelId, publishedAt, description, thumbnails), statistics(viewCount, likeCount, dislikeCount), contentDetails(duration))";
                }

                var videosListRequest = youtubeService.Videos.List(part);
                _log.Info("Got video list in GetVideoAsync()");
                // Set the request filters
                videosListRequest.Id     = videoId;
                videosListRequest.Fields = fields;

                // Call the videos.list method to retrieve results matching the specified query term.
                var videosListResponse = await videosListRequest.ExecuteAsync(cancellationToken);

                _log.Info("Called the videos.list method to retrieve results matching the specified query term. ");
                // Create the YouTubeSearchResult object from the YouTube Video.
                YouTubeSearchResult result = YouTubeParser.ParseResult(videosListResponse.Items[0], _parser, _query);

                await System.Windows.Application.Current.Dispatcher.BeginInvoke(
                    System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                {
                    if (!cancellationToken.IsCancellationRequested)
                    {
                        _store.Add(result);
                    }
                }));

                return(true);
            }
            catch (Exception ex)
            {
                _log.Error("Exception in GetVideoAsync", ex);

                return(false);
            }
            finally
            {
                youtubeService.Dispose();
            }
        }
コード例 #6
0
ファイル: YoutubeSearch.cs プロジェクト: gmich/Gem
 private void Dispose(bool disposing)
 {
     if (disposing && !isDisposed)
     {
         youtubeService.Dispose();
         isDisposed = true;
     }
 }
コード例 #7
0
        private void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            _youTubeApiService.Dispose();
            _httpClient.Dispose();
        }
コード例 #8
0
ファイル: youtubeManager.cs プロジェクト: lcw3176/Strawberry
        public async void Search(string search)
        {
            var youtube = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = "개발자 키",
                ApplicationName = "개발자 프로그램 이름"
            });

            var request = youtube.Search.List("snippet");

            request.Q          = search;
            request.MaxResults = 50;

            try
            {
                var result = await request.ExecuteAsync();

                foreach (var item in result.Items)
                {
                    if (item.Id.Kind == "youtube#video")
                    {
                        addSearch(item.Id.VideoId.ToString(), item.Snippet.Title);
                    }
                }
            }

            catch
            {
                MessageBox.Show("인터넷 연결을 확인해 주세요.", "알림");
                return;
            }

            finally
            {
                youtube.Dispose();
            }
        }
コード例 #9
0
        /// <summary>
        /// Returns the most popular videos for the content region.
        /// </summary>
        /// <param name="cancellationToken">The Task cancellation token for the operation</param>
        /// <returns>The wrapped results of the get operation.</returns>
        private async Task <bool> LoadMoreItemsInternalAsync(uint count, CancellationToken cancellationToken)
        {
            YouTubeService youtubeService = new YouTubeService(new BaseClientService.Initializer()
            {
                ApiKey          = Settings.Default.YouTubeApiKey,  // "AIzaSyBvZfGSa9NUidAMyvT73Kja3ShotaI9VO0",
                ApplicationName = Settings.Default.YouTubeClientId // "YouTubeClient"
            });

            try
            {
                var searchListRequest = youtubeService.Search.List("snippet");

                // Set the request filters
                searchListRequest.Q      = _query;
                searchListRequest.Type   = "video";
                searchListRequest.Fields = "items/id, pageInfo, nextPageToken";

                while (!this._cancellationToken.IsCancellationRequested && _nextPageToken != null)
                {
                    // Set the request filters for page
                    searchListRequest.PageToken  = _nextPageToken == string.Empty ? null : _nextPageToken;
                    searchListRequest.MaxResults = 25;

                    // Call the search.list method to retrieve results matching the specified query term.
                    SearchListResponse searchListResponse;
                    try
                    {
                        _log.Info("About to call searchListRequest.ExecuteAsync() method");
                        searchListResponse = await searchListRequest.ExecuteAsync(cancellationToken);
                    }
                    catch (Exception ex)
                    {
                        _log.Error("Exception during brute force in method: LoadMoreItemsInternalAsync", ex);
                        // Brute force algorithm
                        continue;
                    }

                    // We store the next page token to efficiently access the next page in the dataset
                    this._nextPageToken = searchListResponse.NextPageToken;

                    // We use parallel processing to process results faster and efficiently.
                    List <Task> tasks = new List <Task>();
                    _log.Info("iterating over searchListResponse and starting new tasks to get videos of each result!");

                    foreach (var result in searchListResponse.Items)
                    {
                        tasks.Add(await Task.Factory.StartNew(() => GetVideoAsync(result.Id.VideoId, cancellationToken)));
                    }
                    _log.Info("Waiting for all tasks to finish");

                    // Wait for all tasks to finish completion
                    await Task.WhenAll(tasks);
                }
            }
            catch (GoogleApiException ex)
            {
                _log.Error("Google API exception caught ,passing on the exception ", ex);
                // Pass
                return(false);
            }
            catch (Exception ex)
            {
                _log.Error("General exception caught,passing on the exception ", ex);
                // Pass
                return(false);
            }
            finally
            {
                youtubeService.Dispose();
                _log.Info("Dispose youtube service");
            }
            _log.Info("Success in LoadMoreItemsInternalAsync(), returing true");

            return(true);
        }
コード例 #10
0
 public void Dispose() => _youtube.Dispose();
コード例 #11
0
 public void Dispose()
 {
     _youtubeService.Dispose();
 }
コード例 #12
0
 public void Dispose()
 {
     _ytService?.Dispose();
 }
コード例 #13
0
 public void Dispose()
 {
     OnMusicManagerDisposed(Guild.Id);
     youtubeService.Dispose();
 }