Beispiel #1
0
        private async Task Run()
        {
            UserCredential credential;
            string         clientSecretsPath = CredentialsManager.GetClientSecretsLocation();

            using (FileStream stream = new FileStream(clientSecretsPath, FileMode.Open, FileAccess.Read))
            {
                // This OAuth 2.0 access scope allows for read-only access to the authenticated
                // user's account, but not other types of account access.
                credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    new[] { YouTubeService.Scope.YoutubeReadonly },
                    "user",
                    CancellationToken.None,
                    new FileDataStore(GetType().ToString())
                    );
            }

            BaseClientService.Initializer baseClientServiceInitializer = new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName       = GetType().ToString()
            };
            YouTubeService youtubeService = new YouTubeService(baseClientServiceInitializer);

            ChannelsResource.ListRequest channelsListRequest = youtubeService.Channels.List("contentDetails");
            channelsListRequest.Mine = true;

            // Retrieve the contentDetails part of the channel resource for the authenticated user's channel.
            ChannelListResponse channelsListResponse = await channelsListRequest.ExecuteAsync();

            foreach (Channel channel in channelsListResponse.Items)
            {
                // From the API response, extract the playlist ID that identifies the list
                // of videos uploaded to the authenticated user's channel.
                string uploadsListId = channel.ContentDetails.RelatedPlaylists.Uploads;

                Console.WriteLine("Videos in list {0}", uploadsListId);

                string nextPageToken = "";
                while (nextPageToken != null)
                {
                    PlaylistItemsResource.ListRequest playlistItemsListRequest = youtubeService.PlaylistItems.List("snippet");
                    playlistItemsListRequest.PlaylistId = uploadsListId;
                    playlistItemsListRequest.MaxResults = 50;
                    playlistItemsListRequest.PageToken  = nextPageToken;

                    // Retrieve the list of videos uploaded to the authenticated user's channel.
                    PlaylistItemListResponse playlistItemsListResponse = await playlistItemsListRequest.ExecuteAsync();

                    foreach (PlaylistItem playlistItem in playlistItemsListResponse.Items)
                    {
                        // Print information about each video.
                        Console.WriteLine("{0} ({1})", playlistItem.Snippet.Title, playlistItem.Snippet.ResourceId.VideoId);
                    }

                    nextPageToken = playlistItemsListResponse.NextPageToken;
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Return a complete Channel object from the youtube id of the channel
        /// </summary>
        /// <param name="channelID"></param>
        /// <returns></returns>
        public async static Task <Channel> GetChannel(string channelID)
        {
            try
            {
                ChannelsResource.ListRequest request = YoutubeManager.YoutubeService.Channels.List("snippet");
                request.Id = channelID;

                ChannelListResponse response = await request.ExecuteAsync();

                if (response.Items.Count > 0)
                {
                    var result = response.Items[0];
                    return(new Channel(result.Snippet.Title, channelID, result.Snippet.Thumbnails.High.Url));
                }
                else
                {
                    return(null);
                }
            }
            catch
            {
                MainActivity.instance.UnknowError(ErrorCode.CG1);
                return(null);
            }
        }
Beispiel #3
0
        public async Task ChannelInfoCommand([Remainder] string searchTerm)
        {
            Channel?channelListResult;

            using (var youtubeService = new YouTubeService(new BaseClientService.Initializer
            {
                ApiKey = _botCredentials.GoogleApiKey,
                ApplicationName = GetType().ToString()
            }))

            {
                SearchResource.ListRequest searchListRequest = youtubeService.Search.List("snippet");
                searchListRequest.Q          = searchTerm;
                searchListRequest.MaxResults = 1;
                SearchResult?searchListResult = (await searchListRequest.ExecuteAsync()).Items.FirstOrDefault();

                if (searchListResult == null)
                {
                    await SendErrorAsync("Could not find the requested channel!");

                    return;
                }

                ChannelsResource.ListRequest channelListRequest = youtubeService.Channels.List("snippet");
                channelListRequest.Id         = searchListResult.Snippet.ChannelId;
                channelListRequest.MaxResults = 10;
                channelListResult             = (await channelListRequest.ExecuteAsync()).Items.FirstOrDefault();

                if (channelListResult == null)
                {
                    await SendErrorAsync("Could not find the requested channel!");

                    return;
                }
            }

            var builder = new EmbedBuilder()
                          .WithTitle(channelListResult.Snippet.Title)
                          .WithColor(GetColor(Context))
                          .WithFooter(channelListResult.Id)
                          .WithThumbnailUrl(channelListResult.Snippet.Thumbnails.Medium.Url);

            if (!string.IsNullOrEmpty(channelListResult.Snippet.Description))
            {
                builder.AddField("Description", channelListResult.Snippet.Description);
            }

            if (channelListResult.Snippet.Country != null)
            {
                builder.AddField("Country", channelListResult.Snippet.Country, true);
            }

            if (channelListResult.Snippet.PublishedAt != null)
            {
                // date is in format YYYY-MM-DDThh:mm:ssZ - remove the T and Z
                builder.AddField("Created", channelListResult.Snippet.PublishedAt.Replace('T', ' ').Remove(19), true);
            }

            await ReplyAsync(embed : builder.Build());
        }
        public async Task <ChannelListResponse> GetChannelInfo(ChannelQuery query)
        {
            ChannelsResource.ListRequest listRequest = _youtubeService.Channels.List(query.Part);
            listRequest.Id         = query.Id;
            listRequest.MaxResults = query.MaxResults;

            return(await listRequest.ExecuteAsync());
        }
Beispiel #5
0
        /// <summary>
        /// Gets the channels associated with the specified IDs.
        /// </summary>
        /// <param name="ids">The IDs to search for</param>
        /// <returns>The channel information</returns>
        public async Task <IEnumerable <Channel> > GetChannelsByID(IEnumerable <string> ids)
        {
            Validator.ValidateList(ids, "ids");
            return(await this.YouTubeServiceWrapper(async() =>
            {
                ChannelsResource.ListRequest search = this.connection.GoogleYouTubeService.Channels.List("snippet,statistics,contentDetails");
                search.Id = string.Join(",", ids);
                search.MaxResults = ids.Count();

                ChannelListResponse response = await search.ExecuteAsync();
                return response.Items;
            }));
        }
Beispiel #6
0
        // Youtube 에서 제공하는 API, 영상 제목, 영상 정보, 영상 길이, 영상 조회수, 영상 설명, 영상 좋아요,싫어요 수, 댓글 수 게시자 채널명, 해당 채널 구독자 수,
        async void YoutubeAPi()
        {
            //비동기, 동기
            //비동기 : 해결 속도 동기 보다 느림, 대신 이 명령어 하고 있을 때 다른 일을 동시에 해결 할 수 있음
            //동기 : 비동기보다 빠르고 대신 이 명령어를 하는 동안 다른 명령어를 수행못함

            // viewCount,likecount, dislikecount, commentcount
            VideosResource.ListRequest count_like_dislike_view = youtube.Videos.List("statistics");//Videos statistics 연결
            count_like_dislike_view.Id = $"{this.Id}";
            VideoListResponse countview_res = await count_like_dislike_view.ExecuteAsync();

            viewCount.Text    = Convert.ToString(countview_res.Items[0].Statistics.ViewCount);//
            likeCount.Text    = Convert.ToString(countview_res.Items[0].Statistics.LikeCount);
            dislikeCount.Text = Convert.ToString(countview_res.Items[0].Statistics.DislikeCount);
            commentCount.Text = Convert.ToString(countview_res.Items[0].Statistics.CommentCount);


            // title, description, channelId, chnnelTitle, publichedAt
            VideosResource.ListRequest snippet = youtube.Videos.List("snippet");//Videos statistics 연결
            snippet.Id = $"{this.Id}";
            VideoListResponse snippet_res = await snippet.ExecuteAsync();

            this.stitle         = Convert.ToString(snippet_res.Items[0].Snippet.Title);
            title.Text          = this.stitle;
            descriptionBox.Text = "\n\n" + Convert.ToString(snippet_res.Items[0].Snippet.Description.Replace("\n", "\r\n"));
            ChannelsResource.ListRequest yChannnelId = youtube.Channels.List("statistics");
            string channelId = snippet_res.Items[0].Snippet.ChannelId;

            yChannnelId.Id = channelId;
            ChannelListResponse yChnnelId_res = await yChannnelId.ExecuteAsync();

            // 구독자 수
            godog.Text = " 채널 구독자 수: " + Convert.ToString(yChnnelId_res.Items[0].Statistics.SubscriberCount) + " 명";

            channelTitle.Text = Convert.ToString(snippet_res.Items[0].Snippet.ChannelTitle);

            this.channelUrl = "https://www.youtube.com/channel/" + channelId;
            // title, description, channelId, chnnelTitle, publichedAt
            VideosResource.ListRequest contentDetials = youtube.Videos.List("contentDetails");//Videos statistics 연결
            contentDetials.Id = $"{this.Id}";
            VideoListResponse contentDetails_res = await contentDetials.ExecuteAsync();

            int    timeSeconds = TimeSeconds(contentDetails_res.Items[0].ContentDetails.Duration);
            string timeString  = TimeString(contentDetails_res.Items[0].ContentDetails.Duration);

            videoLength.Text = timeString;


            //status.embeddable	해야할것
            trackBar1.Maximum = timeSeconds;
        }
        public async Task <ActionResult <ChannelListResponse> > List([Required, FromQuery] AppChannelListRequest request)
        {
            YouTubeService service = await serviceAccessor.InitializeServiceAsync();

            ChannelsResource.ListRequest requestActual = request.ToActualRequest(service);

            try {
                ChannelListResponse response = await requestActual.ExecuteAsync();

                return(new ActionResult <ChannelListResponse>(response));
            } catch (GoogleApiException ex) {
                return(StatusCode((int)ex.HttpStatusCode, ex.ToString()));
            }
        }
Beispiel #8
0
        /// <summary>
        /// Gets the channel associated with the account.
        /// </summary>
        /// <returns>The channel information</returns>
        public async Task <Channel> GetMyChannel()
        {
            return(await this.YouTubeServiceWrapper(async() =>
            {
                ChannelsResource.ListRequest search = this.connection.GoogleYouTubeService.Channels.List("snippet,statistics,contentDetails");
                search.Mine = true;
                search.MaxResults = 1;

                ChannelListResponse response = await search.ExecuteAsync();
                if (response.Items.Count > 0)
                {
                    return response.Items.First();
                }
                return null;
            }));
        }
Beispiel #9
0
        /// <summary>
        /// Gets the channel associated with the specified username.
        /// </summary>
        /// <param name="username">The username to search for</param>
        /// <returns>The channel information</returns>
        public async Task <Channel> GetChannelByUsername(string username)
        {
            Validator.ValidateString(username, "username");
            return(await this.YouTubeServiceWrapper(async() =>
            {
                ChannelsResource.ListRequest search = this.connection.GoogleYouTubeService.Channels.List("snippet,statistics");
                search.ForUsername = username;
                search.MaxResults = 1;

                ChannelListResponse response = await search.ExecuteAsync();
                if (response.Items.Count > 0)
                {
                    return response.Items.First();
                }
                return null;
            }));
        }
Beispiel #10
0
        /// <summary>
        /// Return a list of complete Channel objects from the youtube ids of the channels
        /// </summary>
        /// <param name="channelID"></param>
        /// <returns></returns>
        public async static Task <IEnumerable <Channel> > GetChannels(IEnumerable <string> channelIDs)
        {
            ChannelsResource.ListRequest request = YoutubeManager.YoutubeService.Channels.List("snippet");
            request.Id = string.Join(";", channelIDs);

            ChannelListResponse response = await request.ExecuteAsync();

            if (response.Items.Count > 0)
            {
                List <Channel> channels = new List <Channel>();
                foreach (var result in response.Items)
                {
                    channels.Add(new Channel(result.Snippet.Title, result.Id, result.Snippet.Thumbnails.High.Url));
                }

                return(channels);
            }
            else
            {
                return(null);
            }
        }
Beispiel #11
0
        public async Task loadChannelStatistics()
        {
            String channelIds = "";

            lock (channelLock)
            {
                if (Children.Count == 0)
                {
                    return;
                }

                channelIds = (Children[0] as YoutubeChannelNode).ChannelId;

                for (int i = 1; i < Children.Count; i++)
                {
                    channelIds += "," + (Children[i] as YoutubeChannelNode).ChannelId;
                }
            }

            Google.Apis.YouTube.v3.ChannelsResource.ListRequest listRequest = new ChannelsResource.ListRequest(YoutubeViewModel.Youtube, "statistics");

            listRequest.Id = channelIds;

            ChannelListResponse response = await listRequest.ExecuteAsync();

            lock (channelLock)
            {
                foreach (Channel item in response.Items)
                {
                    YoutubeChannelNode node = getChannelWithId(item.Id);

                    if (node != null)
                    {
                        node.updateStatistics(item.Statistics);
                    }
                }
            }
        }
        public async Task loadChannelStatistics()
        {
            String channelIds = "";

            lock (channelLock)
            {
                if (Children.Count == 0) return;

                channelIds = (Children[0] as YoutubeChannelNode).ChannelId;

                for (int i = 1; i < Children.Count; i++)
                {
                    channelIds += "," + (Children[i] as YoutubeChannelNode).ChannelId;
                }
            }
          
            Google.Apis.YouTube.v3.ChannelsResource.ListRequest listRequest = new ChannelsResource.ListRequest(YoutubeViewModel.Youtube, "statistics");

            listRequest.Id = channelIds;
          
            ChannelListResponse response = await listRequest.ExecuteAsync();

            lock (channelLock)
            {
                foreach (Channel item in response.Items)
                {
                    YoutubeChannelNode node = getChannelWithId(item.Id);

                    if (node != null)
                    {
                        node.updateStatistics(item.Statistics);
                    }
                }
            }

        }