Exemple #1
0
        /// <summary>
        /// Get information about a channel.
        /// </summary>
        /// <param name="channelID">ID of the channel to get information for</param>
        /// <returns>Information about a channel.</returns>
        public Database.Types.Channel Info(string channelID)
        {
            try {
                // https://developers.google.com/youtube/v3/docs/channels/list
                API.ChannelsResource.ListRequest channelInfo = APIService.Channels.List("id,snippet");
                channelInfo.Id          = channelID;
                channelInfo.MaxResults  = 1;
                channelInfo.PrettyPrint = false;

                API.Data.Channel response = channelInfo.Execute().Items[0];

                Database.Types.Channel channel = new Database.Types.Channel {
                    ID           = response.Id,
                    Title        = response.Snippet.Title,
                    Description  = response.Snippet.Description,
                    ThumbnailURL = GetBestThumbnail(response.Snippet.Thumbnails)
                };

                LoggingManager.Log.Info($"Information processed for '{channel.ID}'.");
                return(channel);
            } catch (Exception ex) {
                LoggingManager.Log.Error(ex, $"Failed to get information for '{channelID}'.");
                return(null);
            }
        }
        public async Task LoadChannel(string channelid, bool isself)
        {
            if (IsLoadingChannel)
            {
                return;
            }
            IsLoadingChannel = true;

            try
            {
                var videoInfoRequest = YoutubeService.service.Channels.List("topicDetails,status,statistics,snippet,id,contentOwnerDetails,contentDetails,brandingSettings");
                videoInfoRequest.Id = channelid;
                // videoInfoRequest.Mine = isself;

                try
                {
                    var videoResultResponse = await videoInfoRequest.ExecuteAsync();

                    if (videoResultResponse.Items.Count >= 0)
                    {
                        Google.Apis.YouTube.v3.Data.Channel videoNew = videoResultResponse.Items[0];

                        channel = videoNew;
                    }
                }
                catch (Exception exp)
                {
                    Debug.WriteLine(exp.ToString());
                }
            }
            finally
            {
                IsLoadingChannel = false;
            }
        }
Exemple #3
0
 public YouTubeChannel(Google.Apis.YouTube.v3.Data.Channel youTubeChannel)
 {
     if (youTubeChannel != null)
     {
         ChannelName = youTubeChannel.Snippet.Title;
         ChannelId   = youTubeChannel.Id;
         Videos      = new List <YouTubeVideo>();
     }
 }
Exemple #4
0
        public async Task <Subscription> CreateSubscription(Uri uri)
        {
            var parseResult = YouTubeUrlHelper.ParseUrl(uri);
            var api         = new YouTubeAPIProxy(configuration.ApiKey);

            Subscription sub = new Subscription
            {
                SubscriptionId         = uri.AbsoluteUri,
                SubscriptionProviderId = Id,
                OriginalUrl            = uri.ToString()
            };

            YtChannel channel = null;

            switch (parseResult.Type)
            {
            case YouTubeUrlType.Channel:
                channel = await api.FetchChannel(parseResult.ChannelId);

                break;

            case YouTubeUrlType.ChannelCustom:
                var channelSearch = await api.FetchChannelByCustomId(parseResult.ChannelCustomId);

                channel = await api.FetchChannel(channelSearch.Id.ChannelId);

                break;

            case YouTubeUrlType.User:
                channel = await api.FetchChannelByUserId(parseResult.UserId);

                break;

            case YouTubeUrlType.Playlist:
            {
                var playlist = await api.FetchPlaylist(parseResult.ListId);

                sub.Name          = playlist.Snippet.Title;
                sub.Description   = playlist.Snippet.Description;
                sub.ThumbnailPath = playlist.Snippet.Thumbnails.Maxres.Url;
                sub.ProviderData  = playlist.Id;
            }
            break;

            case YouTubeUrlType.Search:
            {
                sub.Name        = uri.Query;
                sub.Description = "Automatic subscription generated from a search query!";
            }
            break;

            default:
                throw new Exception("Unsupported resource type!");
            }

            if (channel != null)
            {
                sub.Name          = channel.Snippet.Title;
                sub.Description   = channel.Snippet.Description;
                sub.ThumbnailPath = channel.Snippet.Thumbnails.Maxres?.Url
                                    ?? channel.Snippet.Thumbnails.High?.Url
                                    ?? channel.Snippet.Thumbnails.Standard?.Url
                                    ?? channel.Snippet.Thumbnails.Medium?.Url
                                    ?? channel.Snippet.Thumbnails.Default__?.Url;
                sub.ProviderData = channel.ContentDetails.RelatedPlaylists.Uploads;
            }

            return(sub);
        }