示例#1
0
        public void TestParsingSpotifyPlaylist()
        {
            var graph = OpenGraph.ParseHtml(SpotifyPlaylistContent);

            Assert.Equal("Programming Jams, a playlist by Jefe on Spotify", graph.Title);
            Assert.Equal(string.Empty, graph.Metadata["og:description"].First().Value);
            Assert.Equal("https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe/playlist/2lzTTRqhYS6AkHPIvdX9u3", graph.Url.ToString());
            Assert.Null(graph.Image);
            Assert.Equal("music.playlist", graph.Type);
            Assert.Equal("https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe", graph.Metadata["music:creator"].First().Value);
            Assert.Equal("1020", graph.Metadata["music:song_count"].First().Value);
            Assert.Equal(2, graph.Metadata["music:song"].Count);
            Assert.Equal("https://open.spotify.com/track/3RL1cNdki1AsOLCMinb60a", graph.Metadata["music:song"][0].Value);
            Assert.Equal("1", graph.Metadata["music:song"][0].Properties["track"].First().Value);
            Assert.Equal("https://open.spotify.com/track/4yVfG04odefa7JanoF5r86", graph.Metadata["music:song"][1].Value);
            Assert.Equal("2", graph.Metadata["music:song"][1].Properties["track"].First().Value);
            Assert.Equal("AD", graph.Metadata["og:restrictions:country:allowed"][0].Value);
            Assert.Equal("AR", graph.Metadata["og:restrictions:country:allowed"][1].Value);
            Assert.Equal("en_US", graph.Metadata["og:locale:alternate"][0].Value);
            Assert.Equal("en_GB", graph.Metadata["og:locale:alternate"][1].Value);

            Assert.Equal(@"<meta property=""og:title"" content=""Programming Jams, a playlist by Jefe on Spotify""><meta property=""og:description"" content=""""><meta property=""og:url"" content=""https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe/playlist/2lzTTRqhYS6AkHPIvdX9u3""><meta property=""og:image"" content=""""><meta property=""og:type"" content=""music.playlist""><meta property=""music:creator"" content=""https://open.spotify.com/user/er811nzvdw2cy2qgkrlei9sqe""><meta property=""music:song_count"" content=""1020""><meta property=""music:song"" content=""https://open.spotify.com/track/3RL1cNdki1AsOLCMinb60a""><meta property=""music:song:track"" content=""1""><meta property=""music:song"" content=""https://open.spotify.com/track/4yVfG04odefa7JanoF5r86""><meta property=""music:song:track"" content=""2""><meta property=""og:restrictions:country:allowed"" content=""AD""><meta property=""og:restrictions:country:allowed"" content=""AR""><meta property=""og:locale:alternate"" content=""en_US""><meta property=""og:locale:alternate"" content=""en_GB"">", graph.ToString());
            Assert.Equal("og: http://ogp.me/ns# music: http://ogp.me/ns/music#", graph.HeadPrefixAttributeValue);
            Assert.Equal("xmlns:og=\"http://ogp.me/ns#\" xmlns:music=\"http://ogp.me/ns/music#\"", graph.HtmlXmlnsValues);
        }
