public static Notification Translate(YoutubeFeed youtubeFeed)
 {
     return(new Notification()
     {
         Content = $"{youtubeFeed.Link}"
     });
 }
        public override RawYoutubeType DoQuery()
        {
            String json= YoutubeWeb.CallApiMethod(YoutubeWeb.WebMethod.GET, this, null, true, YoutubeWeb.Data.Empty);

            YoutubeFeed empty = new YoutubeFeed(null);
            return (RawYoutubeType)empty.FromJson(json);
        }
Esempio n. 3
0
        private static void CreateHtmlFromPoco(YoutubeFeed videos)
        {
            Console.WriteLine("\n----------TASK6----------");

            StringBuilder html = new StringBuilder();

            html.AppendLine("<!DOCTYPE html>");
            html.AppendLine("<html>");
            html.AppendLine("<head><title>Telerik Academy Videos</title></head>");
            html.AppendLine("<body>");
            html.AppendLine("<meta charset=\"ISO - 8859 - 1\">");

            foreach (var video in videos.Feed.Videos)
            {
                html.AppendLine("<div>");
                html.AppendLine($"<div><a href=\"{video.Link.Url}\">{video.Title}</a></div>");
                html.AppendLine($"<iframe src=\"{ video.VideoMedia.Content.ContentUrl}\">");
                html.AppendLine("</iframe>");
                html.AppendLine($"<div>Published by:<a href=\"{video.VideoAuthor.Uri}\">{video.VideoAuthor.Name}</a></div>");
                html.AppendLine($"<div>Published on:<strong> {video.PublishedOn.ToShortDateString()} {video.PublishedOn.ToShortTimeString()}</strong></div>");
                html.AppendLine($"<div>Updated on:<strong> {video.Updated.ToShortDateString()} {video.Updated.ToShortTimeString()}</strong></div>");
                html.AppendLine($"<div>Views:<strong> {video.VideoMedia.CommunityStats.Statistics.ViewsCount}</strong></div>");
                html.AppendLine($"<div>Rating:<strong> { video.VideoMedia.CommunityStats.Rating.Average}</strong></div>");
                html.AppendLine($"<p>Description:{ video.VideoMedia.Description}</p>");
                html.AppendLine("</div>");
            }

            html.AppendLine("</body>");
            html.AppendLine("</html>");

            File.WriteAllText("../../video-feed.html", html.ToString(), Encoding.UTF8);

            Console.WriteLine("video-feed.html created. Go to the root directory and open file.");
        }
 public override RawYoutubeType DoQuery()
 {
     YoutubeFeed empty = new YoutubeFeed(null);
     return (RawYoutubeType)empty.FromJson(
             YoutubeWeb.CallApiMethod(
                 YoutubeWeb.WebMethod.GET,
                 this,
                 null, false, YoutubeWeb.Data.Empty));
     //---
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            var url  = "https://www.youtube.com/feeds/videos.xml?channel_id=UCLC-vbm7OWvpbqzXaoAMGGw";
            var path = "../../video-feed.xml";

            Console.OutputEncoding = Encoding.UTF8;

            DownloadFile(url, path);

            var jsonString = ParseTheXmlToJson(path);

            LinqToJsonPrintTitles(jsonString);

            YoutubeFeed videos = ParseJsonToVideosPOCO(jsonString);

            CreateHtmlFromPoco(videos);
        }
Esempio n. 6
0
        private void GetChannels(List <string> files)
        {
            foreach (var file in files)
            {
                var doc = new XmlDocument();
                doc.Load(file);

                // TODO: Better way of traversing the XML tree
                RecursiveWalk(doc.FirstChild, "xmlUrl");

                if (videoXmlSources.Any())
                {
                    foreach (var url in videoXmlSources)
                    {
                        XNamespace ns         = "http://www.w3.org/2005/Atom";
                        var        httpClient = new HttpClient();
                        var        result     = httpClient.GetAsync(url).Result;

                        var stream = result.Content.ReadAsStreamAsync().Result;

                        var itemXml      = XElement.Load(stream);
                        var authorName   = itemXml.Element(ns + "author").Element(ns + "name").Value;
                        var videoEntries = itemXml.Elements(ns + "entry");

                        if (videoEntries.Any())
                        {
                            var results = (from entry in videoEntries
                                           select new YoutubeFeedEntry
                            {
                                Title = IllegalCharacterReplacer.Replace(entry.Element(ns + "title").Value),
                                Published = DateTime.Parse(entry.Element(ns + "published").Value),
                                VideoLink = entry.Element(ns + "link").Attribute("href").Value
                            }).ToList();

                            var youtubeFeed = new YoutubeFeed();
                            youtubeFeed.Name = IllegalCharacterReplacer.Replace(authorName);
                            youtubeFeed.Entries.AddRange(results);

                            var message = new ChannelsTrackerMessages.CheckLatestChannelEntries(youtubeFeed);
                            Context.ActorSelection(Sender.Path).Tell(message);
                        }
                    }
                }
            }
        }
 public YoutubePlaylist(string playlistId, YoutubeFeed raw)
     : base(playlistId, raw)
 {
 }
