private static void AddToMovieCache(TVProgramme tvp) { int newInt = CachedMovies.Count + 1; TVMovie tvm = new TVMovie(newInt, tvp); CachedMovies.Add(tvp.Title, tvm); }
public async Task AddToArchiveAsync(TVMovie movie) { var toArchiveMovie = new ArchiveMovie(movie); await _liveContext.ArchiveMovies.AddAsync(toArchiveMovie); await _liveContext.SaveChangesAsync(); }
public async Task <TVMovie> GetTheSameFromActual(TVMovie movie) { var movies = await _liveContext.TVMovies.Include(x => x.YouTube).ToListAsync(); var exMovie = movies.FirstOrDefault(s => s.TrailerSearch == movie.TrailerSearch && s.PlayAt == movie.PlayAt); return(exMovie); }
public static bool CachedRedDotRecordingMatchesAndIsRecording(TVMovie tvm, ref bool isSeriesRecording) { foreach (CommonEPG.TVProgramme tvp in tvm.Showings) { if (CachedRedDotRecordingMatchesAndIsRecording(tvp, ref isSeriesRecording)) { return(true); } } return(false); }
private static void MergeToMovieCache(TVProgramme tvp) { TVMovie existingMovie = CachedMovies[tvp.Title]; existingMovie.Showings.Add(tvp); }
/* public async Task UpdateAsync() * { * * Log.Information($"Start TV movies upating"); * * try * { * * * var tvPrograms = new List<string>() { * "https://www.telemagazyn.pl/tvp_1/", * "https://www.telemagazyn.pl/tvp_2/", * "https://www.telemagazyn.pl/polsat/", * "https://www.telemagazyn.pl/tvn/", * "https://www.telemagazyn.pl/tvn_7/", * "https://www.telemagazyn.pl/tv_4/", * "https://www.telemagazyn.pl/tv_puls/", * "https://www.telemagazyn.pl/stopklatka/", * "https://www.telemagazyn.pl/fokus_tv/", * "https://www.telemagazyn.pl/nowa_tv/", * "https://www.telemagazyn.pl/metro/", * "https://www.telemagazyn.pl/wp1/", * "https://www.telemagazyn.pl/zoom_tv/", * }; * * var toManyReq = false; * //var lastDate = GetLastDate(); * * var todayDate = DateTime.Now.Date; * var lastDate = DateTime.Now.Date; * var movies = new List<TVMovie>(); * * using(var context = new LiveContext(_sql)) * { * movies = await context.TVMovies.ToListAsync(); * } * * if(movies.Count>0) * { * //var youngest = movies.OrderByDescending(x => x.PlayAt).ToList().FirstOrDefault(); * //lastDate = DateTime.Parse(youngest.UrlEmisionDay).Date; * * var dates = movies.Select(x => DateTime.Parse(x.UrlEmisionDay)).ToList(); * lastDate = dates.Max(); * * } * * var days = (lastDate - todayDate).TotalDays; * * //var days1 = (lastDate.AddDays(-2) - todayDate).Days; * //var days2 = (lastDate.AddDays(1) - todayDate).Days; * //var days3 = (lastDate.AddDays(-4) - todayDate).Days; * //Console.WriteLine($"days: {days}"); * //Console.WriteLine($"days1: {days1}"); * //Console.WriteLine($"days2: {days2}"); * //Console.WriteLine($"days3: {days3}"); * * int from = 0; * int future = 0; * * if(days < 0) * { * from = 0; * future = 4; * } * if(days == 0) * { * from = 1; * future = 4; * } * if(days == 1) * { * from = 2; * future = 4; * } * if(days == 2) * { * from = 3; * future = 4; * } * if(days > 2) * { * from = 0; * future = 0; * } * * //Console.Write($"Days: {days}"); * * var allMovies = new List<TVMovie>(); * * for(int i=from; i<future; i++) * { * //string z przeslosci - update dzis jutro i pojutrze i popojutrze * //string taki sam jak teraz - update z jutra i pojutrza i popojutrza * //string z jutra - update dla pojutrza i popojutrza * // string z pojutrza - update dla popojutrza * // string z dalej niz pojutrze - udpusc update * * * var date = System.DateTime.Now.AddDays(i); * var day = date.ToString("yyyy-MM-dd"); * * //Console.WriteLine($"Getting movies from day: {day}"); * * foreach(var stat in tvPrograms) * { * var progMovies = await GetMoviesForTvStationAsync(stat, day); * allMovies.AddRange(progMovies); * } * } * * var moviesCount = allMovies.Count; * //Log.Information($"TVMovies UPDATED with {moviesCount} movies"); * foreach (var movie in allMovies) * { * var now = DateTime.Now; * bool inFuture = movie.PlayAt >= now.AddHours(-1); * var exists = await GetTheSameFromActual(movie); * * if((exists is null) && inFuture) * { * //Console.WriteLine(moviesCount); * * var archiveMovieL = await GetByNameFromArchive(movie.TrailerSearch); * * var archiveMovie = archiveMovieL.FirstOrDefault(); * if(archiveMovie is null) * { * if(toManyReq == false) * { * movie.SetYoutube(); * } * else * { * movie.SetWhileYoutube(); * } * * if (movie.YouTube.VideoID.Contains("FirstError")) * { * Log.Warning("First ERROR from TVMovie Update"); * toManyReq = true; * } * var rating = movie.getFilmwebRating(); * await AddToArchiveAsync(movie); * } * else * { * movie.SetYoutubeFromArchive(archiveMovie); * if(archiveMovie.Rating != null) * { * movie.changeRating(archiveMovie.Rating); * } * else{ * var rating = movie.getFilmwebRating(); * archiveMovie.changeRating(rating); * } * } * * //await _liveContext.Songs.AddAsync(movie); * * * //Console.WriteLine(movie.Title + " " + movie.YouTube.VideoID); * movie.Added = DateTime.Now; * //Console.WriteLine(movie.Title); * await _liveContext.TVMovies.AddAsync(movie); * await _liveContext.SaveChangesAsync(); * moviesCount = moviesCount-1; * } * // _liveContext.TVMovies.RemoveRange(_liveContext.TVMovies.Where(x => x.PlayAt < DateTime.Now.AddHours(-2))); * } * * if(allMovies.Count>0) * { * * _liveContext.TVMovies.RemoveRange(_liveContext.TVMovies.Where(x => x.PlayAt < DateTime.Now.AddHours(-2))); * await _liveContext.SaveChangesAsync(); * * var errors = allMovies.Where(x => x.YouTube != null) * .Where(x => x.YouTube.VideoID.Contains("Error")).ToList(); * * Log.Information($"Finish TV movies update with {allMovies.Count} and {errors.Count} youtube errors"); * } * * * InfoCaches._tvMoviesUpdatingRunning = true; * } * catch(Exception ex) * { * Log.Error($"Error while updating tvmovies: {ex.Message}"); * Log.Error(ex.StackTrace); * InfoCaches._tvMoviesUpdatingRunning = false; * } * * } */ public async Task <List <TVMovie> > GetMoviesForTvStationAsync(string station, string url, string day) { var programDay = $"?dzien={day}"; var htmlCode = ""; var movieList = new List <TVMovie>(); try { var movieUrl = url + programDay; using (WebClient client = new WebClient { Encoding = System.Text.Encoding.UTF8 }) { await Task.Run(() => { try { htmlCode = client.DownloadString(movieUrl); } catch (Exception ex) { Log.Error($"Exception DownloadString: {movieUrl}"); Log.Error(ex.Message); } }); } var mainHTML = new HtmlDocument(); await Task.Run(() => { mainHTML.LoadHtml(htmlCode); }); var programList = mainHTML.DocumentNode.SelectSingleNode("//div[@class='lista']").InnerHtml; var statHTML = new HtmlDocument(); await Task.Run(() => { statHTML.LoadHtml(programList); }); var hours = statHTML.DocumentNode.SelectNodes("//em") .Select(x => double.Parse(x.InnerText.Trim().Replace(':', ','))).ToList(); var moviesLi = statHTML.DocumentNode.SelectNodes("//li"); if (moviesLi != null) { var moviesProgList = moviesLi.Where(x => x.OuterHtml.Contains("programInfo")).ToList(); int i = 0; foreach (var movie in moviesProgList) { var restHours = hours.Skip(i).ToList(); /* var nextDay = true; * if(restHours.Count>0) * { * //Console.WriteLine(restHours[0]); * nextDay = restHours.All(x => x<700); * } */ i++; if (movie.Attributes["class"].Value == "filmy") { var html = movie.InnerHtml; var doc = new HtmlDocument(); await Task.Run(() => { doc.LoadHtml(html); }); var docHref = doc.DocumentNode.SelectSingleNode("//a[@class='programInfo']"); if (docHref != null) { var href = docHref.Attributes["href"].Value; var movieObj = new TVMovie(html, href, day); movieObj.SetStation(station); movieList.Add(movieObj); } } } } } catch (Exception ex) { //Console.WriteLine("Something wrong in program --> " + url); //Console.WriteLine(ex.Message); Log.Error($"Something wrong with program: {url}"); Log.Error(ex.Message); Log.Error(ex.StackTrace); } return(movieList); }
private bool GetExists(TVMovie tvMovie) { var actuall = _liveContext.TVMovies.FirstOrDefault(x => x.Title == tvMovie.Title && x.PlayAt == tvMovie.PlayAt); return(actuall == null); }