Exemplo n.º 1
0
        private async Task AddOpenGraphDataToMessagesAsync(IEnumerable <MessageDto> messages)
        {
            var aTagRegex = new Regex("<a href=\"(.*?)\" target=\"_blank\">.*?<\\/a>");

            foreach (var m in messages)
            {
                if (string.IsNullOrEmpty(m.Content) || !aTagRegex.IsMatch(m.Content))
                {
                    continue;
                }

                var openGraphTasks = new List <Task <OpenGraph> >();
                var matches        = aTagRegex.Matches(m.Content);

                try {
                    foreach (Match match in matches)
                    {
                        // first group is the entire matched string
                        var url = HttpUtility.HtmlDecode(match.Groups[1].Value);
                        openGraphTasks.Add(OpenGraph.ParseUrlAsync(url));
                    }

                    var openGraphs = (await Task.WhenAll(openGraphTasks.ToArray())).ToList();
                    AddOpenGraphDataToMessage(openGraphs, m);
                } catch (Exception) {
                    // ignore errors for invalid open graph objects
                }
            }
        }
Exemplo n.º 2
0
        private async Task <OpenGraphResult> GetGraphResultAsync(HttpRequest req, OpenGraphRequest openGraphRequest)
        {
            string url = openGraphRequest.Url, id = openGraphRequest.Id;

            if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(id))
            {
                /**
                 *  This check is a hack in support of adding our own URLs to lists. Rendered URLs return no Open Graph
                 *  metadata and deep links return HTTP 404s when hosting in Blob storage. So we skip the HTTP request.
                 */
                if (!req.Host.HasValue || !url.Contains(req.Host.Host))
                {
                    try
                    {
                        OpenGraph graph = await OpenGraph.ParseUrlAsync(url, "Urlist");

                        HtmlDocument doc = new HtmlDocument();
                        doc.LoadHtml(graph.OriginalHtml);
                        var descriptionMetaTag = doc.DocumentNode.SelectSingleNode("//meta[@name='description']");
                        var titleTag           = doc.DocumentNode.SelectSingleNode("//head/title");
                        return(new OpenGraphResult(id, graph, descriptionMetaTag, titleTag));
                    }
                    catch (Exception)
                    {
                        // Todo - Add logging
                    }
                }
            }
            return(new OpenGraphResult {
                Id = id
            });
        }
Exemplo n.º 3
0
        public static async Task <OpenGraphResult> GetGraphResult(dynamic singleLinkItem, ILogger log)
        {
            string url = singleLinkItem.url, id = singleLinkItem.id;

            if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(id))
            {
                try
                {
                    OpenGraph graph = await OpenGraph.ParseUrlAsync(url, "Urlist");

                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(graph.OriginalHtml);
                    var descriptionMetaTag = doc.DocumentNode.SelectSingleNode("//meta[@name='description']");
                    var titleTag           = doc.DocumentNode.SelectSingleNode("//head/title");
                    return(new OpenGraphResult(id, graph, descriptionMetaTag, titleTag));
                }
                catch (Exception ex)
                {
                    log.LogError(ex, ex.Message);
                    return(new OpenGraphResult {
                        Id = id
                    });
                }
            }
            return(null);
        }
Exemplo n.º 4
0
        public void TestParsingUrlValidateEncodingIsCorrect()
        {
            var expectedContent = "Создайте себе горное настроение с нашим первым фан-китом по игре #SteepGame&amp;#33; -&amp;gt; http://ubi.li/u8w9n";
            var tags            = OpenGraph.ParseUrl("https://vk.com/wall-41600377_66756");

            Assert.Equal(expectedContent, tags.Metadata["og:description"].First().Value);
        }
Exemplo n.º 5
0
        public void TestParsingUrlTest()
        {
            OpenGraph graph = OpenGraph.ParseUrl(SpacedLink);

            Assert.Contains("<html", graph.OriginalHtml);
            this.AssertSpaced(graph);
        }
