private XCData GetContent(RssEpisodeItems item) { string imgUrl = "http://mums.chsk.se/image/episode/" + item.RssEpisodeItemId; string html = string.Format( "<a href=\"{0}\"><img src=\"{0}\" alt=\"{1}\" /></a><p>Tillagd {2:dddd\\e\\n \\d\\e\\n d MMMM, HH:mm}</p>", imgUrl, item.ShowName + " (id:" + item.RssEpisodeItemId + ")", item.Added ); return(new XCData(html)); }
private static void ProcessEpisode(MumsDataContext ctx, ParsedEpisode item, bool skip = false) { var split = item.ShowName.Trim() .Split(new char[] { ' ', '[', ']' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Replace('"', ' ')); var matches = ctx.ExecuteStoreQuery <RssEpisodeItems>( "SELECT * FROM RssEpisodeItems WHERE Season={0} AND Episode={1} AND (ReleaseName={2} OR EnclosureUrl={3} OR FREETEXT(ReleaseName, {4}))", item.Season, item.Episode, item.ReleaseName, item.TorrentUrl.ToString(), string.Join(" AND ", split) ).AsQueryable(); var entity = new RssEpisodeItems { Episode = item.Episode, Season = item.Season, ReleaseName = item.ReleaseName, PubDate = item.PubDate, Added = DateTime.Now, EnclosureUrl = item.TorrentUrl.ToString(), EnclosureLength = item.TorrentSize, SourceUrl = item.SourceUrl.ToString(), ShowName = item.ShowName.Replace('.', ' ').Trim() }; var duplicate = matches.FirstOrDefault(); if (duplicate != null) { // I am only interested in adding an item if there is no item with that releasename yet. // This is because the more duplicates of the same episode with different releasenames there are, // the greater the chance of identifying another duplicate. bool exists = ctx.RssEpisodeItems.Any(i => i.ReleaseName == entity.ReleaseName); Logging.PrintDuplicate(entity.ReleaseName); if (exists) { return; } entity.DuplicateOf = duplicate.RssEpisodeItemId; Duplicates++; } else { Logging.PrintDownloaded(entity.ReleaseName); Downloads++; entity.Download = true; } if (skip) { entity.Download = false; } ctx.RssEpisodeItems.AddObject(entity); ctx.SaveChanges(); if (entity.Download) { Thread.Sleep(180 * 1000); // wait for the full-text index to refresh (180 seconds) } }