public async Task <List <Episode> > DownloadFeedList()
        {
            try
            {
                List <Episode> episodes = new List <Episode>();

                // Cloudflare solver
                var handler = new ClearanceHandler
                {
                    MaxTries       = 3,
                    ClearanceDelay = 3000
                };

                var client = new HttpClient(handler);
                client.Timeout = TimeSpan.FromSeconds(5);

                var content = await client.GetStringAsync(FeedUrl);

                // Create reader and get items
                XmlTextReader          reader          = new XmlTextReader(new StringReader(content));
                SyndicationFeed        syndicationFeed = SyndicationFeed.Load(reader);
                List <SyndicationItem> feedList        = new List <SyndicationItem>(syndicationFeed.Items);

                foreach (SyndicationItem syndicationItem in feedList)
                {
                    Episode episode = new Episode()
                    {
                        // Name = FileNameParser.GetNameFromItem(FileNameParser.TorrentNameParser(syndicationItem.Links[0].Uri.ToString())),
                        Name      = FileNameParser.GetNameFromItem(syndicationItem.Title.Text),
                        Link      = syndicationItem.Links[0].Uri.ToString(),
                        LocalPath = Path.Combine(Logic.LocalConfig.DownloadFolder, syndicationItem.Title.Text)
                    };

                    // double episodeNumber = FileNameParser.GetEpisodeNumberFromItem(FileNameParser.TorrentNameParser(syndicationItem.Links[0].Uri.ToString()));
                    double episodeNumber = FileNameParser.GetEpisodeNumberFromItem(syndicationItem.Title.Text);
                    if (episodeNumber.Equals(-1))
                    {
                        Log.Warning("Can't parse Feed Episode-number from: " + syndicationItem.Links[0].Uri);
                    }
                    else
                    {
                        episode.EpisodeNumber = episodeNumber;
                    }

                    episodes.Add(episode);
                }

                return(episodes);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "DownloadFeedList Error!");
                return(null);
            }
        }
예제 #2
0
        private List <TvShow> GetEpisodesFromFileList(List <FileInfo> fileInfos)
        {
            try
            {
                List <TvShow> tvShows = new List <TvShow>();

                foreach (var fileInfo in fileInfos)
                {
                    Episode episode = new Episode()
                    {
                        Name      = FileNameParser.GetNameFromItem(fileInfo.Name),
                        LocalPath = fileInfo.FullName
                    };

                    double episodeNumber = FileNameParser.GetEpisodeNumberFromItem(fileInfo.Name);
                    if (episodeNumber.Equals(-1))
                    {
                        OnExceptionEvent(new FileFormatException("Can't parse Local Episode-number from: " + fileInfo.Name));
                        continue;
                    }
                    else
                    {
                        episode.EpisodeNumber = episodeNumber;
                    }

                    TvShow tvShow = tvShows.SingleOrDefault(item => item.Name.Equals(episode.Name));
                    if (tvShow == null)
                    {
                        tvShows.Add(new TvShow()
                        {
                            Name     = episode.Name,
                            Episodes = new List <Episode>()
                            {
                                episode
                            }
                        });
                    }
                    else
                    {
                        tvShow.Episodes.Add(episode);
                    }
                }

                return(tvShows);
            }
            catch (Exception e)
            {
                OnExceptionEvent(e);
                return(null);
            }
        }
예제 #3
0
        public List <Episode> DownloadFeedList()
        {
            try
            {
                List <Episode> episodes = new List <Episode>();

                // Create reader and get items
                XmlTextReader          reader          = new XmlTextReader(FeedUrl);
                SyndicationFeed        syndicationFeed = SyndicationFeed.Load(reader);
                List <SyndicationItem> feedList        = new List <SyndicationItem>(syndicationFeed.Items);

                foreach (SyndicationItem syndicationItem in feedList)
                {
                    Episode episode = new Episode()
                    {
                        // Name = FileNameParser.GetNameFromItem(FileNameParser.TorrentNameParser(syndicationItem.Links[0].Uri.ToString())),
                        Name = FileNameParser.GetNameFromItem(syndicationItem.Title.Text),
                        Link = syndicationItem.Links[0].Uri.ToString()
                    };

                    // double episodeNumber = FileNameParser.GetEpisodeNumberFromItem(FileNameParser.TorrentNameParser(syndicationItem.Links[0].Uri.ToString()));
                    double episodeNumber = FileNameParser.GetEpisodeNumberFromItem(syndicationItem.Title.Text);
                    if (episodeNumber.Equals(-1))
                    {
                        LogHandler.WriteSystemLog("Can't parse Feed Episode-number from: " + syndicationItem.Links[0].Uri, LogLevel.Error);
                    }
                    else
                    {
                        episode.EpisodeNumber = episodeNumber;
                    }

                    episodes.Add(episode);
                }

                return(episodes);
            }
            catch (Exception ex)
            {
                LogHandler.WriteSystemLog("DownloadFeedList: " + ex, LogLevel.Error);
                return(null);
            }
        }
예제 #4
0
 public FileHandler(FileNameParser fileNameParser)
 {
     _fileNameParser = fileNameParser;
 }