Exemplo n.º 6
0
        public void TestParsingUrlTest()
        {
            OpenGraph graph = OpenGraph.ParseUrl(SpacedLink);

            Assert.Contains("<html", graph.OriginalHtml, StringComparison.InvariantCultureIgnoreCase);
            this.AssertSpaced(graph);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Tests calling <c>MakeOpenGraph</c> method
        /// </summary>
        public void MakeOpenGraph_Test()
        {
            var title       = "some title";
            var type        = "website";
            var image       = "http://www.go.com/someimg.jpg";
            var url         = "http://www.go.com/";
            var description = "some description";
            var siteName    = "my site";
            var graph       = OpenGraph.MakeGraph(title, type, image, url, description, siteName);

            Assert.AreEqual(title, graph.Title);
            Assert.AreEqual(type, graph.Type);
            Assert.AreEqual(image, graph.Image.ToString());
            Assert.AreEqual(url, graph.Url.ToString());
            Assert.AreEqual(description, graph["description"]);
            Assert.AreEqual(siteName, graph["site_name"]);

            var expected = "<meta property=\"og:title\" content=\"some title\">" +
                           "<meta property=\"og:type\" content=\"website\">" +
                           "<meta property=\"og:image\" content=\"http://www.go.com/someimg.jpg\">" +
                           "<meta property=\"og:url\" content=\"http://www.go.com/\">" +
                           "<meta property=\"og:description\" content=\"some description\">" +
                           "<meta property=\"og:site_name\" content=\"my site\">";

            Assert.AreEqual(expected, graph.ToString());
        }
Exemplo n.º 9
0
        // return remote page title from URI
        public static string GetTitleFromUri(string @remoteUri)
        {
            try
            {
                // try using Open Graph to get target page title
                var graph = OpenGraph.ParseUrl(@remoteUri, "Voat.co OpenGraph Parser");
                if (!string.IsNullOrEmpty(graph.Title))
                {
                    var tmpStringWriter = new StringWriter();
                    HttpUtility.HtmlDecode(graph.Title, tmpStringWriter);
                    return(tmpStringWriter.ToString());
                }

                // Open Graph parsing failed, try getting HTML TITLE tag instead
                HtmlWeb      htmlWeb      = new HtmlWeb();
                HtmlDocument htmlDocument = htmlWeb.Load(@remoteUri);

                if (htmlDocument != null)
                {
                    var titleNode = htmlDocument.DocumentNode.Descendants("title").SingleOrDefault();
                    if (titleNode != null)
                    {
                        return(titleNode.InnerText);
                    }
                }

                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("OpenGraphId,Title,URL,Image,Determiner,Locale,SiteName")] OpenGraph openGraph)
        {
            if (id != openGraph.OpenGraphId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(openGraph);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!OpenGraphExists(openGraph.OpenGraphId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(openGraph));
        }
Exemplo n.º 11
0
        public async Task TestParsingAsyncTest()
        {
            OpenGraph graph = await OpenGraph.ParseUrlAsync(SpacedLink).ConfigureAwait(false);

            Assert.Contains("<html", graph.OriginalHtml, StringComparison.InvariantCultureIgnoreCase);
            this.AssertSpaced(graph);
        }
Exemplo n.º 12
0
        public void TestGetOpenGraphImageFromUri()
        {
            Uri testUri = new Uri("http://www.bbc.com/news/technology-32194196");
            var graph   = OpenGraph.ParseUrl(testUri);

            Assert.AreEqual("http://ichef.bbci.co.uk/news/1024/media/images/80755000/jpg/_80755021_163765270.jpg", graph.Image.ToString(), "Unable to extract domain from given Uri.");
        }
Exemplo n.º 13
0
        public async Task TestParsingAsyncTest()
        {
            OpenGraph graph = await OpenGraph.ParseUrlAsync(SpacedLink);

            Assert.Contains("<html", graph.OriginalHtml);
            this.AssertSpaced(graph);
        }
Exemplo n.º 14
0
        public override async Task <string> ProcessMessageAsync(DynamoDBEvent dynamoDbEvent)
        {
            LogInfo($"# DynamoDB Stream Records Count = {dynamoDbEvent.Records.Count}");
            foreach (var record in dynamoDbEvent.Records.Where(r => r.EventName == "INSERT"))
            {
                LogInfo($"EventID = {record.EventID}");
                var url = new Uri(record.Dynamodb.NewImage["Url"].S);
                try {
                    var graph = await OpenGraph.ParseUrlAsync(url);

                    var bookmark = new Bookmark {
                        ID          = record.Dynamodb.NewImage["ID"].S,
                        Url         = url,
                        Title       = graph.Title,
                        Description = graph.Metadata["og:description"].FirstOrDefault()?.Value,
                        ImageUrl    = graph.Image,
                        Type        = graph.Type
                    };
                    LogInfo($"Updated Bookmark:\n{SerializeJson(bookmark)}");
                    _table.PutItemAsync(Document.FromJson(SerializeJson(bookmark))).Wait();
                } catch (Exception e) {
                    LogError(e);
                    continue;
                }
            }
            return("Ok");
        }
        private async Task <OpenGraphResult> GetGraphResult(HttpRequest req, dynamic singleLinkItem, ILogger log)
        {
            string url = singleLinkItem.url, id = singleLinkItem.id;

            if (!string.IsNullOrEmpty(url) && !string.IsNullOrEmpty(id))
            {
                /**
                 *  This check is a hack in support of adding our own URLs to lists. Rendered URLs return no Open Graph
                 *  metadata and deep links return HTTP 404s when hosting in Blob storage. So we skip the HTTP request.
                 */
                if (!req.Host.HasValue || !url.Contains(req.Host.Host))
                {
                    try
                    {
                        OpenGraph graph = await OpenGraph.ParseUrlAsync(url, "Urlist");

                        HtmlDocument doc = new HtmlDocument();
                        doc.LoadHtml(graph.OriginalHtml);
                        var descriptionMetaTag = doc.DocumentNode.SelectSingleNode("//meta[@name='description']");
                        var titleTag           = doc.DocumentNode.SelectSingleNode("//head/title");
                        return(new OpenGraphResult(id, graph, descriptionMetaTag, titleTag));
                    }
                    catch (Exception ex)
                    {
                        log.LogError(ex, "Processing URL {URL} failed. {Message}", url, ex.Message);
                    }
                }
            }
            return(new OpenGraphResult {
                Id = id
            });
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
        public void UpdateUi()
        {
            this.hyperlinkManager = new HyperlinkManager();

            if (MessageItem != null)
            {
                PreviewFrame.Visibility = Visibility.Collapsed;

                if (hyperlinkManager.LinkClicked != null)
                {
                    hyperlinkManager.LinkClicked -= MediaPreview_Clicked;
                }

                if (MessageItem.Type == MessageType.Info || MessageItem.Type == MessageType.JoinPart)
                {
                    MessageBox.Style = (Style)Application.Current.Resources["InfoTextRichStyle"];
                }
                else if (MessageItem.Type == MessageType.Action)
                {
                    MessageBox.FontStyle = Windows.UI.Text.FontStyle.Italic;
                }

                if (MessageItem.Type == MessageType.MOTD)
                {
                    this.FontFamily = new FontFamily("Consolas");
                }
                else
                {
                    this.FontFamily = new FontFamily(Config.GetString(Config.FontFamily, "Segoe UI"));
                    this.FontSize   = Config.GetInt(Config.FontSize, 14);
                }

                hyperlinkManager.SetText(MessageParagraph, MessageItem.Text);
                hyperlinkManager.LinkClicked += MediaPreview_Clicked;
            }

            try
            {
                if (!hyperlinkManager.InlineLink && hyperlinkManager.FirstLink != null && Config.GetBoolean(Config.ShowMetadata, true))
                {
                    Task.Run(async() =>
                    {
                        var graph = await OpenGraph.ParseUrlAsync(hyperlinkManager.FirstLink);

                        if (graph.Values.Count > 0 && graph.Title != "" && graph["description"] != "")
                        {
                            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                PreviewFrame.Visibility = Visibility.Visible;
                                PreviewFrame.Navigate(typeof(LinkView), graph, new SuppressNavigationTransitionInfo());
                            });
                        }
                    });
                }
            }
            catch { } // swallow exceptions

            this.HasLoaded = true;
            UpdateLayout();
        }
Exemplo n.º 18
0
        public void TestUrlDecodingUrlValues()
        {
            var expectedUrl = "https://tn.periscope.tv/lXc5gSh6UPaWdc37LtVCb3UdtSfvj2QNutojPK2du5YWrNchfI4wXpwwHKTyfDhmfT2ibsBZV4doQeWlhSvI4A==/chunk_314.jpg?Expires=1781852253&Signature=U5OY3Y2HRb4ETmakQAPwMcv~bqu6KygIxriooa41rk64RcDfjww~qpVgMR-T1iX4S9NxfvXHLMT3pEckBDEOicsNO7oUAo4NieH9GRB2Sv0EA7swxLojD~Zn98ThNWTF5fSzv6SSPjyvctsqBiRmvAN6x7fmMH6l3vzx8ePSCgdEm8-31lUAz7lReBNZQjYSi~C8AwqZVI0Mx6y8lNKklL~m0e6RTGdvr~-KIDewU3wpjSdX7AgpaXXjahk4x-ceUUKcH3T1j--ZjaY7nqPO9fbMZFNPs502A32mrcmaZCzvaD~AuoH~u3y44mJVjzHRrpTxHIBklqHxAgc7dzverg__&Key-Pair-Id=APKAIHCXHHQVRTVSFRWQ";
            var og          = OpenGraph.ParseUrl("https://www.periscope.tv/w/1DXxyZZZVykKM");

            Assert.Equal(expectedUrl, og.Image.ToString());
        }
Exemplo n.º 19
0
        public async Task TestParsingUrlAsyncValidateEncodingIsCorrect()
        {
            var expectedContent =
                "Создайте себе горное настроение с нашим первым фан-китом по игре #SteepGame&amp;#33; -&amp;gt; http://ubi.li/u8w9n";
            var tags = await OpenGraph.ParseUrlAsync("https://vk.com/wall-41600377_66756");

            Assert.That(tags["description"], Is.EqualTo(expectedContent));
        }
Exemplo n.º 20
0
        public void FactParsingUrlValidateEncodingIsCorrect()
        {
            var expectedContent =
                "Создайте себе горное настроение с нашим первым фан-китом по игре #SteepGame&amp;#33; -&amp;gt; http://ubi.li/u8w9n";
            var tags = OpenGraph.ParseUrl("https://vk.com/wall-41600377_66756");

            Assert.True(tags["description"] == expectedContent);
        }
Exemplo n.º 21
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            this.graph = e.Parameter as OpenGraph;

            setupPageAsync();
        }
