public TVSeriesWatch GetSeriesWatch(string urlPart) { if (IsUrlPartInvalid(urlPart)) { return(null); } return(Adapter.ReadByContext(c => { TVSeries tvSeries = GetByUrlPart(c, urlPart); if (tvSeries == null) { return null; } TVSeries parentTVSeries = GetParent(c, tvSeries.ParentId); if (parentTVSeries == null) { return null; } TVSeriesInfo coverInfo = ToCoverInfo(parentTVSeries); if (coverInfo == null) { return null; } TVSeriesWatch result = ToTVSeriesWatch(tvSeries); result.SetSeriesInfo(coverInfo); return result; })); }
public FileResult GetVideo(string urlPart) { if (WebSettingsConfig.Instance.IsSectionForbidden(SectionId.TVSeries)) { return(null); } TVSeriesWatch seriesWatch = GetSeriesWatch(urlPart); if (seriesWatch == null) { return(null); } string fullFileName = WebSettingsConfig.Instance.GetDataFileName(SERIES_FOLDER, seriesWatch.GetPathToFiles(), seriesWatch.VideoFileName); byte[] fileContents = ReadFile(fullFileName); if (EnumerableValidator.IsNullOrEmpty(fileContents)) { return(null); } TVSeriesInfo seriesInfo = seriesWatch.GetSeriesInfo(); return(File(fileContents, "video/mp4", seriesInfo.OrigTitle + "_" + seriesWatch.VideoFileName)); }
/// <summary> /// Сохраняет обложку сериала(информацию о сериале) /// </summary> /// <param name="seriesInfo">информация о сериале</param> /// <returns>идентификатор добавленной обложки</returns> public long SaveSeriesInfo(TVSeriesInfo seriesInfo) { string urlPart = seriesInfo != null?seriesInfo.GetUrlPart() : null; if (IsUrlPartInvalid(urlPart)) { return(IdValidator.INVALID_ID); } string info = JsonConvert.SerializeObject(seriesInfo); long result = Save(IdValidator.INVALID_ID, urlPart, info, TVSeriesDataType.Cover); return(result); }
public void GetAllEpisodes_WithValidShowSeason_ReturnsAllEpisodes() { // Arrange ShowInformationManager showMgr = new ShowInformationManager(); // Act TVSeriesInfo seriesInfo = showMgr.GetSeriesInfo("Once Upon a Time"); // Assert foreach (var seasonGroup in seriesInfo.Seasons) { Debug.WriteLine("Season number: {0}", seasonGroup.Key); foreach (TVEpisodeInfo episode in seasonGroup) { Debug.WriteLine("Ep {0}: {1}", episode.EpisodeNumber, episode.EpisodeTitle); } } }
/// <summary> /// Gets all episodes for a given show /// </summary> /// <param name="showName">The TV show name to get information for</param> /// <returns></returns> public TVSeriesInfo GetSeriesInfo(string showName) { TVSeriesInfo seriesInfo = null; // Resolve the show alias (if it exists) showName = ResolveShowToAlias(showName); foreach (var provider in SEShowInfoProviders) { seriesInfo = provider.GetSeriesInfo(showName); // If we found our information, get out if (seriesInfo != null) { break; } } return(seriesInfo); }
public ActionResult GetImageByName(string baseUrlPart, int season, int episode) { if (IsInvalid(baseUrlPart, season, episode)) { //TODO: на другой урл return(RedirectToAction("Index", RouteConfig.MAIN_CONTROLLER_NAME)); } string urlPart = TVSeriesQuery.GetUrlPart(baseUrlPart, season, episode); TVSeriesWatch seriesWatch = GetSeriesWatch(urlPart); if (seriesWatch == null) { return(null); } string fullFileName = WebSettingsConfig.Instance.GetDataFileName(SERIES_FOLDER, seriesWatch.GetPathToFiles(), seriesWatch.ImageFileName); TVSeriesInfo seriesInfo = seriesWatch.GetSeriesInfo(); return(GetImage(seriesInfo.OrigTitle + "_" + seriesWatch.ImageFileName, e => ReadFile(fullFileName))); }
public static List <BreadcrumbItem> GetTVSeries(UrlHelper url, TVSeriesInfo seriesInfo, TVSeriesWatch seriesWatch) { string seasonHeader = "Серия " + seriesWatch.Episode; if (seriesWatch.Season > 0) { seasonHeader = "Сезон " + seriesWatch.Season + ". " + seasonHeader; } return(new List <BreadcrumbItem> { new BreadcrumbItem { Html = string.Format("<a href='{0}'>Сериал «{1}»</a>", url.Action("Detail", RouteConfig.TV_SERIES_CONTROLLER, new { baseUrlPart = seriesInfo.GetUrlPart() }), seriesInfo.Title), }, new BreadcrumbItem { IsActive = true, Title = seasonHeader } }); }
public ActionResult Detail(string baseUrlPart) { if (WebSettingsConfig.Instance.IsSectionForbidden(SectionId.TVSeries)) { return(RedirectToAction("Index", RouteConfig.MAIN_CONTROLLER_NAME)); } var tvSeriesQuery = new TVSeriesQuery(WebSettingsConfig.Instance.DefaultUserLanguages.From.Id); List <TVSeriesWatch> watches = tvSeriesQuery.GetSeriesWatches(baseUrlPart); if (EnumerableValidator.IsEmpty(watches)) { return(RedirectToAction("Index", RouteConfig.MAIN_CONTROLLER_NAME)); } TVSeriesInfo seriesInfo = watches[0].GetSeriesInfo(); var model = new TVSeriesModel { Title = seriesInfo.Title, OrigTitle = seriesInfo.OrigTitle, Series = ConvertWatchesToModels(watches) }; return(View("../Video/TVSeriesIndex", model)); }
/// <summary> /// Gets all show information, including all episodes for a show /// </summary> /// <param name="showname"></param> /// <returns></returns> public TVSeriesInfo GetSeriesInfo(string showname) { TVSeriesInfo retval = new TVSeriesInfo(); // Get the show information TVDBSeriesResult seriesResult = GetSeriesForShow(showname); TVDBSeriesInfo series = null; if (seriesResult != null) { series = seriesResult.SeriesInfo; } // Get all episodes for the show: if (series != null) { // Set basic show information: retval.Name = series.SeriesName; // Get the language from the configuration file language = ConfigurationManager.AppSettings["TheTVDB_Language"] ?? "en"; // Construct the cache path string currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); cacheDirectory = ConfigurationManager.AppSettings["TheTVDB_CacheDir"] ?? "cache"; cacheDirectory = Path.Combine(currentPath, cacheDirectory, series.SeriesId); // Construct the cache filename string cacheFile = cacheDirectory + Path.DirectorySeparatorChar + "episodes.zip"; // Make sure the cache file exists: if (!Directory.Exists(cacheDirectory)) { // If the directory doesn't exist, create it: if (!Directory.Exists(cacheDirectory)) { Directory.CreateDirectory(cacheDirectory); } } // Check to see if we have cached results for the series if (!File.Exists(cacheFile)) { // Get the latest episode zip and save it to the cache path GetEpisodeBundle(series, language, cacheFile); } // If the cache file exists... if (File.Exists(cacheFile)) { XDocument doc = new XDocument(); // Open it as a zipfile: using (ZipArchive zip = ZipFile.Open(cacheFile, ZipArchiveMode.Read)) { foreach (ZipArchiveEntry entry in zip.Entries) { if (entry.Name == language + ".xml") { // Attempt to create an XDocument from it doc = XDocument.Load(entry.Open()); break; } } } // Using the XDocument return a list of TVEpisodeInfo's var episodes = from item in doc.Descendants("Episode") select new TVEpisodeInfo() { EpisodeTitle = item.Element("EpisodeName").Value, EpisodeSummary = item.Element("Overview").Value, EpisodeNumber = Convert.ToInt32(item.Element("EpisodeNumber").Value), OriginalAirDate = DateTime.Parse(item.Element("FirstAired").Value), SeasonNumber = Convert.ToInt32(item.Element("SeasonNumber").Value), ShowName = series.SeriesName }; retval.Seasons = from episode in episodes group episode by episode.SeasonNumber into seasonGroup orderby seasonGroup.Key select seasonGroup; } } return(retval); }
public void Create(int season, int episode, string videoFile, string sourceSubtitlesFile, string origTitle, string transTitle, TimeSpan thumbnailTime) { string urlPart = _transSeriesName; var tvSeriesInfo = new TVSeriesInfo { OrigTitle = _origSeriesName, Title = _transSeriesName, Description = null, PathToFiles = _origSeriesName, ImageFileName = null, }; tvSeriesInfo.SetUrlPart(urlPart); var coverId = _seriesQuery.SaveSeriesInfo(tvSeriesInfo); string newFileName = episode.ToString(CultureInfo.InvariantCulture); string timeShiftFile = episode.ToString(CultureInfo.InvariantCulture); if (season > 0) { timeShiftFile = season + "_" + timeShiftFile; timeShiftFile = timeShiftFile + "_time.txt"; } timeShiftFile = Path.Combine(Path.GetDirectoryName(sourceSubtitlesFile), timeShiftFile); var sourceAnalyzer = new SubtitlesAnalyzer(sourceSubtitlesFile, Encoding.UTF8); List <Subtitle> sourceSubtitles = sourceAnalyzer.Analyze(timeShiftFile); var tvSeriesWatch = new TVSeriesWatch { Season = season, Episode = episode, OrigTitle = origTitle, TransTitle = transTitle, Description = null, Subtitles = sourceSubtitles, VideoFileName = newFileName + Path.GetExtension(videoFile), }; tvSeriesWatch.SetSeriesInfo(tvSeriesInfo); urlPart = TVSeriesQuery.GetUrlPart(urlPart, season, episode); tvSeriesWatch.SetUrlPart(urlPart); string fullPath = Path.Combine(_outputPath, tvSeriesWatch.GetPathToFiles()); if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } string destVideoFile = Path.Combine(fullPath, tvSeriesWatch.VideoFileName); File.Copy(videoFile, destVideoFile, true); tvSeriesWatch.ImageFileName = newFileName + ".jpeg"; CreateImage(videoFile, thumbnailTime, fullPath, tvSeriesWatch); long tvSeriesId = _seriesQuery.SaveSeriesWatch(coverId, tvSeriesWatch); if (IdValidator.IsInvalid(tvSeriesId)) { Console.WriteLine("Не удалось добавить видео {0}", videoFile); } /*int partNumber = 1; * var videoCutter = new VideoCutter(videoFileName, @"C:\Projects\Сериалы\Друзья\1_1_parts"); * foreach (Subtitle episode in enEpisodes) * { * //TODO: соединить с другими частями и получить более длинный отрывок * if (episode.Duration.TotalSeconds < 2) * { * continue; * } * string outFileName = partNumber.ToString(CultureInfo.InvariantCulture) + ".mp4"; * if (!videoCutter.Cut(outFileName, episode.TimeFrom, episode.TimeTo)) * { * Console.WriteLine("Не удалось разрезать файл {0}, часть №{1}", videoFileName, partNumber); * Console.ReadLine(); * } * Console.WriteLine("Обработана часть {0} у видео {1}", partNumber, videoFileName); * partNumber++; * }*/ /*string ruFileName = * @"C:\Projects\Сериалы\Друзья\Субтитры\ru\Friends - 1x01 - The One Where Monica Gets A Roommate.ru.srt"; * var ruAnalyzer = new SubtitlesAnalyzer(ruFileName, Encoding.GetEncoding(1251)); * var ruEpisodes = ruAnalyzer.Analyze(); * * var matcher = new VideoEpisodesMatcher(enEpisodes, ruEpisodes); * var result = matcher.Match(); * * foreach (var tuple in result) { * Console.WriteLine(tuple.Item1.ToPrettyFormat() + "\r\n" + tuple.Item2.ToPrettyFormat()); * Console.ReadLine(); * }*/ }
/// <summary> /// Gets all show information, including all episodes for a show /// </summary> /// <param name="showname"></param> /// <returns></returns> public TVSeriesInfo GetSeriesInfo(string showname) { TVSeriesInfo retval = new TVSeriesInfo(); // Get the show information TVDBSeriesResult seriesResult = GetSeriesForShow(showname); TVDBSeriesInfo series = null; if (seriesResult != null) { series = seriesResult.SeriesInfo; } // Get all episodes for the show: if (series != null) { // Set basic show information: retval.Name = series.SeriesName; // Get the language from the configuration file language = "en"; // Construct the cache path string currentPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); cacheDirectory = "cache"; cacheDirectory = Path.Combine(currentPath, cacheDirectory, series.SeriesId); // Construct the cache filename string cacheFile = cacheDirectory + Path.DirectorySeparatorChar + "episodes.zip"; // Make sure the cache file exists: if (!Directory.Exists(cacheDirectory)) { // If the directory doesn't exist, create it: if (!Directory.Exists(cacheDirectory)) { Directory.CreateDirectory(cacheDirectory); } } // Check to see if we have cached results for the series if (!File.Exists(cacheFile)) { // Get the latest episode zip and save it to the cache path GetEpisodeBundle(series, language, cacheFile); } // If the cache file exists... if (File.Exists(cacheFile)) { XDocument doc = new XDocument(); // Open it as a zipfile: using (ZipArchive zip = ZipFile.Open(cacheFile, ZipArchiveMode.Read)) { foreach (ZipArchiveEntry entry in zip.Entries) { if (entry.Name == language + ".xml") { // Attempt to create an XDocument from it doc = XDocument.Load(entry.Open()); break; } } } // Using the XDocument return a list of TVEpisodeInfo's var episodes = (from item in doc.Descendants("Episode") select GetEpisode(item, series.SeriesName)).Where(e => e != null); retval.Seasons = from episode in episodes group episode by episode.SeasonNumber into seasonGroup orderby seasonGroup.Key select seasonGroup; } } return(retval); }