예제 #1
0
        private ActionResult HandleAuthenticatedUser(string authenticatedToken)
        {
            using (var ctx = new MumsDataContext())
            {
                var user = ctx.User.SingleOrDefault(u => u.Token == authenticatedToken);
                if (user == null)
                {
                    TempData.Add("NotFound", authenticatedToken);
                    return RedirectToAction(MVC.Account.LogOn());
                }

                CurrentSession.User = user;
            }

            var expiration = DateTime.Now.Date.AddDays(365);
            int timeoutMinutes = (int)(expiration - DateTime.Now).TotalMinutes;
            var ticket = new FormsAuthenticationTicket(authenticatedToken, true, timeoutMinutes);

            string ticketString = FormsAuthentication.Encrypt(ticket);
            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, ticketString)
            {
                Expires = expiration
            };

            FormsAuthentication.SetAuthCookie(authenticatedToken, true);

            HttpContext.Response.Cookies.Add(cookie);

            return RedirectToAction(MVC.Root.Index());
        }
예제 #2
0
 public static List<RssEpisodeItems> GetItems(int limit = 100)
 {
     using (var ctx = new MumsDataContext())
     {
         return ctx.RssEpisodeItems
             .Where(e => e.Download)
             .OrderByDescending(e => e.Added)
             .Take(limit)
             .ToList();
     }
 }
예제 #3
0
파일: Program.cs 프로젝트: jcbarton/MUMS
        static void Main(string[] args)
        {
            var items = ItemExtracter.GetItems();
            items.Shuffle();

            var currentMaxDate = DateTime.MinValue;
            Match match;

            int skipped = 0;
            int processed = 0;

            bool skipDate = false;
            if (args != null && args.Contains("/skip"))
                skipDate = true;

            using (var ctx = new MumsDataContext())
            {
                if (ctx.RssEpisodeItems.Any())
                {
                    currentMaxDate = ctx.RssEpisodeItems.Max(e => e.PubDate).Date;
                }

                foreach (ParsedEpisode item in items)
                {
                    bool skip = false;
                    if (skipDate && item.PubDate < currentMaxDate)
                    {
                        skip = true;
                        skipped++;
                        Logging.PrintDateSkipped(item.ShowName);
                    }

                    if (SetSeasonAndEpisode(item))
                    {
                        ProcessEpisode(ctx, item, skip);
                        processed++;
                    }
                    else
                    {
                        Logging.PrintInvalid("Pattern match failed: " + item.ShowName);
                    }
                }
            }

            Logging.PrintNewline();
            Logging.PrintStatus(ConsoleColor.DarkGreen, "# Item count", items.Count.ToString());
            Logging.PrintStatus(ConsoleColor.DarkGreen, "# Downloads", Downloads.ToString());
            Logging.PrintStatus(ConsoleColor.DarkGreen, "# Duplicates", processed.ToString());
            Logging.PrintStatus(ConsoleColor.DarkGreen, "# DateSkips", skipped.ToString());

            Logging.End();
        }
예제 #4
0
        public virtual ActionResult Episode(int id)
        {
            using (var ctx = new MumsDataContext())
            {
                var data = ctx.RssEpisodeItems.Where(e => e.RssEpisodeItemId == id).Select(e => new
                {
                    e.ShowName,
                    e.Season,
                    e.Episode
                }).SingleOrDefault();

                if (data == null)
                    return new EmptyResult();

                return TvShow(data.ShowName, data.Season, data.Episode);
            }
        }
예제 #5
0
        public virtual ActionResult GetEpisodes()
        {
            try
            {
                var model = new PollEpisodesModel();

                using (var ctx = new MumsDataContext())
                {
                    DateTime now = DateTime.Now;

                    var items = FeedController.GetItems(6);

                    model.LatestEpisodes = items.Select(e => new RssEpisodeModel
                    {
                        Name = e.ReleaseName.Trim(),
                        SecondsSinceAdded = (int)(now - e.Added).TotalSeconds,
                        Id = e.RssEpisodeItemId.ToString(),
                        ImageUrl = Url.Action(MVC.Image.Episode(e.RssEpisodeItemId)),
                        ShowName = e.ShowName,
                        Season = e.Season,
                        Episode = e.Episode
                    }).ToList();
                }

                return JsonContract(model);
            }
            catch (Exception ex)
            {
                return JsonContract(new TorrentResult { Ok = false, ErrorMessage = ex.Message });
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: jcbarton/MUMS
        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)
        }