Exemplo n.º 22
0
        private async void MessageLine_Loaded(object sender, RoutedEventArgs e)
        {
            DataContext = MessageItem;
            UpdateLayout();

            if (double.IsNaN(UsernameBox.ActualWidth) || double.IsNaN(TimestampBox.ActualWidth))
            {
                return;
            }

            MessageParagraph.TextIndent = UsernameBox.ActualWidth + TimestampBox.ActualWidth;

            if (MessageBox.ActualHeight > UsernameBox.ActualHeight)
            {
                Thickness margin = new Thickness(0, -1, 0, 0);
                MessageBox.Margin = margin;
            }

            if (MessageItem != null)
            {
                if (MessageItem.Type == MessageType.Info)
                {
                    UsernameBox.Style = (Style)Application.Current.Resources["InfoTextBlockStyle"];
                    MessageBox.Style  = (Style)Application.Current.Resources["InfoTextRichStyle"];
                }
                else if (MessageItem.Type == MessageType.Action)
                {
                    UsernameBox.FontStyle = Windows.UI.Text.FontStyle.Italic;
                    MessageBox.FontStyle  = Windows.UI.Text.FontStyle.Italic;
                }

                if (MessageItem.Mention)
                {
                    UsernameBox.Foreground = new SolidColorBrush(Colors.Red);
                    MessageBox.Foreground  = new SolidColorBrush(Colors.Red);
                }

                hyperlinkManager.SetText(MessageParagraph, MessageItem.Text);
                hyperlinkManager.LinkClicked += MediaPreview_Clicked;
            }

            try
            {
                if (!hyperlinkManager.InlineLink && hyperlinkManager.FirstLink != null && Config.GetBoolean(Config.ShowMetadata, true))
                {
                    var graph = await OpenGraph.ParseUrlAsync(hyperlinkManager.FirstLink);

                    if (graph.Values.Count > 0 && graph.Title != "" && graph["description"] != "")
                    {
                        PreviewFrame.Visibility = Visibility.Visible;
                        PreviewFrame.Navigate(typeof(LinkView), graph);
                    }
                }
            }
            catch { } // swallow exceptions

            this.HasLoaded = true;
        }