示例#2
0
        public void TestParsingSpotifyAlbum()
        {
            var graph = OpenGraph.ParseHtml(SpotifyAlbumContent);

            Assert.Equal("Salutations", graph.Title);
            Assert.Empty(graph.Metadata["og:description"].First().Value);
            Assert.Equal("https://open.spotify.com/album/5YQGQfkjghbxW00eKy9YpJ", graph.Url.ToString());
            Assert.Null(graph.Image);
            Assert.Equal("music.album", graph.Type);
            Assert.Equal("https://open.spotify.com/artist/2Z7gV3uEh1ckIaBzTUCE6R", graph.Metadata["music:musician"].First().Value);
            Assert.Equal("2017-03-17", graph.Metadata["music:release_date"].Value());
            Assert.Equal(2, graph.Metadata["music:song"].Count);
            Assert.Equal("https://open.spotify.com/track/1JJUbiYekbYkdDhK1kp3C9", graph.Metadata["music:song"][0].Value);
            Assert.Equal("1", graph.Metadata["music:song"][0].Properties["disc"].Value());
            Assert.Equal("1", graph.Metadata["music:song"][0].Properties["track"].Value());
            Assert.Equal("https://open.spotify.com/track/3eitV6XbyRW0FxKEUh60Pi", graph.Metadata["music:song"][1].Value);
            Assert.Equal("1", graph.Metadata["music:song"][1].Properties["disc"].Value());
            Assert.Equal("2", graph.Metadata["music:song"][1].Properties["track"].Value());
            Assert.Equal("es", graph.Metadata["og:locale"].Value());
            Assert.Equal("es_US", graph.Metadata["og:locale"].First().Properties["alternate"][0].Value);
            Assert.Equal("es_ES", graph.Metadata["og:locale"].First().Properties["alternate"][1].Value);

            Assert.Equal(@"<meta property=""og:title"" content=""Salutations""><meta property=""og:description"" content=""""><meta property=""og:url"" content=""https://open.spotify.com/album/5YQGQfkjghbxW00eKy9YpJ""><meta property=""og:image"" content=""""><meta property=""og:type"" content=""music.album""><meta property=""music:musician"" content=""https://open.spotify.com/artist/2Z7gV3uEh1ckIaBzTUCE6R""><meta property=""music:release_date"" content=""2017-03-17""><meta property=""music:song"" content=""https://open.spotify.com/track/1JJUbiYekbYkdDhK1kp3C9""><meta property=""music:song:disc"" content=""1""><meta property=""music:song:track"" content=""1""><meta property=""music:song"" content=""https://open.spotify.com/track/3eitV6XbyRW0FxKEUh60Pi""><meta property=""music:song:disc"" content=""1""><meta property=""music:song:track"" content=""2""><meta property=""og:locale"" content=""es""><meta property=""og:locale:alternate"" content=""es_US""><meta property=""og:locale:alternate"" content=""es_ES"">", graph.ToString());
            Assert.Equal("og: http://ogp.me/ns# music: http://ogp.me/ns/music#", graph.HeadPrefixAttributeValue);
            Assert.Equal("xmlns:og=\"http://ogp.me/ns#\" xmlns:music=\"http://ogp.me/ns/music#\"", graph.HtmlXmlnsValues);
        }
示例#3
0
        public void TestUrlDecodingUrlValues()
        {
            var expectedUrl = "https://prod-video-us-west-2.pscp.tv/lXc5gSh6UPaWdc37LtVCb3UdtSfvj2QNutojPK2du5YWrNchfI4wXpwwHKTyfDhmfT2ibsBZV4doQeWlhSvI4A==/replay_thumbnail/us-west-2/periscope-replay-direct-live/eyJkIjowfQ/chunk_314.jpg?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsInZlcnNpb24iOiIyIn0.eyJBbGxvd2VkUHJvdG9jb2xzIjpbInRodW1iIl0sIkJyb2FkY2FzdElkIjoiMURYeHlaWlpWeWtLTSIsIkdyYW50VHlwZSI6InJlYWQiLCJHcmFudGVkQXQiOjE1NDQwNTgzMjgsIkdyYW50ZWRUbyI6IndlYi1yYXRlLWxpbWl0ZWQtMDA4NjkxZjE3ZDUyY2E3OTMyNTdlYWQ4NTkyOGE1N2IiLCJTdHJlYW1OYW1lIjoibFhjNWdTaDZVUGFXZGMzN0x0VkNiM1VkdFNmdmoyUU51dG9qUEsyZHU1WVdyTmNoZkk0d1hwd3dIS1R5ZkRobWZUMmlic0JaVjRkb1FlV2xoU3ZJNEE9PSIsImV4cCI6MTU0NDIzMTEyOH0.UbJfSn8A0BFBRJHAlhgBxAxGv4DuMnTnwGOztR-3swE&service=proxsee&digest=tGkjjGWVywQpODOMKx7vAqtCh-QohM9rSCR8KM_JtN4";
            var og          = OpenGraph.ParseHtml(PeriscopeTvContent);

            Assert.Equal(expectedUrl, og.Image.ToString());
            Assert.Equal("320", og.Metadata["image"].First().Properties["width"].Value());
            Assert.Equal("568", og.Metadata["image"].First().Properties["height"].Value());
        }
示例#4
0
        public void ParseHtml_HtmlMissingUrls_Test()
        {
            OpenGraph graph = OpenGraph.ParseHtml(this.invalidMissingRequiredUrls, false);

            Assert.AreEqual("product", graph.Type);
            Assert.AreEqual("Product Title", graph.Title);
            Assert.IsNull(graph.Image);
            Assert.IsNull(graph.Url);
            Assert.AreEqual("My Description", graph["description"]);
            Assert.AreEqual("Test Site", graph["site_name"]);
        }