Esempio n. 8
0
        public void Initialize(Rendering rendering)
        {
            //Get current item
            var dataSource = rendering.DataSource;

            if (dataSource.IsNullOrEmpty())
            {
                dataSource = Sitecore.Configuration.Settings.GetSetting("FeedsDataSource", "{AF7BCA0A-4C7F-4ACA-9956-E4801143775A}");
            }

            CurrentItem = Sitecore.Context.Database.GetItem(dataSource);

            if (CurrentItem != null)
            {
                // Get all social feeds items
                var socialFeeds = CurrentItem.InnerItem.GetChildren().ToList();
                FacebookApi  = new FacebookApi();
                TwitterApi   = new TwitterApi();
                InstagramApi = new InstagramApi();
                YouTubeApi   = new YouTubeApi();
                PinterestApi = new PinterestApi();
                FlickrApi    = new FlickrApi();

                if (socialFeeds.Any())
                {
                    // Get facebook feed item and bind facebook api class properties
                    var facebookFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FacebookFeed.TemplateId));
                    if (facebookFeedItem != null)
                    {
                        var facebookFeed = new FacebookFeed(facebookFeedItem);
                        if (facebookFeed != null)
                        {
                            if (facebookFeed.FacebookAccount.TargetItem != null)
                            {
                                var facebookAccount = new FacebookAccount(facebookFeed.FacebookAccount.TargetItem);

                                if (facebookAccount.SocialLink != null)
                                {
                                    if (!ShowSocialFeed)
                                    {
                                        ShowSocialFeed = true;
                                    }
                                    FacebookApi.ApiId = string.Join("|",
                                                                    new string[]
                                    {
                                        facebookAccount.ApiId.Value, facebookAccount.ApiKey.Value
                                    });
                                    FacebookApi.Icon = facebookAccount.SocialLink != null
                                        ? MediaManager.GetMediaUrl(
                                        new SocialMedia(facebookAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                        : "";

                                    // new BaseFeed()

                                    FacebookApi.Priority = GetPriority(facebookFeed.BaseFeed);
                                }
                            }
                        }
                    }

                    // Get twitter feed item and bind twitter api class properties
                    var twitterFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(TwitterFeed.TemplateId));
                    if (twitterFeedItem != null)
                    {
                        var twitterFeed = new TwitterFeed(twitterFeedItem);
                        if (twitterFeed != null)
                        {
                            if (twitterFeed.TwitterAccount.TargetItem != null)
                            {
                                var twitterAccount = new TwitterAccount(twitterFeed.TwitterAccount.TargetItem);

                                if (!ShowSocialFeed)
                                {
                                    ShowSocialFeed = true;
                                }
                                TwitterApi.HashTagsWithTokens = string.Join("|", new string[]
                                {
                                    string.Join(",",
                                                twitterFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value)),
                                    twitterAccount.TwitterToken.Value,
                                    twitterAccount.TwitterTokenSecret.Value,
                                    twitterAccount.TwitterConsumerKey.Value,
                                    twitterAccount.TwitterConsumerSecret.Value
                                });

                                TwitterApi.Icon = twitterAccount.SocialLink != null
                                    ? MediaManager.GetMediaUrl(
                                    new SocialMedia(twitterAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                    : "";

                                TwitterApi.Priority = GetPriority(twitterFeed.BaseFeed);
                            }
                        }
                    }

                    // Get instagram feed item and bind instagram api class properties
                    var instagramFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(InstagramFeed.TemplateId));

                    if (instagramFeedItem != null)
                    {
                        var instagramFeed = new InstagramFeed(instagramFeedItem);
                        if (instagramFeed != null)
                        {
                            if (instagramFeed.InstagramAccount.TargetItem != null)
                            {
                                var instagramAccount = new InstagramAccount(instagramFeed.InstagramAccount.TargetItem);

                                if (!ShowSocialFeed)
                                {
                                    ShowSocialFeed = true;
                                }
                                InstagramApi.HashTags = string.Join(",",
                                                                    instagramFeed.Hashtags.GetItems().Select(i => new Hashtag(i).Value.Value));
                                InstagramApi.AccessToken = instagramAccount.AccessToken.Value;
                                InstagramApi.ClientId    = instagramAccount.InstagramClientId.Value;
                                InstagramApi.Icon        = instagramAccount.SocialLink != null
                                    ? MediaManager.GetMediaUrl(
                                    new SocialMedia(instagramAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                    : "";


                                InstagramApi.Priority = GetPriority(instagramFeed.BaseFeed);
                            }
                        }
                    }


                    // Get youtube feed item and bind youtube api class properties
                    var youTubeFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(YoutubeFeed.TemplateId));
                    if (youTubeFeedItem != null)
                    {
                        var youTubeFeed = new YoutubeFeed(youTubeFeedItem);
                        if (youTubeFeed.YouTubeAccount.TargetItem != null)
                        {
                            var youtubeAccount = new YoutubeAccount(youTubeFeed.YouTubeAccount.TargetItem);

                            if (!ShowSocialFeed)
                            {
                                ShowSocialFeed = true;
                            }
                            YouTubeApi.AccountId     = youtubeAccount.AccountId.Value;
                            YouTubeApi.AccountApiKey = youtubeAccount.AccountApiKey.Value;

                            YouTubeApi.Icon = youtubeAccount.SocialLink != null
                                ? MediaManager.GetMediaUrl(
                                new SocialMedia(youtubeAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                : "";

                            YouTubeApi.Priority = GetPriority(youTubeFeed.BaseFeed);
                        }
                    }

                    // Get pinterest feed item and bind pinterest api class properties
                    var pinterestFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(PinterestFeed.TemplateId));
                    if (pinterestFeedItem != null)
                    {
                        var pinterestFeed = new PinterestFeed(pinterestFeedItem);
                        if (pinterestFeed != null && pinterestFeed.PinterestAccount.TargetItem != null)
                        {
                            var pinterestAccount = new PinterestAccount(pinterestFeed.PinterestAccount.TargetItem);


                            if (!ShowSocialFeed)
                            {
                                ShowSocialFeed = true;
                            }
                            PinterestApi.AccountId = pinterestAccount.AccountId.Value;

                            PinterestApi.Icon = pinterestAccount.SocialLink != null
                                ? MediaManager.GetMediaUrl(
                                new SocialMedia(pinterestAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                : "";

                            PinterestApi.Priority = GetPriority(pinterestFeed.BaseFeed);
                        }
                    }

                    // Get flickr feed item and bind flickr api class properties
                    var flickrFeedItem = socialFeeds.FirstOrDefault(i => i.IsOfType(FlickrFeed.TemplateId));
                    if (flickrFeedItem != null)
                    {
                        var flickrFeed = new FlickrFeed(flickrFeedItem);
                        if (flickrFeed != null)
                        {
                            if (flickrFeed.FlickrAccount.TargetItem != null)
                            {
                                var flickrAccount = new FlickrAccount(flickrFeed.FlickrAccount.TargetItem);

                                if (!ShowSocialFeed)
                                {
                                    ShowSocialFeed = true;
                                }
                                FlickrApi.AccountId = flickrAccount.AccountId.Value;
                                FlickrApi.Icon      = flickrAccount.SocialLink != null
                                    ? MediaManager.GetMediaUrl(
                                    new SocialMedia(flickrAccount.SocialLink.TargetItem).SocialIcon.MediaItem)
                                    : "";

                                FlickrApi.Priority = GetPriority(flickrFeed.BaseFeed);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 public CheckLatestChannelEntries(YoutubeFeed feed)
 {
     Feed = feed;
 }