Exemplo n.º 1
0
        private static bool SetSeasonAndEpisode(ParsedEpisode item)
        {
            Match match = regex1.Match(item.ReleaseName);

            if (match.Success)
            {
                SetSeasonAndEpisode(item, match, 1, 3);
                return(true);
            }

            match = regex2.Match(item.ReleaseName);
            if (match.Success)
            {
                SetSeasonAndEpisode(item, match, 1, 3);
                return(true);
            }

            match = regex3.Match(item.ReleaseName);
            if (match.Success)
            {
                SetSeasonAndEpisode(item, match, 1, 2);
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        private static bool TryParseItem(XElement item, out ParsedEpisode episode)
        {
            episode = null;
            Uri torrentUrl;

            XElement enclosure = item.Element("enclosure");
            string   link      = enclosure.Attribute("url").Value;

            if (!Uri.TryCreate(link, UriKind.RelativeOrAbsolute, out torrentUrl))
            {
                Logging.PrintInvalid("Invalid torrent url\t" + link);
                return(false);
            }

            long length;

            if (!long.TryParse(enclosure.Attribute("length").Value, out length))
            {
                Logging.PrintInvalid("Invalid torrent size\t" + enclosure.Attribute("length"));
                return(false);
            }

            Uri sourceUrl;

            Uri.TryCreate(item.Element("link").Value, UriKind.RelativeOrAbsolute, out sourceUrl);

            episode = new ParsedEpisode
            {
                ReleaseName = (item.Element("title").Value ?? string.Empty).Trim(),
                PubDate     = DateTime.Parse(item.Element("pubDate").Value),
                TorrentUrl  = torrentUrl,
                TorrentSize = length,
                SourceUrl   = sourceUrl
            };

            return(true);
        }
Exemplo n.º 3
0
        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)
            }
        }
Exemplo n.º 4
0
 private static void SetSeasonAndEpisode(ParsedEpisode item, Match match, int idxSeason, int idxEpisode)
 {
     item.ShowName = item.ReleaseName.Substring(0, match.Groups[0].Index).Trim();
     item.Season   = int.Parse(match.Groups[idxSeason].Value);
     item.Episode  = int.Parse(match.Groups[idxEpisode].Value);
 }
Exemplo n.º 5
0
        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)
        }
Exemplo n.º 6
0
 private static void SetSeasonAndEpisode(ParsedEpisode item, Match match, int idxSeason, int idxEpisode)
 {
     item.ShowName = item.ReleaseName.Substring(0, match.Groups[0].Index).Trim();
     item.Season = int.Parse(match.Groups[idxSeason].Value);
     item.Episode = int.Parse(match.Groups[idxEpisode].Value);
 }
Exemplo n.º 7
0
        private static bool SetSeasonAndEpisode(ParsedEpisode item)
        {
            Match match = regex1.Match(item.ReleaseName);

            if (match.Success)
            {
                SetSeasonAndEpisode(item, match, 1, 3);
                return true;
            }

            match = regex2.Match(item.ReleaseName);
            if (match.Success)
            {
                SetSeasonAndEpisode(item, match, 1, 3);
                return true;
            }

            match = regex3.Match(item.ReleaseName);
            if (match.Success)
            {
                SetSeasonAndEpisode(item, match, 1, 2);
                return true;
            }

            return false;
        }