1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using System;
- using System.Collections.Generic;
- using BanTur.Cli.Entity;
- using CodeHollow.FeedReader;
- using CodeHollow.FeedReader.Feeds;
- namespace BanTur.Rss
- {
- public static class RssParser
- {
- public static T[] Parse<T>(string xml) where T : IBangumiEntry, new()
- {
- var doc = FeedReader.ReadFromString(xml);
- var isFeed20 = doc.Type == FeedType.Rss_2_0;
- var list = new List<T>();
- foreach (var item in doc.Items)
- {
- string magnet = null;
- if (isFeed20)
- {
- var rss20 = (Rss20FeedItem)item.SpecificItem;
- if (rss20.Enclosure?.MediaType == "application/x-bittorrent") magnet = rss20.Enclosure.Url;
- }
- if (magnet == null) continue;
- var entry = new T
- {
- FetchDate = DateTime.Now,
- PubDate = item.PublishingDate,
- Magnet = magnet,
- Title = item.Title,
- Url = item.Link,
- };
- list.Add(entry);
- }
- return list.ToArray();
- }
- }
- }
|