示例#1
0
        /// <summary>
        /// Convert this YouTube specific track to a universal track.
        /// </summary>
        /// <returns></returns>
        public BaseTrack ToBaseTrack()
        {
            var track = new BaseTrack
            {
                ServiceType = ServiceType.YouTube,
                Id          = Id.VideoId,
                Link        = $"https://www.youtube.com/watch?v={Id.VideoId}",
                ArtworkUrl  = Snippet.Thumbnails.DefaultSize.Url,
                Title       = Snippet.Title,
                Description = Snippet.Description,
                Created     = DateTime.Parse(Snippet.PublishedAt),
                Genre       = "YouTube"
            };

            // Get the correct kind value for the
            // universal object
            switch (Id.Kind)
            {
            case "youtube#video":
                track.Kind = "track";
                break;

            default:
                track.Kind = Kind;
                break;
            }

            return(track);
        }
示例#2
0
        /// <summary>
        /// Convert this YouTube specific track to a universal track.
        /// </summary>
        /// <returns></returns>
        public BaseTrack ToBaseTrack()
        {
            try
            {
                var track = new BaseTrack
                {
                    ServiceType  = ServiceTypes.YouTube,
                    TrackId      = string.IsNullOrEmpty(ContentDetails.VideoId) ? Id.VideoId : ContentDetails.VideoId,
                    ArtworkUrl   = Snippet.Thumbnails?.HighSize?.Url,
                    ThumbnailUrl = Snippet.Thumbnails?.MediumSize?.Url,
                    Title        = Snippet.Title,
                    Description  = Snippet.Description,
                    Created      = DateTime.Parse(Snippet.PublishedAt),
                    Duration     = GetDuration(),
                    Genre        = "YouTube",
                    IsLive       = IsLive(),
                    User         = new BaseUser
                    {
                        UserId       = Snippet.ChannelId,
                        ServiceType  = ServiceTypes.YouTube,
                        Username     = Snippet.ChannelTitle,
                        ArtworkUrl   = "http://a1.sndcdn.com/images/default_avatar_large.png",
                        ThumbnailUrl = "http://a1.sndcdn.com/images/default_avatar_large.png"
                    }
                };

                track.Link = $"https://www.youtube.com/watch?v={track.TrackId}";

                track.CustomProperties.Add("YouTubePlaylistItemId", Snippet?.PlaylistId);

                return(track);
            }
            catch (Exception e)
            {
                throw new Exception("Error Decoding YouTube track: " + e.Message, e);
            }
        }
示例#3
0
        /// <summary>
        /// Convert this YouTube specific track to a universal track.
        /// </summary>
        /// <returns></returns>
        public BaseTrack ToBaseTrack()
        {
            var track = new BaseTrack
            {
                ServiceType = ServiceType.YouTube,
                Id          = Id.VideoId,
                Link        = $"https://www.youtube.com/watch?v={Id.VideoId}",
                ArtworkUrl  = Snippet.Thumbnails.HighSize.Url,
                Title       = Snippet.Title,
                Description = Snippet.Description,
                Created     = DateTime.Parse(Snippet.PublishedAt),
                Duration    = (ContentDetails != null) ? XmlConvert.ToTimeSpan(ContentDetails.Duration) : TimeSpan.FromMilliseconds(0),
                Genre       = "YouTube",
                IsLive      = Snippet.LiveBroadcastContent != "none",
                User        = new BaseUser
                {
                    Id       = Snippet.ChannelId,
                    Username = Snippet.ChannelTitle
                }
            };

            // Get the correct kind value for the
            // universal object
            switch (Id.Kind)
            {
            case "youtube#video":
                track.Kind = "track";
                break;

            default:
                track.Kind = Kind;
                break;
            }

            return(track);
        }