private void CheckForLatestVideos(ChannelsTrackerMessages.CheckLatestChannelEntries videoInfo)
        {
            var downloadDir = new DirectoryInfo(_downloadFolder);
            var channelDir  = downloadDir.CreateSubdirectory(videoInfo.Feed.Name);

            var videos        = channelDir.GetFiles().Select(f => f.Name.Substring(0, f.Name.Length - 4));
            var missingVideos = videoInfo.Feed.Entries.Where(v => !videos.Contains(v.Title));

            foreach (var item in missingVideos)
            {
                var message = new HttpDownloaderMessages.DownloadVideo(item.VideoLink, videoInfo.Feed.Name, item.Title, channelDir.FullName);
                Context.ActorSelection(_downloadActorPath).Tell(message);
            }
        }
예제 #2
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);
                        }
                    }
                }
            }
        }