void p_Old(Feed feed, XDocument feedXML) { lock (thisLock) { try { RssDnldInfos.Clear(); var errMsgs = " "; if (feedXML == null) { feed.LastAvailCastCount = -7; Debug.WriteLine( $"Unable to get data from {feed.Url}:\n{System.Reflection.MethodInfo.GetCurrentMethod().DeclaringType.Name}\n{System.Reflection.MethodInfo.GetCurrentMethod().Name}\a"); } else { var podcastSyndItems = from cast in feedXML.Descendants("item") select cast; feed.LastAvailCastCount = podcastSyndItems.Count(); feed.LastCastAt = DateTime.Today.AddYears(-10); var neverRanYet = true; foreach (var si in podcastSyndItems) { //Debug.WriteLine(string.Format("\n{0}\n", feed)); if (si.Element("pubDate") == null) { var msg = $"No \"pubDate\" element \n in podcast: \t {(si.Element("title") != null ? si.Element("title").Value : "")} \n from feed: \t {feed.Name} \n feed url: \t {feed.Url}"; Debug.WriteLine(msg); errMsgs += msg; // if (showMessages) showMessages = (MessageBox.Show(msg, "Continue showing these messages?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes); continue; } var pubDate = MiscHelper.GetDateFromAnyFormatString(si.Element("pubDate").Value); if (feed.LastCastAt < pubDate) { feed.LastCastAt = pubDate; } var enclosure = MiscHelper.gerRightEleName(si); if (enclosure == "" || si.Element(enclosure).Attribute("url") == null || si.Element(enclosure).Attribute("length") == null) { if ((DateTime.Now - pubDate).TotalDays > feed.AcptblAgeDay || pubDate < feed.IgnoreBefore) { continue;//ignore old errors } else { var msg = $"No \"enclosure\" element \n in podcast: \t {(si.Element("title") != null ? si.Element("title").Value : "")} \n published: \t {pubDate} \n from feed: \t {feed.Name} \n feed url: \t {feed.Url}"; Debug.WriteLine(msg); Clipboard.SetText(feed.Url); if (neverRanYet) { neverRanYet = false; Process.Start(new ProcessStartInfo(feed.Url)); } else { Debug.WriteLine("::>>Second try."); } errMsgs += msg; // if (showMessages) showMessages = (MessageBox.Show(msg, "Continue showing these messages?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes); continue; } } var castTitle = si.Element("title") == null ? "NoTitle" : si.Element("title").Value.Replace("\n", " ").Trim(); var castUrl = si.Element(enclosure).Attribute("url").Value; long castLen = -1; long.TryParse(si.Element(enclosure).Attribute("length").Value, out castLen); var fnm = MiscHelper.GetSmartPathFileName(castUrl, pubDate, feed.Tla, feed.SubFolderEx, feed.IsTitleInFilename ? castTitle : null, feed.IsNewerFirst); RssDnldInfos.Add(new RssDnldInfo { CastTitle = castTitle, Published = pubDate, OrgSrcUrl = castUrl, AltSrcUrl = "", OrignLink = "", CastSumry = "old rss parser (xml-based)", TtlMinuts = 44.444, CastFileLen = castLen, CasFilename = fnm }); // saveToDnldRow_IsNewAdded(_db, feed, castTitle, pubDate, castUrl, "altSrcUrl", "origLink_", "summary__", 44.444, castLen, fnm); } } // foreach (var pCast in availablePodcasts) } catch (Exception ex) { ex.Log(); throw; } } }
void doSyndItem(Feed feed, SyndicationItem si) { //Debug.WriteLine(" Pub Date \t Title: \t{0} \t\t {1} ", si.PublishDate, si.Title.Text); try { string preSrcUrl = null, fileSize = null; var content = si.ElementExtensions.FirstOrDefault(r => r.OuterName == "content"); if (content != null) { RssHelper.getFromContent(content, ref preSrcUrl, ref fileSize); } var orgSrcUrl = preSrcUrl ?? si.Id; var altSrcUrl = RssHelper.tryGetStrVal(si, "origEnclosureLink") ?? ""; var orignLink = RssHelper.tryGetStrVal(si, "origLink") ?? ""; var duration_ = RssHelper.tryGetStrVal(si, "duration") ?? "44.4"; var summary_0 = RssHelper.tryGetStrVal(si, "summary") ?? si.Summary.Text; var castSumry = summary_0.Length < 1000 ? summary_0 : summary_0.Substring(0, 1000); //if (altSrcUrl != "") orgSrcUrl = altSrcUrl; //for DNR - much faster src... actually, not really. //foreach (SyndicationElementExtension see in si.ElementExtensions) { var xe = see.GetObject<XElement>(); Debug.WriteLine(" xEl = name/value: {0,-64}= {1}", xe.Name, xe.Value); foreach (var atr in xe.Attributes()) Debug.WriteLine(" atr - {0,-64} - {1}", atr.Name, atr.Value); } var ts = TimeSpan.FromMinutes(44); if (duration_.Contains(':')) { TimeSpan.TryParse(duration_, out ts); } else if (double.TryParse(duration_, out var durSec)) { ts = TimeSpan.FromSeconds(durSec); } var enclosure = si.Links.FirstOrDefault(r => r.RelationshipType == "enclosure"); var fileLen = fileSize != null?Convert.ToInt64(fileSize) : enclosure != null ? enclosure.Length : 0; if (fileLen < 150000 && feed.Name.Contains("CBC")) //cbc seems to be using kb. { fileLen *= 1024; } var prefix = feed.Tla; if (!isMedia(orgSrcUrl)) { if (enclosure != null && Path.GetExtension(enclosure.Uri.ToString()).Length != 0) { orgSrcUrl = enclosure.Uri.ToString(); } else { prefix = "Non-Media\\"; } } if (orgSrcUrl.EndsWith("/")) { return; } var castTitle = UnicodeBuster(si.Title.Text).Replace("\n", " ").Trim(); var fileName = MiscHelper.GetSmartPathFileName(orgSrcUrl, si.PublishDate.Date, prefix, feed.SubFolderEx, feed.IsTitleInFilename ? castTitle : null, feed.IsNewerFirst); RssDnldInfos.Add(new RssDnldInfo { CastTitle = castTitle, Published = si.PublishDate.Date > DateTime.Today.AddYears(-100) ? si.PublishDate.Date : DateTime.Today.AddYears(-100), OrgSrcUrl = orgSrcUrl, AltSrcUrl = altSrcUrl, OrignLink = orignLink, CastSumry = UnicodeBuster(castSumry), TtlMinuts = ts.TotalMinutes, CastFileLen = fileLen, CasFilename = fileName }); // var isNewDlRowAdded = saveToDnldRow_IsNewAdded(_db, feed, si.Title.Text.Replace("\n", " ").Trim(), si.PublishDate.Date, orgSrcUrl_, altSrcUrl, origLink_, summary__, ts.TotalMinutes, fileLen, fnm); } catch (Exception ex) { ex.Log(); } }