示例#5
0
        public void ParseHtml_ValidGraphParsing_Test()
        {
            OpenGraph graph = OpenGraph.ParseHtml(this.validSampleContent, true);

            Assert.AreEqual("product", graph.Type);
            Assert.AreEqual("Product Title", graph.Title);
            Assert.AreEqual("http://www.test.com/test.png", graph.Image.ToString());
            Assert.AreEqual("http://www.test.com/", graph.Url.ToString());
            Assert.AreEqual("My Description", graph["description"]);
            Assert.AreEqual("Test Site", graph["site_name"]);
        }
示例#6
0
        public void FactParsingHtmlHtmlMissingUrlsFact()
        {
            OpenGraph graph = OpenGraph.ParseHtml(this.invalidMissingRequiredUrls);

            Assert.Equal("product", graph.Type);
            Assert.Equal("Product Title", graph.Title);
            Assert.Null(graph.Image);
            Assert.Null(graph.Url);
            Assert.Equal("My Description", graph["description"]);
            Assert.Equal("Fact Site", graph["site_name"]);
        }
示例#7
0
        public void ParseHtml_InvalidGraphParsingWithoutCheck_Test()
        {
            OpenGraph graph = OpenGraph.ParseHtml(this.invalidSampleContent);

            Assert.AreEqual(string.Empty, graph.Type);
            Assert.IsFalse(graph.ContainsKey("mistake"));
            Assert.AreEqual("Product Title", graph.Title);
            Assert.AreEqual("http://www.test.com/test.png", graph.Image.ToString());
            Assert.AreEqual("http://www.test.com/", graph.Url.ToString());
            Assert.AreEqual("My Description", graph["description"]);
            Assert.AreEqual("Test Site", graph["site_name"]);
        }
示例#8
0
        public void TestParsingHtmlInvalidGraphParsingWithoutCheckTest()
        {
            OpenGraph graph = OpenGraph.ParseHtml(this.invalidSampleContent);

            Assert.Equal(string.Empty, graph.Type);
            Assert.False(graph.Metadata.ContainsKey("mistake"));
            Assert.Equal("Product Title", graph.Title);
            Assert.Equal("http://www.test.com/test.png", graph.Image.ToString());
            Assert.Equal("http://www.test.com/", graph.Url.ToString());
            Assert.Equal("My Description", graph.Metadata["og:description"].First().Value);

            Assert.Equal("Test Site", graph.Metadata["og:site_name"].First().Value);
        }
示例#9
0
        public void TestParsingHtmlHtmlMissingUrlsTest()
        {
            OpenGraph graph = OpenGraph.ParseHtml(this.invalidMissingRequiredUrls);

            Assert.Equal(1, graph.Namespaces.Count);
            Assert.Equal("og", graph.Namespaces["og"].Prefix);
            Assert.Equal("http://ogp.me/ns#", graph.Namespaces["og"].SchemaUri.ToString());
            Assert.Equal("product", graph.Type);
            Assert.Equal("Product Title", graph.Title);
            Assert.Null(graph.Image);
            Assert.Null(graph.Url);
            Assert.Equal("My Description", graph.Metadata["og:description"].First().Value);
            Assert.Equal("My Description", graph.Metadata["description"].Value());
            Assert.Equal("Test Site", graph.Metadata["og:site_name"].First().Value);
            Assert.Equal("Test Site", graph.Metadata["site_name"].Value());
        }
 public async Task <LinkPreview> ParseHtmlAsync(string html)
 {
     return(await Task.Run(() =>
     {
         var openGraphData = OpenGraph.ParseHtml(html);
         if (openGraphData != null)
         {
             return new LinkPreview
             {
                 ImageUrl = openGraphData.Image,
                 Title = openGraphData.Title,
                 Html = openGraphData.OriginalHtml
             };
         }
         return null;
     }));
 }
示例#11
0
        public void TestParsingHtmlValidGraphParsingTest()
        {
            NamespaceRegistry.Instance.AddNamespace("gah", "http://www.geoffhorsey.com/ogp/pea_brain#", "pea_brain:size");
            OpenGraph graph = OpenGraph.ParseHtml(this.validSampleContent, true);

            Assert.Equal(3, graph.Namespaces.Count);
            Assert.Equal("og", graph.Namespaces["og"].Prefix);
            Assert.Equal("http://ogp.me/ns#", graph.Namespaces["og"].SchemaUri.ToString());
            Assert.Equal("product", graph.Namespaces["product"].Prefix);
            Assert.Equal("http://ogp.me/ns/product#", graph.Namespaces["product"].SchemaUri.ToString());
            Assert.Equal("gah", graph.Namespaces["gah"].Prefix);
            Assert.Equal("http://www.geoffhorsey.com/ogp/pea_brain#", graph.Namespaces["gah"].SchemaUri.ToString());

            Assert.Equal("product", graph.Type);
            Assert.Equal("Product Title", graph.Title);
            Assert.Equal("http://www.test.com/test.png", graph.Image.ToString());
            Assert.Equal("http://www.test.com/", graph.Url.ToString());
            Assert.Equal("My Description", graph.Metadata["og:description"].First().Value);
            Assert.Equal("My Description", graph.Metadata["description"].Value());
            Assert.Equal("Test Site", graph.Metadata["og:site_name"].First().Value);
            Assert.Equal("Test Site", graph.Metadata["og:site_name"].Value());
            Assert.Equal("small", graph.Metadata["gah:pea_brain:size"].First().Value);
            NamespaceRegistry.Instance.RemoveNamespace("gah");
        }