Exemplo n.º 23
0
        private static void Main(string[] args)
        {
            string url = "http://www.kickstarter.com/projects/archieshepp/attica-blues";
            var data = new OpenGraph().ParseFromUrl(url);

            foreach (var pair in data) {
                Console.WriteLine("{0} => {1}", pair.Key, pair.Value);
            }
        }
Exemplo n.º 24
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());
        }
Exemplo n.º 25
0
 public async Task <object> FetchOpenGraph(string url)
 {
     try {
         return(await OpenGraph.ParseUrlAsync(url, timeout : 6000));
     }
     catch {
         return(null);
     }
 }
Exemplo n.º 26
0
        public void TestMetaCharsetParsesCorrectly()
        {
            var expectedTitle       = "Réalité virtuelle : 360° de bonheur à améliorer";
            var expectedDescription = "Le cinéma à 360° a désormais son festival. Organisé par le Forum des images, le premier Paris Virtual Film Festival a donc vu le jour. Narration, réalisation, montage… une révolution balbutiante est en marche. Tour d&#039;horizon.";

            var ogs = OpenGraph.ParseUrl("http://www.telerama.fr/cinema/realite-virtuelle-360-de-bonheur-a-ameliorer,144339.php?utm_medium=Social&utm_source=Twitter&utm_campaign=Echobox&utm_term=Autofeed#link_time=1466595239");

            Assert.Equal(expectedTitle, ogs.Title);
            Assert.Equal(expectedDescription, ogs.Metadata["og:description"].First().Value);
        }
