Example #1
0
        /// <summary>
        /// エンティティを変換する
        /// </summary>
        /// <param name="textReader"></param>
        /// <param name="rawEntity"></param>
        /// <returns></returns>
        private static IEntity CreateEntity(SequentialSurrogateTextReader textReader, TwitterApi.EntityBase rawEntity)
        {
            var content    = textReader.Content;
            int startIndex = textReader.RawCursor;
            int length     = textReader.GetRawLength(rawEntity.IndexEnd - rawEntity.IndexStart);

            return(rawEntity switch
            {
                TwitterApi.HashtagEntity hashtag => new HashtagEntity(content.Substring(startIndex, length), hashtag),
                TwitterApi.MediaEntity media => new MediaEntity(media),
                TwitterApi.UrlEntity url => new UrlEntity(url),
                TwitterApi.UserMentionEntity user => new MentionEntity(content.Substring(startIndex, length), user),
                _ => throw new NotImplementedException(),
            });
Example #2
0
        public Attachment(TwitterApi.MediaEntity media)
        {
            this.Id          = media.Id;
            this.Url         = media.Url;
            this.PreviewUrl  = media.MediaUrl;
            this.Description = media.Unwound?.Description;
            this.Type        = TwitterValueConverter.ToAttachmentType(media.Type);

            if (!media.VideoInfo.HasValue)
            {
                this.OriginalUrl = media.MediaUrl;
            }
            else
            {
                var videoList = media.VideoInfo.Value.Variants;
                var videoItem = videoList
                                .Where(video => video.ContentType.Equals("video/mp4"))
                                .FirstOrDefault();

                this.OriginalUrl = videoItem.Url;
            }
        }