示例#12
0
        public async Task TestParsingYouTubeTagsInBody()
        {
            var html = await File.ReadAllTextAsync("./TestHtml/YoutubeTagsInBody.htm");

            var graph = OpenGraph.ParseHtml(html);

            Assert.NotEmpty(graph.Metadata);
            Assert.Equal("YouTube", graph.Metadata["og:site_name"].First());
            Assert.Equal("https://www.youtube.com/watch?v=c_-ViUmhqtk", graph.Url.ToString());
            Assert.Equal("PVE Corvette Build Guide | Cucumber Update!", graph.Title);
            Assert.Equal("https://i.ytimg.com/vi/c_-ViUmhqtk/maxresdefault.jpg", graph.Image.ToString());
            Assert.Equal("1280", graph.Metadata["og:image"].First().Properties["width"].First());
            Assert.Equal("720", graph.Metadata["og:image"].First().Properties["height"].First());
            Assert.Equal("The merch store is open!! Take a look▶️ https://teespring.com/stores/down-to-earth-storeWant to help support the channel? Get you name listed at the end of m...", graph.Metadata["og:description"].First());
            Assert.Equal("The merch store is open!! Take a look▶️ https://teespring.com/stores/down-to-earth-storeWant to help support the channel? Get you name listed at the end of m...", graph.Metadata["og:description"].First());
            Assert.Equal("video.other", graph.Type);
            Assert.Equal("https://www.youtube.com/embed/c_-ViUmhqtk", graph.Metadata["og:video:url"].First());
            Assert.Equal("https://www.youtube.com/embed/c_-ViUmhqtk", graph.Metadata["og:video:secure_url"].First());
            Assert.Equal("text/html", graph.Metadata["og:video:type"].First());
            Assert.Equal("1280", graph.Metadata["og:video:width"].First());
            Assert.Equal("720", graph.Metadata["og:video:height"].First());
            Assert.Equal("Elite dangerous", graph.Metadata["og:video:tag"][0]);
            Assert.Equal("corvette", graph.Metadata["og:video:tag"][1]);
            Assert.Equal("PVE", graph.Metadata["og:video:tag"][2]);
            Assert.Equal("build", graph.Metadata["og:video:tag"][3]);
            Assert.Equal("loadout", graph.Metadata["og:video:tag"][4]);
            Assert.Equal("fitting", graph.Metadata["og:video:tag"][5]);
            Assert.Equal("guide", graph.Metadata["og:video:tag"][6]);
            Assert.Equal("tutorial", graph.Metadata["og:video:tag"][7]);
            Assert.Equal("help", graph.Metadata["og:video:tag"][8]);
            Assert.Equal("2020", graph.Metadata["og:video:tag"][9]);
            Assert.Equal("D2EA", graph.Metadata["og:video:tag"][10]);
            Assert.Equal("shield", graph.Metadata["og:video:tag"][11]);
            Assert.Equal("cucumber", graph.Metadata["og:video:tag"][12]);
            Assert.Equal("newest", graph.Metadata["og:video:tag"][13]);
        }
示例#13
0
 public void TestParsingHtmlInvalidGraphParsingMissingAllMetaTest()
 {
     Assert.Throws <InvalidSpecificationException>(() => OpenGraph.ParseHtml(this.invalidMissingAllMeta, true));
 }
示例#14
0
 public void TestParsingHtmlInvalidGraphParsingTest()
 {
     Assert.Throws <InvalidSpecificationException>(() => OpenGraph.ParseHtml(this.invalidSampleContent, true));
 }
示例#15
0
 public void ParseHtml_InvaidGraphParsingMissingAllMeta_Test()
 {
     OpenGraph graph = OpenGraph.ParseHtml(this.invalidMissingAllMeta, true);
 }
示例#16
0
 public void ParseHtml_InvaidGraphParsing_Test()
 {
     OpenGraph graph = OpenGraph.ParseHtml(this.invalidSampleContent, true);
 }