public YoutubePlaylistItem(PlaylistItem response)
        {
            if (response == null)
            {
                return;
            }

            RawData = response;
            Id      = response.Id;
            Kind    = response.Kind;

            if (response.Snippet == null)
            {
                return;
            }

            ItemKind     = (response.Snippet.ResourceId?.Kind).GetValueOrDefault();
            ItemId       = response.Snippet.ResourceId?.Id();
            PublishedAt  = response.Snippet.PublishedAt.GetValueOrDefault();
            ChannelId    = response.Snippet.ChannelId;
            Title        = response.Snippet.Title;
            Description  = response.Snippet.Description;
            ChannelTitle = response.Snippet.ChannelTitle;
            PlaylistId   = response.Snippet.PlaylistId;
            Position     = response.Snippet.Position;
            Thumbnails   = response.Snippet.Thumbnails?.Clone();

            Thumbnail defaultThumbnail = null;

            Thumbnails?.TryGetValue(ThumbnailSize.Default, out defaultThumbnail);
            DefaultThumbnail = defaultThumbnail;

            switch (ItemKind)
            {
            case ResourceKind.Channel: Url = YoutubeChannel.GetUrl(Id); break;

            case ResourceKind.Playlist: Url = YoutubePlaylist.GetUrl(Id); break;

            case ResourceKind.Video: Url = YoutubeVideo.GetUrl(Id); break;

            default: throw new InvalidOperationException();
            }
        }
Esempio n. 2
0
        public YoutubeSearchResult(SearchResult response)
        {
            if (response == null)
            {
                return;
            }

            RawData    = response;
            Kind       = response.Kind;
            ResultKind = response.Id.Kind;
            Id         = response.Id.Id();

            switch (ResultKind)
            {
            case ResourceKind.Channel: Url = YoutubeChannel.GetUrl(Id); break;

            case ResourceKind.Playlist: Url = YoutubePlaylist.GetUrl(Id); break;

            case ResourceKind.Video: Url = YoutubeVideo.GetUrl(Id); break;

            default: throw new InvalidOperationException();
            }

            if (response.Snippet == null)
            {
                return;
            }

            PublishedAt  = response.Snippet.PublishedAt.GetValueOrDefault();
            ChannelId    = response.Snippet.ChannelId;
            Title        = response.Snippet.Title;
            Description  = response.Snippet.Description;
            ChannelTitle = response.Snippet.ChannelTitle;
            Thumbnails   = response.Snippet.Thumbnails?.Clone();

            Thumbnail defaultThumbnail = null;

            Thumbnails?.TryGetValue(ThumbnailSize.Default, out defaultThumbnail);
            DefaultThumbnail = defaultThumbnail;
        }