protected override AbstractSource DoCreateNewSource(string name, string url, List <MetaDataObject> templateAndValues) { string value; int tmp; MetaDataObject source = MetaDataObject.FindIn(templateAndValues, SmackProvider.META_SOURCE); value = source.GetValueAsString(); if (String.IsNullOrEmpty(value)) { throw new Exception("No source selected"); } AbstractSource s = new SmackSource(value); MetaDataObject pages = MetaDataObject.FindIn(templateAndValues, SmackProvider.META_PAGES); value = pages.GetValueAsString(); if (String.IsNullOrEmpty(value)) { tmp = DefaultPages; } else { int.TryParse(value, out tmp); } pages.SetValue(tmp); s.SetMetaData(templateAndValues); return(s); }
private List <AbstractItem> GetNewItems(SmackSource source) { string BaseUrl; string Selector; if (source.Source == SourceNames.ChinaSmack.ToString()) { BaseUrl = ChinaBase; Selector = ChinaSelect; } else if (source.Source == SourceNames.JapanCrush.ToString()) { BaseUrl = JapanBase; Selector = JapanSelect; } else { throw new Exception(source + "not accepted"); } List <AbstractItem> items = new List <AbstractItem>(); WebClient wc = new WebClient(); int max = Convert.ToInt32(source.Pages); for (int p = 1; p <= max; p++) { string url = BaseUrl + p; string page; page = wc.DownloadString(url); HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(page); var itemNodes = doc.DocumentNode.SelectNodes(Selector); foreach (var a in itemNodes) { try { string name = WebUtility.HtmlDecode(a.InnerText); string link = a.Attributes["href"].Value; var post = new Post(source, name, link); items.Add(post); } catch (Exception e) { } } } return(items); }
internal static SmackSource CreateFrom(AbstractSource source) { if (source is SmackSource) { return((SmackSource)source); } SmackSource js = new SmackSource(source.SourceName); js.SetMetaData(source.GetMetaData()); js.SetID(source.ID.Value); return(js); }
protected override List <AbstractItem> GetNewItems(AbstractSource source) { SmackSource js = SmackSource.CreateFrom(source); return(GetNewItems(js)); }
public override AbstractSource CastSource(GenericSource src) { return(SmackSource.CreateFrom(src)); }