public VisitorProfile UpdateVisitorProfile(Guid?sessionID, string ip, string url, string language = "") { VisitorProfile vp = null; using (var db = new MovieFinderEntities()) { if (sessionID != null) { vp = db.VisitorProfiles.FirstOrDefault(x => x.ID == sessionID); } if (vp == null) { vp = new VisitorProfile { LastAccessedLanguage = "" }; db.VisitorProfiles.Add(vp); } vp.LastAccessedIP = ip; vp.LastAccessedLanguage = language ?? vp.LastAccessedLanguage; vp.LastAccessedTime = DateTime.Now; vp.LastAccessedUrl = url; vp.HitCount++; db.SaveChanges(); } return(vp); }
public static void RemoveLink(Guid uid, string link) { try { using (var db = new MovieFinderEntities()) { var r = db.AccessLogs.FirstOrDefault(x => x.UniqueID == uid); if (r == null) { return; } var ml = db.MovieLinks.FirstOrDefault(x => x.DowloadUrl == link && x.FailedAttempts <= 3); if (ml != null) { if (MovieTube.Client.Scraper.VideoScraperBase.ValidateUrl(ml.DowloadUrl) == MovieTube.Client.Scraper.ScraperResult.VideoDoesNotExist) { ml.FailedAttempts = 5; ml.LastValidatedBy = uid; db.SaveChanges(); } } } } catch { } }
public static void LogShowAd(Guid uid, string ipAddress, string countryCode, DateTime clientTime, string pcName, string version) { try { using (var db = new MovieFinderEntities()) { var r = db.AccessLogs.FirstOrDefault(x => x.UniqueID == uid); if (r != null) { r.IPAddress = ipAddress; } else { r = new AccessLog { IPAddress = ipAddress, UniqueID = uid }; db.AccessLogs.AddObject(r); } r.PCName = pcName; r.ClientTime = clientTime; r.Timestamp = DateTime.Now; r.CountryCode = countryCode; r.Version = version; r.AccessCount++; db.SaveChanges(); } } catch { } }
private int GetDBVersion() { using (var db = new MovieFinderEntities()) { return db.Movies.DefaultIfEmpty().Max(p => p == null ? 0 : p.Version); } }
public void Run(string imagePath) { using (var db = new MovieFinderEntities()) { while (!IsCancelled) { //var movies = db.Movies // .Where(x => x.ImageUrl != null && x.ImageLocalUrl == null) // .OrderByDescending(x => x.ID) // .Take(100).ToList(); //if (movies.Count == 0) // return; foreach (var m in db.Movies .Where(x => x.ImageUrl != null && x.ImageLocalUrl == null) .OrderByDescending(x => x.ID)) { if (IsCancelled) { return; } if (CopyImageToLocal(m, imagePath)) { db.SaveChanges(); } } } } }
private void Start(List<MovieDetailsScraperBase> scrapers, bool export = false) { this.textBoxMsg.Text = String.Empty; movies.Clear(); EnableDisable(false); var yrs = new List<int>(); for(var i = this.numericUpDown1.Value; i <= 2015; i++) yrs.Add((int)i); NewDBVersion = GetDBVersion() + 1; Task.Factory.StartNew(() => { running = true; try { foreach (var scraper in scrapers) { try { List<string> existing = null; using (var db = new MovieFinderEntities()) { existing = db.MovieLinks.Select(x => x.DowloadUrl).ToList(); } scraper.MovieFound += new EventHandler<MovieFoundEventArgs>(scraper_MovieFound); scraper.ScraperNotFound += new EventHandler<ScraperNotFound>(scraper_ScraperNotFound); scraper.Notify += new EventHandler<NotificationEventArgs>(scraper_Notify); scraper.ScrapeMovies(existing, yrs); } catch { } } if (export && GetDBVersion() >= NewDBVersion) Export(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { this.InvokeEx(() => { EnableDisable(true); }); running = false; } }); }
public VisitorProfile GetVisitor(Guid id) { using (var db = new MovieFinderEntities()) { var vp = db.VisitorProfiles .First(x => x.ID == id); if (db == null) { new ArgumentException(String.Format("Visitor with id {0} does not exist", id)); } return(vp); } }
public List <MovieThumbnailVm> QueryMovies(string term, string langCode, int?year, int?page, int count) { using (var db = new MovieFinderEntities()) { try { IQueryable <Movie> movies = null; if (!String.IsNullOrWhiteSpace(langCode)) { movies = db.Movies.Where(x => x.LanguageCode == langCode); } if (!String.IsNullOrWhiteSpace(term)) { movies = (movies == null ? db.Movies : movies).Where(x => x.Name.StartsWith(term)); } if (year != 0) { movies = (movies == null ? db.Movies : movies).Where(x => x.ReleaseDate.Year == year); } if (movies == null) { movies = db.Movies; } var m = movies.OrderByDescending(x => x.ReleaseDate) .ThenByDescending(x => x.CreateDate) .Skip(page.Value * count) .Take(count) .ToList() .Select(x => new MovieThumbnailVm { ImageUrl = String.IsNullOrWhiteSpace(x.ImageLocalUrl) ? x.ImageUrl : imgUrlBuilder.Build(x.ImageLocalUrl), PostedBy = "Admin", PostedDate = x.CreateDate.ToShortDateString(), Title = x.Name, Language = GetLanguage(x.LanguageCode), ReleasedYear = x.ReleaseDate.Year, Id = x.UniqueID, Url = String.Format("{0}/Watch/{1}/{2}/{3}/{4}", confProvider.RootUrl, GetLanguage(x.LanguageCode), x.ReleaseDate.Year, x.UniqueID, x.Name), ViewCount = x.ViewCount, LikeCount = x.LikeCount }).ToList(); return(m); } catch { return(null); } } }
public MovieVm QueryMovie(string id, bool updateStat = false) { using (var db = new MovieFinderEntities()) { try { var movie = db.Movies .Include(x => x.MovieLinks) .Where(x => x.UniqueID == id && x.MovieLinks.Any(y => y.FailedAttempts < 5)) .ToList() .Select(x => new MovieVm { ImageUrl = String.IsNullOrWhiteSpace(x.ImageLocalUrl) ? x.ImageUrl : imgUrlBuilder.Build(x.ImageLocalUrl), PostedBy = "Admin", Description = x.Description, PostedDate = x.CreateDate.ToShortDateString(), Title = x.Name, Language = GetLanguage(x.LanguageCode), ReleasedYear = x.ReleaseDate.Year, Id = x.UniqueID, Url = String.Format("{0}/Watch/{1}/{2}/{3}/{4}", confProvider.RootUrl, GetLanguage(x.LanguageCode), x.ReleaseDate.Year, x.UniqueID, x.Name), ViewCount = x.ViewCount, LikeCount = x.LikeCount, Links = x.MovieLinks.Where(z => z.IsWebSupported).Select(y => new VideoLinkVm { HostSite = y.DownloadSiteID, Title = ShortenLinkTitle(y.LinkTitle), Url = VideoScraperBase.GetScraper(y.DowloadUrl).GetFlashUrl(y.DowloadUrl), ID = y.ID, PartID = y.PartID, PartIndex = y.PartIndex }).ToList() }).FirstOrDefault(); movie.Links.Sort(); if (updateStat) { var m = db.Movies.Single(x => x.UniqueID == id); m.ViewCount++; db.SaveChanges(); } return(movie); } catch { return(null); } } }
private static void Update() { var doc = XDocument.Load("http://gkplugins.com/mapfile.xml"); var files = doc.Element("dir").Elements("file").ToList(); foreach (var file in files) { using (var db = new MovieFinderEntities()) { var gkName = file.Attribute("name").Value; var time = Convert.ToInt32(file.Attribute("time").Value); var rec = db.Plugins.FirstOrDefault(x => x.GKName == gkName && x.SiteID != null && time != x.LastUpdatedTime); if (rec == null) continue; //get zip file //updated plugin directory //update plugin xml file //update db rec.LastUpdatedTime = time; db.SaveChanges(); } } }
private void Export() { using (var db = new MovieFinderEntities()) { var movies = db.Movies.OrderByDescending(x => x.ID) .Include(x => x.MovieLinks) .ToList(); var path = ConfigurationManager.AppSettings["ExportPath"]; var moviePathTemp = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path, "movie_temp.db")); var moviePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path, "movie.db")); var videoPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path, "video.db")); if (File.Exists(moviePathTemp)) File.Delete(moviePathTemp); File.Copy(videoPath, moviePathTemp); var dataService = new DataService(moviePathTemp); foreach (var m in movies) { if (m.MovieLinks.Count == 0 || m.MovieLinks.Any(x => x.PageUrl.ToLower().Contains("-in-hindi"))) continue; dataService.AddMovie(m); } NewDBVersion = GetDBVersion(); dataService.UpdateMovieSettings(NewDBVersion, DateTime.Now); dataService.ShutDown(); if (File.Exists(moviePath)) File.Delete(moviePath); File.Copy(moviePathTemp, moviePath); File.Delete(moviePathTemp); this.InvokeEx(() => { this.labelLastExportedTime.Text = DateTime.Now.ToString() + "(" + NewDBVersion + ")"; }); } }
public void RemoveLink(string link) { Task.Factory.StartNew(() => { try { using (var db = new MovieFinderEntities()) { var ml = db.MovieLinks.FirstOrDefault(x => x.DowloadUrl == link && x.FailedAttempts <= 3); if (ml != null) { if (VideoScraperBase.ValidateUrl(ml.DowloadUrl) == MovieTube.Client.Scraper.ScraperResult.VideoDoesNotExist) { ml.FailedAttempts = 5; ml.LastValidatedBy = new Guid(); db.SaveChanges(); } } } } catch { } }); }
public void DataUpdate() { using (var db = new MovieFinderEntities()) { var items = db.MovieLinks.Where(x => x.LinkTitle.Contains("part") && x.PartID == null).ToList(); int id = 0; foreach (var item in items) { if (id == item.MovieID) { continue; } id = item.MovieID; var currentItems = items.Where(x => x.MovieID == id).ToList(); var partId = 0; foreach (var cItem in currentItems) { var index = Convert.ToInt32(Regex.Match(cItem.LinkTitle, @"\d+").Value); if (index == 1) { partId = cItem.ID; } cItem.PartID = partId; cItem.PartIndex = index; var k = 0; while (k++ < 3) { db.SaveChanges(); break; } } } } }
private void StartValidate() { this.textBoxMsg.Text = String.Empty; int total = 0, validated = 0, removed= 0 , unknown = 0; var yrs = new List<int>(); if (this.checkBoxQuickValidate.Checked) yrs.AddRange(new List<int> { 2014, 2013, 2012 }); Task.Factory.StartNew(() => { try { List<Movie> movies = null; using (var db = new MovieFinderEntities()) movies = db.Movies.Where(x => yrs.Contains(x.ReleaseDate.Year)) .Include(x => x.MovieLinks).ToList(); var d = DateTime.Now; foreach (var movie in movies) { if (this.stop) break; var recs = movie.MovieLinks.Where(x => x.FailedAttempts < 4 && (x.LastValidatedWhen == null || x.LastValidatedWhen.Value.AddDays(2) < d) && x.PageSiteID != "eih").OrderByDescending(x => x.ID); foreach (var ml in recs) { this.InvokeEx(() => { this.labelValidatingLink.Text = ml.DowloadUrl; this.labelTotalValidated.Text = total.ToString(); this.labelValidatedLink.Text = validated.ToString(); this.labelUnknownLink.Text = unknown.ToString(); this.labelRemovedLink.Text = removed.ToString(); }); var result = MovieTube.Client.Scraper.VideoScraperBase.ValidateUrl(ml.DowloadUrl); total++; switch (result) { case MovieTube.Client.Scraper.ScraperResult.Success: validated++; break; case MovieTube.Client.Scraper.ScraperResult.UnknownError: unknown++; AddError("Unknown error: " + ml.DowloadUrl); continue; case MovieTube.Client.Scraper.ScraperResult.VideoDoesNotExist: this.InvokeEx(() => { this.richTextBoxRemoved.AppendText(ml.DowloadUrl + Environment.NewLine); }); removed++; break; default: break; } using (var db = new MovieFinderEntities()) { var dbMl = db.MovieLinks.Single(x => x.ID == ml.ID); dbMl.FailedAttempts = result == MovieTube.Client.Scraper.ScraperResult.Success ? 0 : (result == MovieTube.Client.Scraper.ScraperResult.VideoDoesNotExist ? 4 : dbMl.FailedAttempts + 1); dbMl.LastValidatedWhen = DateTime.Now; db.SaveChanges(); } } } this.InvokeEx(() => { EnableDisable(true); MessageBox.Show("Done"); }); } catch (Exception ex) { this.InvokeEx(() => { EnableDisable(true); MessageBox.Show(ex.Message); }); } }); }
private void UpdateUI(ScrapedMovie movie) { this.InvokeEx(() => { if (movie.Links.Count == 0) return; try { using (var db = new MovieFinderEntities()) { //check if movie already exists var dbMovie = db.Movies.FirstOrDefault(x => (x.UniqueID == movie.UniqueId)); var modified = false; if (dbMovie == null) //new movie { dbMovie = new Movie { CreateDate = DateTime.Now, Description = movie.Description, ImageUrl = movie.ImageUrl, LanguageCode = movie.LangCode, Name = movie.Name, ReleaseDate = movie.ReleasedDate, Version = NewDBVersion, VersionChange = 0, UniqueID = movie.UniqueId, ImageScrapperID = movie.Scraper.ID }; db.Movies.Add(dbMovie); } else { //get the previous scraper var prevScrapper = MovieDetailsScraperBase.Scrappers.First(x => x.ID == dbMovie.ImageScrapperID); if (String.IsNullOrWhiteSpace(dbMovie.Description) || (dbMovie.Description.Length < 50 && !String.IsNullOrWhiteSpace(movie.Description) && movie.Description.Length > 50)) { dbMovie.Description = movie.Description; modified = true; } if (!String.IsNullOrWhiteSpace(movie.ImageUrl) && (String.IsNullOrWhiteSpace(dbMovie.ImageUrl) || movie.Scraper.ImagePriority < prevScrapper.ImagePriority)) { dbMovie.ImageUrl = movie.ImageUrl; dbMovie.ImageScrapperID = movie.Scraper.ID; dbMovie.ImageLocalUrl = null; modified = true; } } db.SaveChanges(); if (String.IsNullOrWhiteSpace(dbMovie.ImageLocalUrl)) { if(new ImageScrapperService().CopyImageToLocal(dbMovie, ConfigurationManager.AppSettings["ImagePath"])) db.SaveChanges(); } foreach (var l in movie.Links) { if (!db.MovieLinks.Any(x => x.DowloadUrl == l.DownloadUrl)) { db.MovieLinks.Add(new MovieLink { MovieID = dbMovie.ID, LinkTitle = l.Title, SiteTitle = movie.Scraper.Title, PageSiteID = movie.Scraper.ID, PageUrl = movie.PageUrl, DowloadUrl = l.DownloadUrl, DownloadSiteID = l.DownloadSiteID, Version = NewDBVersion, HasSubtitle = movie.Scraper.Title == "EIH", IsWebSupported = true, IsDesktopSupported = true }); db.SaveChanges(); modified = true; } } if (dbMovie.Version != NewDBVersion && modified) { dbMovie.Version = NewDBVersion; dbMovie.ModifiedDate = DateTime.Now; db.SaveChanges(); } } movies.Add(movie); this.labelCount.Text = "Total: " + movies.Count; } catch (Exception ex) { MessageBox.Show(ex.Message); } }); }
public void UpdateVisitor(VisitorProfile model) { using (var db = new MovieFinderEntities()) { } }