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 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(); * }*/ }