/// <summary> /// Adds the specified feed item. /// </summary> /// <param name="feedItem">The feed item.</param> public void Add(FeedItem feedItem) { if (feedItem.GUID == null) { feedItem.GUID = System.Guid.NewGuid().ToString(); } bool boolFound = false; foreach (FeedItem f in List) { if (f.Url == feedItem.Url) { boolFound = true; break; } } if (boolFound == false) { List.Add(feedItem); //Settings.Default.Save(); } //List.Add(feedItem); }
public SpecificEpisodesForm(FeedItem feedItem) { InitializeComponent(); this.feedItem = feedItem; FillPosts(feedItem); }
/// <summary> /// Gets the RSS feed. /// </summary> /// <param name="feedItem">The feed item.</param> /// <returns></returns> public static Rss.RssFeed GetFeed(FeedItem feedItem, bool OnlyCache) { Rss.RssFeed rssFeed = null; Rss.RssFeed rssExistingFeed = null; if (feedItem.FeedHashCode != "" && feedItem.FeedHashCode != null && File.Exists(DataFolder + "\\" + feedItem.FeedHashCode + ".bin")) { try { //XmlSerializer ser = new XmlSerializer(typeof(Rss.RssFeed)); BinaryFormatter ser = new BinaryFormatter(); FileStream stream = File.Open(DataFolder + "\\" + feedItem.FeedHashCode + ".bin", FileMode.Open, FileAccess.Read); rssExistingFeed = (Rss.RssFeed)ser.Deserialize(stream); stream.Close(); if (OnlyCache == false) { if (feedItem.Authenticate == true) { rssFeed = Rss.RssFeed.Read(rssExistingFeed, feedItem.Username, feedItem.Password); } else { rssFeed = Rss.RssFeed.Read(rssExistingFeed); } SerializeFeed(rssFeed); } else { rssFeed = rssExistingFeed; } } catch { // something went wrong try { if (feedItem.Authenticate == true) { rssFeed = Rss.RssFeed.Read(feedItem.Url, feedItem.Username, feedItem.Password); } else { rssFeed = Rss.RssFeed.Read(feedItem.Url); } } catch (ApplicationException ex) { if (Settings.Default.LogLevel > 0) { log.Error("GetFeed", ex); } } SerializeFeed(rssFeed); } } else { try { rssFeed = Rss.RssFeed.Read(feedItem.Url); SerializeFeed(rssFeed); } catch (ApplicationException ex) { if (Settings.Default.LogLevel > 0) { log.Error("GetFeed", ex); } } try { if (rssFeed != null && !File.Exists(Path.Combine(Utils.DataFolder, rssFeed.GetHashCode().ToString("X") + ".ico"))) { GetFavIcon(new Uri(rssFeed.Channels[0].Link), rssFeed.GetHashCode().ToString("X")); } } catch { } try { if (rssFeed != null && !File.Exists(Path.Combine(Utils.DataFolder, rssFeed.GetHashCode().ToString("X") + ".jpg"))) { GetFeedImage(new Uri(rssFeed.Channels[0].Image.Url), rssFeed.GetHashCode().ToString("X")); } } catch { } } if (rssFeed != null) { Settings.Default.Feeds[feedItem].FeedHashCode = rssFeed.GetHashCode().ToString("X"); } return(rssFeed); }
public static Rss.RssFeed GetFeed(FeedItem feedItem) { return(GetFeed(feedItem, false)); }
/// <summary> /// Applies the space savers. /// </summary> /// <param name="feedItem">The feed item.</param> public void ApplySpaceSavers(FeedItem feedItem) { //Settings set = new Settings(); string strDownloadlocation; string strPlaylistName; if (feedItem.PlaylistName != "") { strPlaylistName = feedItem.PlaylistName; } else { strPlaylistName = feedItem.Title; } strDownloadlocation = Settings.Default.DownloadLocation + "\\" + GetValidFolderPath(feedItem.Title); // spacesavers? try { if (feedItem.UseSpaceSavers) { if (feedItem.Spacesaver_Size > 0) { #region spacesaver_maxMb code // apply the max Mb spacesaver // check the size of the folder System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(strDownloadlocation); System.IO.FileInfo[] fileInfo = dirInfo.GetFiles(); long longTotalSize = 0; foreach (System.IO.FileInfo fileInfoItem in fileInfo) { longTotalSize += fileInfoItem.Length; } while ((longTotalSize / 1024 / 1024) > Convert.ToInt64(feedItem.Spacesaver_Files)) { // folder grew to big System.IO.FileInfo oldestFile = null; foreach (System.IO.FileInfo fileInfoItem in fileInfo) { if (oldestFile == null) { oldestFile = fileInfoItem; } else { if (oldestFile.CreationTime > fileInfoItem.CreationTime) { oldestFile = fileInfoItem; } } } if (oldestFile != null) { // remove the oldest file //retr.RemoveFromPlaylist(strPlaylistName, oldestFile.FullName); System.IO.File.Delete(oldestFile.FullName); } fileInfo = dirInfo.GetFiles(); longTotalSize = 0; foreach (System.IO.FileInfo fileInfoItem in fileInfo) { longTotalSize += fileInfoItem.Length; } } #endregion } if (feedItem.Spacesaver_Files > 0) { #region spacesaver_maxFiles code System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(strDownloadlocation); System.IO.FileInfo[] fileInfo = dirInfo.GetFiles(); while (fileInfo.Length > feedItem.Spacesaver_Files) { // folder grew to big System.IO.FileInfo oldestFile = null; foreach (System.IO.FileInfo fileInfoItem in fileInfo) { if (oldestFile == null) { oldestFile = fileInfoItem; } else { if (oldestFile.CreationTime > fileInfoItem.CreationTime) { oldestFile = fileInfoItem; } } } if (oldestFile != null) { // remove the oldest file //retr.RemoveFromPlaylist(strPlaylistName, oldestFile.FullName); System.IO.File.Delete(oldestFile.FullName); } fileInfo = dirInfo.GetFiles(); } #endregion } if (feedItem.Spacesaver_Days > 0) { #region spacesaver_ageDays code System.DateTime dateNow = DateTime.Now; System.IO.DirectoryInfo dirInfo = new System.IO.DirectoryInfo(strDownloadlocation); System.IO.FileInfo[] fileInfo = dirInfo.GetFiles(); foreach (System.IO.FileInfo fileInfoItem in fileInfo) { DateTime dateAgo = dateNow.AddDays(-Convert.ToInt16(feedItem.Spacesaver_Days)); DateTime dateFile = fileInfoItem.LastWriteTime; if (dateFile <= dateAgo) { //retr.RemoveFromPlaylist(strPlaylistName, fileInfoItem.FullName); System.IO.File.Delete(fileInfoItem.FullName); } } #endregion } } } catch (Exception) { // log.logMsg(e.Message,true,"Spacesaver"); } }
/// <summary> /// Parses OPML /// </summary> /// <param name="doc"></param> /// <returns>FeedList containing found subscriptions</returns> public static FeedList Parse(XmlDocument doc) { FeedList feedCollection = new FeedList(); XmlNodeList opmlCategories; XmlNodeList opmlEntries; XmlNode body = doc.DocumentElement.SelectSingleNode("body"); opmlCategories = body.SelectNodes("outline[not(@type='rss')]"); if (opmlCategories != null) { foreach (XmlNode category in opmlCategories) { string strCat = category.Attributes["text"].InnerText; opmlEntries = category.SelectNodes("outline[@type='rss']"); foreach (XmlNode opmlEntry in opmlEntries) { FeedItem feedItem = new FeedItem(); string strTitle = ""; if (opmlEntry.Attributes["text"] != null) { strTitle = opmlEntry.Attributes["text"].InnerText; } else { if (opmlEntry.Attributes["title"] != null) { strTitle = opmlEntry.Attributes["title"].InnerText; } else { if (opmlEntry.Attributes["description"] != null) { strTitle = opmlEntry.Attributes["description"].InnerText; } else { strTitle = opmlEntry.Attributes["xmlUrl"].InnerText; } } } feedItem.Title = strTitle; feedItem.Url = opmlEntry.Attributes["xmlUrl"].InnerText; //dopplerFeed.Title = strTitle; //dopplerFeed.LastModified = DateTime.Now; //dopplerFeed.UnRead = -1; //dopplerFeed.Url = opmlEntry.Attributes["xmlUrl"].InnerText; feedCollection.Add(feedItem); // feedCollection.Add(dopplerFeed); } } } // check if there are items without categories opmlEntries = body.SelectNodes("outline[@type='rss']"); if (opmlEntries != null) { foreach (XmlNode opmlEntry in opmlEntries) { FeedItem dopplerFeed = new FeedItem(); string strTitle = ""; if (opmlEntry.Attributes["text"] != null) { strTitle = opmlEntry.Attributes["text"].InnerText; } else { if (opmlEntry.Attributes["title"] != null) { strTitle = opmlEntry.Attributes["title"].InnerText; } else { if (opmlEntry.Attributes["description"] != null) { strTitle = opmlEntry.Attributes["description"].InnerText; } else { strTitle = opmlEntry.Attributes["xmlUrl"].InnerText; } } } dopplerFeed.Title = strTitle; dopplerFeed.Url = opmlEntry.Attributes["xmlUrl"].InnerText; feedCollection.Add(dopplerFeed); } } return(feedCollection); }
private DownloadPackage GetDownloadPackage(Rss.RssItem rssItem, FeedItem feedItem, string strDownloadlocation) { bool boolAcceptableFile = false; bool byteRanging = true; string strFilenameWithoutExt = null; string strFilenameExt = null; string strPath = null; DirectoryInfo dirInfo = null; FileInfo[] fileInfo = null; long longReturn = 0; //bool boolGuid = false; string strFilename = null; // new WebResponse response = null; // first try a HEAD call (less intrusive) if (feedItem.Authenticate == true) { string strPassword = EncDec.Decrypt(feedItem.Password, feedItem.Username); response = GetWebResponseObjectHEAD(rssItem.Enclosure.Url, feedItem.Username, strPassword); } else { response = GetWebResponseObjectHEAD(rssItem.Enclosure.Url, "", ""); } // the HEAD call didn't seem to work. We'll use a GET now if (response == null) { if (feedItem.Authenticate == true) { string strPassword = EncDec.Decrypt(feedItem.Password, feedItem.Username); response = GetWebResponseObjectGET(rssItem.Enclosure.Url, feedItem.Username, strPassword); } else { response = GetWebResponseObjectGET(rssItem.Enclosure.Url, "", ""); } } if (response != null) { long longDownloadsize = response.ContentLength; if (longDownloadsize == -1) { longDownloadsize = 1; } WebHeaderCollection responseHeaders = response.Headers; string[] strAcceptRange = responseHeaders.GetValues("Accept-Ranges"); if (strAcceptRange != null && strAcceptRange[0] == "none") { // no byte ranging byteRanging = false; } // check if there is content-disposition header string[] strContDisp = responseHeaders.GetValues("content-disposition"); string strAttachment = ""; string strHeader = ""; if (strContDisp != null && strContDisp.Length > 0) { for (int l = 0; l < strContDisp.Length; l++) { strHeader = strContDisp[l]; if (strHeader.ToLower().StartsWith("attachment")) { // attachment header strAttachment = strHeader.Substring(strHeader.ToLower().IndexOf("filename=") + 9); } } } if (strAttachment != "") { if (feedItem.UseTitleForFiles) { FileInfo f = new FileInfo(strAttachment); strPath = Utils.GetValidFileName(rssItem.Title + f.Extension); } else { strPath = strAttachment; strPath = Utils.GetValidFileName(strPath); } strFilename = strDownloadlocation + "\\" + strPath; if (strFilename.IndexOf(".") > 0) { FileInfo f = new FileInfo(strFilename); strFilenameWithoutExt = f.FullName.Substring(0, f.FullName.Length - f.Extension.Length); //strFilenameWithoutExt = strFilename.Substring(0, strFilename.LastIndexOf(".")); strFilenameExt = f.Extension.Substring(1); //strFilenameExt = strFilename.Substring(strFilename.LastIndexOf(".") + 1); } else { strFilenameWithoutExt = strFilename; strFilenameExt = ""; } } else { try { Uri uriEnclosure = new Uri(rssItem.Enclosure.Url); string strEnclosureUrl = uriEnclosure.GetLeftPart(UriPartial.Path); if (feedItem.UseTitleForFiles) { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); FileInfo f = new FileInfo(strPath); strPath = Utils.GetValidFileName(rssItem.Title + f.Extension); } else { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); } if (strPath == "") { // check the query strEnclosureUrl = uriEnclosure.GetLeftPart(UriPartial.Query); if (feedItem.UseTitleForFiles) { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); FileInfo f = new FileInfo(strPath); strPath = Utils.GetValidFileName(rssItem.Title + f.Extension); } else { strPath = strEnclosureUrl.Substring(strEnclosureUrl.LastIndexOf("/") + 1); } } // empty path? not good. Generate one //strPath = System.Web.HttpUtility.UrlDecode(strPath); strFilename = strDownloadlocation + "\\" + strPath; FileInfo fileInfo1 = new FileInfo(strFilename); strFilenameWithoutExt = fileInfo1.FullName.Substring(0, fileInfo1.FullName.Length - fileInfo1.Extension.Length); //strFilenameWithoutExt = strFilename.Substring(0, strFilename.LastIndexOf(".")); strFilenameExt = fileInfo1.Extension.Substring(1); //strFilenameExt = strFilename.Substring(strFilename.LastIndexOf(".") + 1); //strFilenameWithoutExt = strFilename.Substring(0, strFilename.LastIndexOf(".")); //strFilenameExt = strFilename.Substring(strFilename.LastIndexOf(".") + 1); } catch { strFilename = ""; strFilenameExt = ""; strFilenameWithoutExt = ""; boolAcceptableFile = false; } } if (Settings.Default.DefaultMediaAction == 0) { boolAcceptableFile = true; } else { foreach (string extension in Utils.AudioExtensions) { if (extension.ToUpper() == strFilenameExt.ToUpper()) { boolAcceptableFile = true; break; } } if (!boolAcceptableFile) { // check if it is a video file foreach (string extension in Utils.VideoExtensions) { if (extension.ToUpper() == strFilenameExt.ToUpper()) { boolAcceptableFile = true; break; } } } } if (boolAcceptableFile) { try { dirInfo = new System.IO.DirectoryInfo(strDownloadlocation); fileInfo = dirInfo.GetFiles(strPath); } catch (Exception fex) { if (Settings.Default.LogLevel > 0) { log.Error("Retriever", fex); } strFilenameExt = ""; } // check if the file is available on the filesystem bool boolContinue = true; if (fileInfo.Length > 0) { if ((fileInfo.Length > 0 && fileInfo[0].Length != longDownloadsize)) { // there is a file with the same name switch (Settings.Default.DuplicateAction) { case 1: strFilename = strFilenameWithoutExt + DateTime.Now.ToString("yyyyMMddTHHMMss") + "." + strFilenameExt; boolContinue = true; break; default: boolContinue = false; break; } } else if (fileInfo.Length > 0) { // add the item to the history HistoryItem historyItem = new HistoryItem(); historyItem.FeedGUID = feedItem.GUID; historyItem.FeedUrl = feedItem.Url; historyItem.Title = rssItem.Title; historyItem.Hashcode = rssItem.GetHashCode(); //historyItem.LocalFilename = fileInfo[0].FullName; historyItem.ItemDate = fileInfo[0].CreationTime.ToString("yyyy-MM-dd HH:MM:ss"); historyItem.FileName = fileInfo[0].Name; //historyItem.URL = enc.EnclosureURL; Settings.Default.History.Add(historyItem); boolContinue = false; } else { boolContinue = false; } } if (boolContinue) { // did the user specify a text filter on the item? if (feedItem.Textfilter != null && feedItem.Textfilter != "") { System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(feedItem.Textfilter); if (regEx.Match(rssItem.Description).Success || regEx.Match(rssItem.Title).Success) { // if(rssItem.Description.ToUpper().IndexOf(feedItem.textFilter.ToUpper()) >= 0 || rssItem.Title.ToUpper().IndexOf(feedItem.textFilter.ToUpper()) >= 0) // { longReturn = longDownloadsize; } else if (rssItem.Description.ToUpper().IndexOf(feedItem.Textfilter.ToUpper()) >= 0 || rssItem.Title.ToUpper().IndexOf(feedItem.Textfilter.ToUpper()) >= 0) { longReturn = longDownloadsize; } } else { longReturn = longDownloadsize; } } } } DownloadPackage downloadPackage = new DownloadPackage(); downloadPackage.ByteRanging = byteRanging; downloadPackage.DownloadSize = longReturn; downloadPackage.strFilename = strFilename; return(downloadPackage); }
private void ParseRss(FeedItem feedItem, string strDownloadlocation) { log4net.NDC.Push("ParseRss"); try { //RssReader rssReader = new RssReader(feedItem,false,null); //rssReader.RdfMode = false; if (SetFeedStatus != null) { SetFeedStatus(lvi, 1, feedItem.Pubdate, FormStrings.RetrievingRSS); } //RssFeed feed = rssReader.Retrieve(); try { Rss.RssFeed feed = Utils.GetFeed(feedItem); if (feed != null) { // first clean up the history CleanHistory(feedItem, feed); // set the description of the feed //if ( feed.ErrorMessage == null || feed.ErrorMessage == "" ) //{ if (feed.Exceptions.Count == 0) { //RssItems items = feed.Items; //int intItems = items.Count; int intItemCount = 0; //for(int q=0;q<intItems;q++) //{ feed.Channels[0].Items.Sort(); foreach (Rss.RssItem rssItem in feed.Channels[0].Items) { if (SetFeedStatus != null) { SetFeedStatus(lvi, 1, feedItem.Pubdate, "Parsing items"); } //hist.ReRead(); //Application.DoEvents(); //RssItem rssItem = items[q]; #region // Default : Enclosures //if(rssItem.Enclosures != null) //{ if (rssItem.Enclosure != null) { if (intItemCount < feedItem.RetrieveNumberOfFiles || feedItem.RetrieveNumberOfFiles == 0) { intItemCount++; // EnclosureItem enc = rssItem.Enclosures[y]; bool validUri = false; System.Uri uri = null; try { uri = new Uri(rssItem.Enclosure.Url); validUri = true; } catch (UriFormatException ex) { boolError = true; if (Settings.Default.LogLevel > 0) { log.Error(String.Format("Invalid enclosure url for {0} ({1})", feedItem.Title, rssItem.Enclosure.Url), ex); } } if (validUri) { // check if the enclosure is already in the history if (Settings.Default.History[rssItem.GetHashCode().ToString()] == null) { string strPath = GetValidFilename(uri.LocalPath.Substring(uri.LocalPath.LastIndexOf("/") + 1)); string strFilename = Path.Combine(strDownloadlocation, strPath); if (!Directory.Exists(strDownloadlocation)) { try { Directory.CreateDirectory(strDownloadlocation); } catch (DirectoryNotFoundException ex) { if (Settings.Default.LogLevel > 1) { log.Error("Error creating directory", ex); } boolError = true; return; } } DownloadPackage downloadPackage = GetDownloadPackage(rssItem, feedItem, strDownloadlocation); long longDownloadsize = downloadPackage.DownloadSize; if (downloadPackage.strFilename != null) { strFilename = downloadPackage.strFilename; } if (longDownloadsize > 0) { if (feedItem.Authenticate == true) { string strPassword = EncDec.Decrypt(feedItem.Password, feedItem.Username); FileFound(feedItem, rssItem.Enclosure.Url, longDownloadsize, downloadPackage.strFilename, rssItem, downloadPackage.ByteRanging); } else { FileFound(feedItem, rssItem.Enclosure.Url, longDownloadsize, downloadPackage.strFilename, rssItem, downloadPackage.ByteRanging); } } // update the FeedItem with an last update date and the description feedItem.Pubdate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (feed.Channels[0].Description != null) { feedItem.Description = feed.Channels[0].Description; } Settings.Default.Feeds[feedItem.GUID] = feedItem; } } } } #endregion } } } } catch (WebException wex) { if (Settings.Default.LogLevel > 0) { log.Error("Retriever", wex); } } } catch (ThreadAbortException) { //MessageBox.Show("TA"); } log4net.NDC.Pop(); }
private void FinishButton_Click(object sender, EventArgs e) { Settings.Default.ShowAdvancedFeedDialog = ShowAdvancedCheckBox.Checked; _feedItem.Url = UrlTextBox.Text; _showAdvancedDialog = ShowAdvancedCheckBox.Checked; _feedItem.Authenticate = LoginCheckBox.Checked; if (LoginCheckBox.Checked) { _feedItem.Username = UsernameTextBox.Text; _feedItem.Password = PasswordTextBox.Text; } try { Cursor.Current = Cursors.WaitCursor; Rss.RssFeed feed = Utils.GetFeed(_feedItem); if (feed.Exceptions.Count == 0) { char[] trimChars = new char[4]; trimChars[0] = ' '; trimChars[1] = '\n'; trimChars[2] = '\r'; trimChars[3] = '\t'; string strTitle = feed.Channels[0].Title.Trim(trimChars); int intCounter = 1; while (IsTitleUnique(strTitle, _feedItem.GUID) == false) { strTitle = feed.Channels[0].Title.Trim(trimChars) + " (" + intCounter.ToString() + ")"; intCounter++; } _feedItem.Title = feed.Channels[0].Title.Trim(trimChars); _feedItem.FeedHashCode = feed.GetHashCode().ToString("X"); if (feed.Channels[0].Description != null) { _feedItem.Description = feed.Channels[0].Description; } Settings.Default.Feeds.Add(_feedItem); } else { MessageBox.Show(FormStrings.NotAValidFeedCheckTheLogForMoreInformation, FormStrings.ErrorAddingFeed, MessageBoxButtons.OK, MessageBoxIcon.Error); _feedItem = null; if (Settings.Default.LogLevel > 0) { log.Error("Add feed", feed.Exceptions.LastException); } } Cursor.Current = Cursors.Default; } catch (Exception ex) { MessageBox.Show(FormStrings.NotAValidFeedCheckTheLogForMoreInformation, FormStrings.ErrorAddingFeed, MessageBoxButtons.OK, MessageBoxIcon.Error); if (Settings.Default.LogLevel > 0) { log.Error("Add feed", ex); } _feedItem = null; Cursor.Current = Cursors.Default; } }
public CatchupForm() { InitializeComponent(); this.feedItem = null; }
private void setItem(int Index, FeedItem Item) { List[Index] = Item; }
public FeedItem[] ToArray() { FeedItem[] items = new FeedItem[List.Count]; List.CopyTo(items, 0); return(items); }