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)); }
private static TVSeriesWatch GetSeriesWatch(string urlPart) { var tvSeriesQuery = new TVSeriesQuery(WebSettingsConfig.Instance.DefaultUserLanguages.From.Id); TVSeriesWatch result = tvSeriesQuery.GetSeriesWatch(urlPart); return(result); }
public TVSeriesWatch GetSeriesWatch(long id) { return(Adapter.ReadByContext(c => { TVSeries tvSeries = c.TVSeries.FirstOrDefault(e => e.LanguageId == _languageId && e.Id == id); if (tvSeries == null) { return null; } TVSeriesWatch result = ToTVSeriesWatch(tvSeries); return result; })); }
/// <summary> /// Сохраняет серию сериала /// </summary> /// <param name="parentId">идентификатор родителя(сезона или названия сериала)</param> /// <param name="seriesInfo">информация о серии</param> /// <returns>идентификатор добавленного сериала</returns> public long SaveSeriesWatch(long parentId, TVSeriesWatch seriesInfo) { string urlPart = seriesInfo != null?seriesInfo.GetUrlPart() : null; if (IdValidator.IsInvalid(parentId) || IsUrlPartInvalid(urlPart)) { return(IdValidator.INVALID_ID); } string info = JsonConvert.SerializeObject(seriesInfo); long result = Save(parentId, urlPart, info, TVSeriesDataType.Series); return(result); }
public ActionResult Watch(long userId, 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 watch = GetSeriesWatch(urlPart); if (watch == null) { //TODO: на другой урл return(RedirectToAction("Index", RouteConfig.MAIN_CONTROLLER_NAME)); } watch.IsAdmin = WebSettingsConfig.Instance.IsAdmin(userId); return(View("../Video/TVSeriesDetail", watch)); }
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 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(); * }*/ }
private static void CreateImage(string videoFile, TimeSpan thumbnailTime, string fullPath, TVSeriesWatch tvSeriesWatch) { var imageFileName = Path.Combine(fullPath, tvSeriesWatch.ImageFileName); if (File.Exists(imageFileName)) { File.Delete(imageFileName); } var videoTransformation = new VideoTransformation(videoFile, fullPath); if (!videoTransformation.GetImage(tvSeriesWatch.ImageFileName, thumbnailTime)) { Console.WriteLine("НЕ удалось создать картинку {0}!", tvSeriesWatch.ImageFileName); } }