Exemplo n.º 27
0
        private static void Main(string[] args)
        {
            string url  = "http://www.kickstarter.com/projects/archieshepp/attica-blues";
            var    data = new OpenGraph().ParseFromUrl(url);

            foreach (var pair in data)
            {
                Console.WriteLine("{0} => {1}", pair.Key, pair.Value);
            }
        }
Exemplo n.º 28
0
        public OpenGraphProfileOutput GetOpenGraph(string url)
        {
            var result = OpenGraph.ParseUrl(url);

            return(new OpenGraphProfileOutput()
            {
                Image = result?.Image?.ToString(),
                Title = result?.Title,
            });
        }
Exemplo n.º 29
0
        public async Task TestParsingUrlsWithoutScheme()
        {
            var withoutScheme   = SpacedLink.Replace("http://", string.Empty, StringComparison.InvariantCultureIgnoreCase);
            var withHttpsScheme = SpacedLink.Replace("http", "https", StringComparison.InvariantCultureIgnoreCase);

            OpenGraph.ParseUrl(withHttpsScheme);
            await OpenGraph.ParseUrlAsync(withHttpsScheme).ConfigureAwait(false);

            OpenGraph.ParseUrl(withoutScheme);
            await OpenGraph.ParseUrlAsync(withoutScheme).ConfigureAwait(false);
        }
Exemplo n.º 30
0
        public void ParseUrl_AmazonUrl_Test()
        {
            OpenGraph graph = OpenGraph.ParseUrl("http://www.amazon.com/Spaced-Complete-Simon-Pegg/dp/B0019MFY3Q");

            Assert.AreEqual("http://www.amazon.com/dp/B0019MFY3Q/ref=tsm_1_fb_lk", graph.Url.ToString());
            Assert.IsTrue(graph.Title.StartsWith("Spaced: The Complete Series"));
            Assert.IsTrue(graph["description"].Contains("Spaced"));
            Assert.IsTrue(graph.Image.ToString().StartsWith("http://ecx.images-amazon.com/images/I"));
            Assert.AreEqual("movie", graph.Type);
            Assert.AreEqual("Amazon.com", graph["site_name"]);
        }
        public async Task <String> ScrapMeta(string url)
        {
            OpenGraph graph = await OpenGraph.ParseUrlAsync(url);

            HtmlDocument pageDocument = new HtmlDocument();

            pageDocument.LoadHtml(graph.ToString());
            string newContent = "<html><head><title>Fc lunaar</title>" + pageDocument.DocumentNode.OuterHtml + "</head><body></body></html><script>window.location.replace('" + url + "')</script>";

            return(newContent);
        }