public async Task <EpisodeDetails> GetEpisodeDetails(string episodeId) { HttpClient client = new HttpClient(); HttpRequestMessage request = new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = new Uri($"{apiUrl}/title/get-overview-details?tconst={episodeId}¤tCountry={apiCountry}"), Headers = { { "x-rapidapi-key", user.APIKey }, { "x-rapidapi-host", host } } }; using (HttpResponseMessage response = await client.SendAsync(request)) { response.EnsureSuccessStatusCode(); EpisodeDetails episode = await response.Content.ReadFromJsonAsync <EpisodeDetails>(); episode.Id = episodeId; return(episode); } }
private async void GetSeasonEpisodes() { episodes = new List <Episode>(); foreach (var ep in season.Episodes) { Episode episode = GlobalConfig.Connection.FindEpisodeById(ep.Id); if (episode != null) { episodes.Add(episode); } else { EpisodeDetails episodeDetails = await api.GetEpisodeDetails(ep.Id); episode = new Episode() { EpisodeId = episodeDetails.Id, ShowId = show.Id, Show = show, Title = episodeDetails.Title.Title, EpisodeNumber = episodeDetails.Title.Episode, ImageUrl = episodeDetails.Title.Image.Url, RunningTimeInMinutes = episodeDetails.Title.RunningTimeInMinutes, Season = episodeDetails.Title.Season, Rating = episodeDetails.Ratings.Rating, Genres = string.Join(", ", episodeDetails.Genres), Year = episodeDetails.Title.Year, ReleaseDate = DateTime.Parse(episodeDetails.ReleaseDate), PlotOutline = episodeDetails.PlotOutline != null ? episodeDetails.PlotOutline.Text : "" }; GlobalConfig.Connection.AddEpisode(episode); episodes.Add(episode); } PopulateListBox(); } }
public async static Task SendFavoritesToWatchEmail(User user) { API api = new API(user); List <string> showsWhithNewEpisodes = new List <string>(); List <FavoriteShow> favoriteShows = GlobalConfig.Connection.FindUserFavoriteShows(user); foreach (FavoriteShow favoriteShow in favoriteShows) { Show show = GlobalConfig.Connection.FindShowById(favoriteShow.ShowId); var seasons = await api.GetShowSeasons(favoriteShow.ShowId); bool hasNewEpisode = false; foreach (ShowSeason season in seasons.ToList()) { foreach (ShowSeasonEpisode seasonEpisode in season.Episodes) { if (seasonEpisode.Year < ((DateTime)user.LastLogin).Year) { break; } if (seasonEpisode.Year == ((DateTime)user.LastLogin).Year) { Episode episode = GlobalConfig.Connection.FindEpisodeById(seasonEpisode.Id); if (episode == null) { EpisodeDetails episodeDetails = await api.GetEpisodeDetails(seasonEpisode.Id); episode = new Episode() { EpisodeId = episodeDetails.Id, ShowId = show.Id, Show = show, Title = episodeDetails.Title.Title, EpisodeNumber = episodeDetails.Title.Episode, ImageUrl = episodeDetails.Title.Image.Url, RunningTimeInMinutes = episodeDetails.Title.RunningTimeInMinutes, Season = episodeDetails.Title.Season, Rating = episodeDetails.Ratings.Rating, Genres = string.Join(", ", episodeDetails.Genres), Year = episodeDetails.Title.Year, ReleaseDate = DateTime.Parse(episodeDetails.ReleaseDate), PlotOutline = episodeDetails.PlotOutline != null ? episodeDetails.PlotOutline.Text : "" }; GlobalConfig.Connection.AddEpisode(episode); } if (episode.ReleaseDate > user.LastLogin && episode.ReleaseDate < DateTime.UtcNow) { showsWhithNewEpisodes.Add(show.Title); hasNewEpisode = true; break; } } } if (hasNewEpisode) { break; } } if (showsWhithNewEpisodes.Count() == 0) { return; } string subject = GlobalConfig.GetEmailResourceString("NewFavoriteEpisodesSubject"); StringBuilder body = new StringBuilder(); body.AppendLine("<div style='text-align: center;'>"); body.AppendLine("<img title='IMDb Tracker logo' alt='IMDb Tracler logo' src='cid:email-logo' />"); body.AppendLine("<h1>" + GlobalConfig.GetEmailResourceString("NewFavoriteEpisodesTitle") + "</h1>"); body.AppendLine("<p>" + GlobalConfig.GetEmailResourceString("NewFavoriteEpisodesMessage") + "</p>"); body.AppendLine("<ul>"); foreach (string episodeTitle in showsWhithNewEpisodes) { body.AppendLine("<li><strong>" + episodeTitle + "</strong></li>"); } body.AppendLine("</ul>"); body.AppendLine("<br/>"); body.AppendLine("<strong>" + GlobalConfig.GetEmailResourceString("Signature") + "</strong>"); body.AppendLine("</div>"); SendEmail(user.Email, subject, body.ToString(), null); } }
/// <summary> /// Add scan result. /// </summary> /// <param name="episodeDetails"> /// The episode details. /// </param> public static void AddScanResult(EpisodeDetails episodeDetails) { var seriesName = episodeDetails.SeriesName; var name = seriesName; var check1 = (from s in Scan where s.Key.ToLower() == name.ToLower() select s.Key).SingleOrDefault(); // Process Series if (check1 == null) { Scan.Add(seriesName, new ScanSeries()); var check2 = (from s in SeriesNameList where s.SeriesName.ToLower() == seriesName.ToLower() select s.SeriesName.ToLower()).ToList(); if (!check2.Contains(seriesName.ToLower()) && !string.IsNullOrEmpty(seriesName)) { string dir = Directory.GetParent(episodeDetails.FilePath).Name; string path = string.Empty; if (dir.StartsWith("season", true, System.Globalization.CultureInfo.CurrentCulture)) { // Looks like it. Qualified series guess path = Directory.GetParent(episodeDetails.FilePath).Parent.FullName; } else { // Best guess path = Directory.GetParent(episodeDetails.FilePath).FullName; } SeriesNameList.Add( new SeriesListModel { WaitingForScan = true, SeriesName = seriesName, SeriesPath = path }); } } else { seriesName = check1; } // Process Series if (!Scan[seriesName].Seasons.ContainsKey(episodeDetails.SeasonNumber)) { Scan[seriesName].Seasons.Add(episodeDetails.SeasonNumber, new ScanSeason()); } if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( episodeDetails.EpisodeNumber)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( episodeDetails.EpisodeNumber, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[episodeDetails.EpisodeNumber]. FilePath = episodeDetails.FilePath; if (episodeDetails.SecondaryNumbers.Count > 0) { foreach (int secondary in episodeDetails.SecondaryNumbers) { if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( secondary)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( secondary, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].FilePath = episodeDetails.FilePath; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].Secondary = true; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].SecondaryTo = episodeDetails.EpisodeNumber; } } var findList = (from s in MediaPathDBFactory.GetMediaPathTvUnsorted() where s.PathAndFileName == episodeDetails.FilePath select s).ToList(); foreach (var path in findList) { MediaPathDBFactory.GetMediaPathTvUnsorted().Remove(path); } }
/// <summary> /// Gets the episode details. /// </summary> /// <param name="filePath">The file path.</param> /// <returns>The episode details.</returns> public static EpisodeDetails GetEpisodeDetails(string filePath) { string logCategory = "ImportTvFactory > GetEpisodeDetails"; var episodeDetails = new EpisodeDetails { FilePath = filePath }; string series; if (MovieNaming.IsDVD(filePath)) { series = MovieNaming.GetDvdName(filePath); } else if (MovieNaming.IsBluRay(filePath)) { series = MovieNaming.GetBluRayName(filePath); } else { series = Path.GetFileNameWithoutExtension(filePath); } InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format("Getting episode details for: {0}", series), logCategory); // Check if dir structure is <root>/<series>/<season>/<episodes> string dir = Directory.GetParent(filePath).Name; string seriesGuess = string.Empty; if (dir.StartsWith("season", true, System.Globalization.CultureInfo.CurrentCulture)) { // Looks like it. Qualified series guess seriesGuess = Directory.GetParent(filePath).Parent.Name; } InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format("Qualified series name guess, based on folder: {0}", seriesGuess), logCategory); var regex = Regex.Match( series, "(?<seriesName>.*?)" + DefaultRegex.Tv, RegexOptions.IgnoreCase); string rawSeriesName; if (regex.Success) { rawSeriesName = regex.Groups["seriesName"].Value.Trim(); InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format("Series name from file: {0}", rawSeriesName), logCategory); var result = (from r in ScanSeriesPicks where r.SearchString == rawSeriesName select r) .SingleOrDefault(); string rawSeriesGuess = rawSeriesName.Replace(new string[] { ".", "_", "-" }, " ").Trim(); if (seriesGuess != string.Empty) { if (rawSeriesName == string.Empty) { // Anything's better than nothing rawSeriesName = seriesGuess; } else if (rawSeriesName.StartsWith(seriesGuess)) { // Regex might've picked up some random crap between series name and s01e01 rawSeriesName = seriesGuess; } else if (rawSeriesName.Length > 0 && (rawSeriesName.Substring(0, 1) == seriesGuess.Substring(0, 1) || rawSeriesGuess.ToLower().Replace("and", "&") == seriesGuess.ToLower().Replace("and", "&"))) { // Regex might've picked up an acronym for the series // TGaaG = Two Guys and a Girl if (result == null) { rawSeriesName = seriesGuess; } } } else { rawSeriesName = rawSeriesGuess; } InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format("Best series guess: {0}", rawSeriesName), logCategory); episodeDetails.SeriesName = result != null ? result.SeriesName : rawSeriesName; episodeDetails.SeriesName = FileSystemCharChange.From(episodeDetails.SeriesName, FileSystemCharChange.ConvertArea.Tv); } var seasonMatch = Regex.Match(series, DefaultRegex.TvSeason, RegexOptions.IgnoreCase); if (seasonMatch.Success) { episodeDetails.SeasonNumber = seasonMatch.Groups[1].Value.GetNumber(); } InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format("Extracted season number: {0}", episodeDetails.SeasonNumber), logCategory); var episodeMatch = Regex.Matches(series, DefaultRegex.TvEpisode, RegexOptions.IgnoreCase); if (episodeMatch.Count > 0) { episodeDetails.TvMatchSuccess = true; if (episodeMatch.Count > 1) { bool first = true; foreach (Match match in episodeMatch) { if (first) { episodeDetails.EpisodeNumber = match.Value.GetNumber(); first = false; } else { episodeDetails.SecondaryNumbers.Add(match.Value.GetNumber()); } } InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format( "Extracted episode numbers ({0}): {1}", episodeDetails.SecondaryNumbers.Count, string.Join(", ", episodeDetails.SecondaryNumbers)), logCategory); } else { var episodeMatch2 = Regex.Match(series, DefaultRegex.TvEpisode, RegexOptions.IgnoreCase); episodeDetails.EpisodeNumber = episodeMatch2.Groups[1].Value.GetNumber(); InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format("Extracted episode number: {0}", episodeDetails.EpisodeNumber), logCategory); } } episodeDetails.SeriesName = episodeDetails.SeriesName.Replace(".", string.Empty).Trim(); if (episodeDetails.SeriesName.EndsWith("-")) { episodeDetails.SeriesName = episodeDetails.SeriesName.TrimEnd('-').Trim(); } var check = (from s in ScanSeriesPicks where s.SearchString == episodeDetails.SeriesName select s).SingleOrDefault(); if (check != null) { episodeDetails.SeriesName = check.SeriesName; } InternalApps.Logs.Log.WriteToLog( LogSeverity.Debug, 0, string.Format("Final series name: {0}", episodeDetails.SeriesName), logCategory); return(episodeDetails); }
/// <summary> /// Add scan result. /// </summary> /// <param name="episodeDetails"> /// The episode details. /// </param> public static void AddScanResult(EpisodeDetails episodeDetails) { var seriesName = episodeDetails.SeriesName; var name = seriesName; var check1 = (from s in Scan where s.Key.ToLower() == name.ToLower() select s.Key).SingleOrDefault(); // Process Series if (check1 == null) { Scan.Add(seriesName, new ScanSeries()); var check2 = (from s in SeriesNameList where s.SeriesName.ToLower() == seriesName.ToLower() select s.SeriesName.ToLower()).ToList(); if (!check2.Contains(seriesName.ToLower())) { SeriesNameList.Add( new SeriesListModel { WaitingForScan = true, SeriesName = seriesName }); } } else { seriesName = check1; } // Process Series if (!Scan[seriesName].Seasons.ContainsKey(episodeDetails.SeasonNumber)) { Scan[seriesName].Seasons.Add(episodeDetails.SeasonNumber, new ScanSeason()); } if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( episodeDetails.EpisodeNumber)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( episodeDetails.EpisodeNumber, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[episodeDetails.EpisodeNumber]. FilePath = episodeDetails.FilePath; if (episodeDetails.SecondaryNumbers.Count > 0) { foreach (int secondary in episodeDetails.SecondaryNumbers) { if ( !Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.ContainsKey( secondary)) { Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes.Add( secondary, new ScanEpisode()); } Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].FilePath = episodeDetails.FilePath; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].Secondary = true; Scan[seriesName].Seasons[episodeDetails.SeasonNumber].Episodes[secondary].SecondaryTo = episodeDetails.EpisodeNumber; } } var findList = (from s in MediaPathDBFactory.GetMediaPathTvUnsorted() where s.PathAndFileName == episodeDetails.FilePath select s).ToList(); foreach (var path in findList) { MediaPathDBFactory.GetMediaPathTvUnsorted().Remove(path); } }
/// <summary> /// Gets the episode details. /// </summary> /// <param name="filePath">The file path.</param> /// <returns>The episode details.</returns> public static EpisodeDetails GetEpisodeDetails(string filePath) { var episodeDetails = new EpisodeDetails { FilePath = filePath }; string series; if (MovieNaming.IsDVD(filePath)) { series = MovieNaming.GetDvdName(filePath); } else if (MovieNaming.IsBluRay(filePath)) { series = MovieNaming.GetBluRayName(filePath); } else { series = Path.GetFileNameWithoutExtension(filePath); } var regex = Regex.Match( series, "(?<seriesName>.*?)" + DefaultRegex.Tv, RegexOptions.IgnoreCase); if (regex.Success) { var rawSeriesName = regex.Groups["seriesName"].Value.Trim(); var result = (from r in ScanSeriesPicks where r.SearchString == rawSeriesName select r) .SingleOrDefault(); episodeDetails.SeriesName = result != null ? result.SeriesName : rawSeriesName; episodeDetails.SeriesName = Tools.Restructure.FileSystemCharChange.From(episodeDetails.SeriesName); } var fileMatch = Regex.Match(series, DefaultRegex.Tv, RegexOptions.IgnoreCase); if (fileMatch.Success) { episodeDetails.TvMatchSuccess = true; var ep = fileMatch.Groups[2].Value; if (string.IsNullOrEmpty(ep)) { ep = fileMatch.Groups[3].Value; } var episodeNumberString = ep; var seriesNumberString = fileMatch.Groups[1].Value; episodeDetails.SeasonNumber = seriesNumberString.GetNumber(); episodeDetails.EpisodeNumber = episodeNumberString.GetNumbers()[0]; var episodeNumbers = episodeNumberString.GetNumbers(); if (episodeNumbers.Count > 1) { for (var i = 1; i < episodeNumbers.Count; i++) { episodeDetails.SecondaryNumbers.Add(episodeNumbers[i]); } } } episodeDetails.SeriesName = episodeDetails.SeriesName.Replace(".", string.Empty).Trim(); if (episodeDetails.SeriesName.EndsWith("-")) { episodeDetails.SeriesName = episodeDetails.SeriesName.TrimEnd('-').Trim(); } var check = (from s in ScanSeriesPicks where s.SearchString == episodeDetails.SeriesName select s).SingleOrDefault(); if (check != null) { episodeDetails.SeriesName = check.SeriesName; } return(episodeDetails); }