public static EntitiesInfoWindow ShowVideoInfo(Entities entities) { var w = new EntitiesInfoWindow(); w.DataSet(entities); w.Show(); return w; }
public EntitiesModel(CoreTweet.Entities entities) { if (entities != null) { if (entities.HashTags != null && entities.HashTags.Length != 0) { HashTags = new List <ISymbolEntity>(); foreach (var hashTag in entities.HashTags) { HashTags.Add(new HashTagEntityModel(hashTag)); } } if (entities.Media != null && entities.Media.Length != 0) { Media = new List <IMediaEntity>(); foreach (var m in entities.Media) { Media.Add(new MediaEntityModel(m)); } } if (entities.Symbols != null && entities.Symbols.Length != 0) { Symbols = new List <ISymbolEntity>(); foreach (var symbol in entities.Symbols) { Symbols.Add(new SymbolEntityModel(symbol)); } } if (entities.Urls != null && entities.Urls.Length != 0) { Urls = new List <IUrlEntity>(); foreach (var url in entities.Urls) { Urls.Add(new UrlEntityModel(url)); } } if (entities.UserMentions != null && entities.UserMentions.Length != 0) { UserMentions = new List <IUserMentionEntity>(); foreach (var userMention in entities.UserMentions) { UserMentions.Add(new UserMentionEntityModel(userMention)); } } } }
private static IEnumerable<TextPart> EnumerateTextParts(IList<DoubleUtf16Char> chars, Entities entities, int startIndex, int endIndex) { if (entities == null) { var text = ToString(chars, startIndex, endIndex - startIndex); yield return new TextPart() { RawText = text, Text = HtmlDecode(text) }; yield break; } var media = entities.Media ?? Enumerable.Empty<UrlEntity>(); if (entities.Urls != null) { // Remove duplicate entities in DM media = media.Where(e => !entities.Urls.Any(x => x.Indices[0] == e.Indices[0])); } var list = new LinkedList<TextPart>( (entities.HashTags ?? Enumerable.Empty<SymbolEntity>()) .Select(e => new TextPart() { Type = TextPartType.Hashtag, Start = e.Indices[0], End = e.Indices[1], RawText = "#" + e.Text, Text = "#" + e.Text, Entity = e }) .Concat( (entities.Symbols ?? Enumerable.Empty<SymbolEntity>()) .Select(e => new TextPart() { Type = TextPartType.Cashtag, Start = e.Indices[0], End = e.Indices[1], RawText = "$" + e.Text, Text = "$" + e.Text, Entity = e }) ) .Concat( (entities.Urls ?? Enumerable.Empty<UrlEntity>()) .Concat(media) .Select(e => new TextPart() { Type = TextPartType.Url, Start = e.Indices[0], End = e.Indices[1], RawText = e.Url, Text = e.DisplayUrl, Entity = e }) ) .Concat( (entities.UserMentions ?? Enumerable.Empty<UserMentionEntity>()) .Select(e => new TextPart() { Type = TextPartType.UserMention, Start = e.Indices[0], End = e.Indices[1], RawText = "@" + e.ScreenName, Text = "@" + e.ScreenName, Entity = e }) ) .Where(e => e.Start >= startIndex && e.Start < endIndex) .OrderBy(part => part.Start) ); if (list.Count == 0) { var text = ToString(chars, startIndex, endIndex - startIndex); yield return new TextPart() { RawText = text, Text = HtmlDecode(text) }; yield break; } var current = list.First; while (true) { var start = current.Previous?.Value.End ?? startIndex; var count = current.Value.Start - start; if (count > 0) { var output = ToString(chars, start, count); yield return new TextPart() { RawText = output, Text = HtmlDecode(output) }; } yield return current.Value; if (current.Next == null) break; current = current.Next; } var lastStart = current.Value.End; if (lastStart < endIndex) { var lastOutput = ToString(chars, lastStart, endIndex - lastStart); yield return new TextPart() { RawText = lastOutput, Text = HtmlDecode(lastOutput) }; } }
/// <summary> /// Enumerates parts split into Tweet Entities. /// </summary> /// <param name="text">The text such as <see cref="Status.Text"/>, <see cref="DirectMessage.Text"/> and <see cref="User.Description"/>.</param> /// <param name="entities">The <see cref="Entities"/> instance.</param> /// <param name="startIndex">The starting character position in code point.</param> /// <param name="endIndex">The ending character position in code point.</param> /// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns> public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities, int startIndex, int endIndex) { var chars = GetCodePoints(text); if (startIndex < 0 || startIndex >= chars.Count) throw new ArgumentOutOfRangeException(nameof(startIndex)); if (endIndex < startIndex || endIndex > chars.Count) throw new ArgumentOutOfRangeException(nameof(endIndex)); return EnumerateTextParts(chars, entities, startIndex, endIndex); }
/// <summary> /// Enumerates parts split into Tweet Entities. /// </summary> /// <param name="text">The text such as <see cref="Status.Text"/>, <see cref="DirectMessage.Text"/> and <see cref="User.Description"/>.</param> /// <param name="entities">The <see cref="Entities"/> instance.</param> /// <returns>An <see cref="IEnumerable{TextPart}"/> whose elements are parts of <paramref name="text"/>.</returns> public static IEnumerable<TextPart> EnumerateTextParts(string text, Entities entities) { var chars = GetCodePoints(text); return EnumerateTextParts(chars, entities, 0, chars.Count); }
private void DataSet(Entities entities) { var variants = entities.Media[0].VideoInfo.Variants; Title = Format(Properties.Resources.AboutThis, entities.Media[0].DisplayUrl); dataGrid.ItemsSource = variants; }
public static IEnumerable <Media> Parse(CoreTweet.Entities cEntities, CoreTweet.Entities cExtendedEntities = null) { if (cEntities?.Urls != null) { foreach (var url in cEntities.Urls) { if (url.ExpandedUrl == null) { continue; } // 画像サービス #region DirectLink var match = RegexDirectLink.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = match.Value, MediaUrl = match.Value, ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region yfrog match = RegexYfrog.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = match.Value + ":small", MediaUrl = match.Value + ":medium", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region imgur match = RegexImgur.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://img.imgur.com/" + match.Groups[1] + "l.jpg", MediaUrl = "http://img.imgur.com/" + match.Groups[1] + ".jpg", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region ついっぷるフォト match = RegexTwipplePhoto.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://p.twipple.jp/show/thumb/" + match.Groups["ContentId"], MediaUrl = "http://p.twpl.jp/show/orig/" + match.Groups["ContentId"], ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region img.ly match = RegexImgly.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://img.ly/show/thumb/" + match.Groups[1], MediaUrl = "http://img.ly/show/full/" + match.Groups[1], ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region ニコニコ静画 match = RegexNicoImage.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://lohas.nicoseiga.jp/thumb/" + match.Groups["Id"] + "q?", MediaUrl = "http://lohas.nicoseiga.jp/thumb/" + match.Groups["Id"] + "l?", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region Pixiv match = RegexPixiv.Match(url.ExpandedUrl); if (match.Success) { /*var fileName = "Pixiv_" + match.Groups["Id"]; * try * { * Thumbnail.Pixiv.GetThumbnail(match.Groups["Id"].Value, fileName); * } * catch * { * }*/ yield return(new Media { MediaThumbnailUrl = "http://embed.pixiv.net/decorate.php?illust_id=" + match.Groups["Id"], MediaUrl = "http://embed.pixiv.net/decorate.php?illust_id=" + match.Groups["Id"], ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region Instagram match = RegexInstagram.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://instagr.am/p/" + match.Groups[1] + "/media/?size=t", MediaUrl = "http://instagr.am/p/" + match.Groups[1] + "/media/?size=l", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region Gyazo match = RegexGyazo.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://gyazo.com/" + match.Groups[1] + ".png", MediaUrl = "http://gyazo.com/" + match.Groups[1] + ".png", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region Pckles match = RegexPckles.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = match.Value + ".resize.jpg", MediaUrl = match.Value + ".jpg", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region フォト蔵 match = RegexPhotoZou.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://photozou.jp/p/thumb/" + match.Groups["Id"], MediaUrl = "http://photozou.jp/p/img/" + match.Groups["Id"], ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region flickr (外部サービス使用) match = RegexFlickr.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://img.azyobuzi.net/api/redirect?size=thumb&uri=" + match.Value, MediaUrl = "http://img.azyobuzi.net/api/redirect?size=full&uri=" + match.Value, ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region MobyPicture match = RegexMobyPicture.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://moby.to/" + match.Groups[1] + ":thumb", MediaUrl = "http://moby.to/" + match.Groups[1] + ":full", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region はてなフォトライフ match = RegexHatenaPhotoLife.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://img.f.hatena.ne.jp/images/fotolife/" + match.Groups[2] + "/" + match.Groups[1] + "/" + match.Groups[4] + "/" + match.Groups[3] + "_120.jpg", MediaUrl = "http://img.f.hatena.ne.jp/images/fotolife/" + match.Groups[2] + "/" + match.Groups[1] + "/" + match.Groups[4] + "/" + match.Groups[3] + "_original.jpg", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region 携帯百景 match = RegexKeitaiHyakkei.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://image.movapic.com/pic/s_" + match.Groups[1] + ".jpeg", MediaUrl = "http://image.movapic.com/pic/m_" + match.Groups[1] + ".jpeg", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region Twitgoo match = RegexTwitgoo.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://twitgoo.com/" + match.Groups[1] + "/mini", MediaUrl = "http://twitgoo.com/" + match.Groups[1] + "/img", ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion #region Twitpic match = RegexTwitpic.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://twitpic.com/show/thumb/" + match.Groups["Id"], MediaUrl = "http://twitpic.com/show/full/" + match.Groups["Id"], ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Image" }); continue; } #endregion // 動画サービス #region ニコニコ動画 match = RegexNicoVideo.Match(url.ExpandedUrl); if (match.Success) { if (match.Groups["VideoId"].Value.StartsWith("sm") || match.Groups["VideoId"].Value.StartsWith("nm")) { yield return(new Media { MediaThumbnailUrl = "http://tn-skr2.smilevideo.jp/smile?i=" + match.Groups["VideoId"].Value.Replace("sm", "").Replace("nm", ""), MediaUrl = string.Empty, ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Video", VideoInfo = new VideoInfo { VideoId = match.Groups["VideoId"].Value, VideoType = "NicoVideo" } }); continue; } else { /*var fileName = "NicoVideo_" + match.Groups["VideoId"].Value; * try * { * Thumbnail.NicoVideo.GetThumbnail(match.Groups["VideoId"].Value, fileName); * } * catch * { * }*/ yield return(new Media { // MediaThumbnailUrl = "ms-appdata:///temp/" + fileName, MediaThumbnailUrl = "http://localhost/", MediaUrl = string.Empty, ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Video", VideoInfo = new VideoInfo { VideoId = match.Groups["VideoId"].Value, VideoType = "NicoVideo" } }); continue; } } #endregion #region Youtube match = RegexYoutube.Match(url.ExpandedUrl); if (match.Success) { yield return(new Media { MediaThumbnailUrl = "http://img.youtube.com/vi/" + match.Groups["VideoId"] + "/default.jpg", MediaUrl = string.Empty, ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Video", VideoInfo = new VideoInfo { VideoId = match.Groups["VideoId"].Value, VideoType = "Youtube" } }); continue; } #endregion #region Vine match = RegexVine.Match(url.ExpandedUrl); if (match.Success) { yield return new Media { MediaThumbnailUrl = "http://img.azyobuzi.net/api/redirect?size=thumb&uri=" + match.Value, MediaUrl = string.Empty, ExpandedUrl = match.Value, DisplayUrl = url.DisplayUrl, Type = "Video", VideoInfo = new VideoInfo { VideoId = match.Groups["VideoId"].Value, VideoType = "Vine" } } } ; #endregion } } #region Twitter公式 if (cEntities?.Media != null && cExtendedEntities == null) { foreach (var media in cEntities.Media) { yield return new Media { MediaThumbnailUrl = media.MediaUrl + ":thumb", MediaUrl = media.MediaUrl + ":orig", ExpandedUrl = media.Url, DisplayUrl = media.DisplayUrl, Type = "Image" } } } ; if (cExtendedEntities?.Media != null) { foreach (var media in cExtendedEntities.Media) { if (media.Type == "animated_gif" || media.Type == "video") { var variants = media.VideoInfo.Variants.Where(x => x.ContentType == "video/mp4"); var variant = !variants.Any() ? media.VideoInfo.Variants.First() : variants.FindMax(x => x.Bitrate ?? 0); yield return(new Media { MediaThumbnailUrl = media.MediaUrl + ":thumb", MediaUrl = media.MediaUrl + ":orig", ExpandedUrl = media.Url, DisplayUrl = media.DisplayUrl, Type = "Video", VideoInfo = new VideoInfo { VideoId = variant.Url, VideoType = "Twitter", Size = new VideoInfo.MediaSize { Width = media.Sizes.Large.Width, Height = media.Sizes.Large.Height }, VideoContentType = variant.ContentType } }); } else { yield return(new Media { MediaThumbnailUrl = media.MediaUrl + ":thumb", MediaUrl = media.MediaUrl + ":orig", ExpandedUrl = media.Url, DisplayUrl = media.DisplayUrl, Type = "Image" }); } } } #endregion }