/// <summary> /// Updates the DVD demos. /// </summary> private void UpdateDVDDemos() { string demoPath = MovieNaming.GetDvdPath(Get.InOutCollection.MovieDVDTestPath) + Path.DirectorySeparatorChar; string demoFileName = MovieNaming.GetDvdName(Get.InOutCollection.MovieDVDTestPath); const string DemoExtention = "jpg"; const string DemoSetName = "DemoSetName"; this.txtDVDNfoPreview.Text = Get.InOutCollection.CurrentMovieSaveSettings.DvdNfoNameTemplate.Replace("<path>", demoPath).Replace( "<filename>", demoFileName).Replace("<ext>", DemoExtention); this.txtDVDPosterPreview.Text = Get.InOutCollection.CurrentMovieSaveSettings.DvdPosterNameTemplate.Replace("<path>", demoPath).Replace( "<filename>", demoFileName).Replace("<ext>", DemoExtention); this.txtDVDFanartPreview.Text = Get.InOutCollection.CurrentMovieSaveSettings.DvdFanartNameTemplate.Replace("<path>", demoPath).Replace( "<filename>", demoFileName).Replace("<ext>", DemoExtention); // Add demo for trailer this.txtDVDSetPosterPreview.Text = Get.InOutCollection.CurrentMovieSaveSettings.DvdSetPosterNameTemplate.Replace("<path>", demoPath). Replace("<filename>", demoFileName).Replace("<ext>", DemoExtention).Replace( "<setname>", DemoSetName); this.txtDVDSetFanartPreview.Text = Get.InOutCollection.CurrentMovieSaveSettings.DvdSetFanartNameTemplate.Replace("<path>", demoPath). Replace("<filename>", demoFileName).Replace("<ext>", DemoExtention).Replace( "<setname>", DemoSetName); }
/// <summary> /// Process a file rename /// </summary> /// <param name="pathFrom"> /// Path from. /// </param> /// <param name="renameTo"> /// Rename too. /// </param> /// <returns> /// The remained path. /// </returns> public static string DoRename(string pathFrom, string renameTo) { renameTo = FileSystemCharChange.To(renameTo); if (MovieNaming.IsBluRay(pathFrom)) { string folderPathFrom = MovieNaming.GetBluRayPath(pathFrom) + MovieNaming.GetBluRayName(pathFrom); string folderPathTo = MovieNaming.GetBluRayPath(pathFrom) + renameTo; if (folderPathFrom != folderPathTo) { try { Directory.Move(folderPathFrom, folderPathTo); return(folderPathTo); } catch { return(string.Empty); } } return(folderPathFrom); } if (MovieNaming.IsDVD(pathFrom)) { string folderPathFrom = MovieNaming.GetDvdPath(pathFrom) + MovieNaming.GetDvdName(pathFrom); string folderPathTo = MovieNaming.GetDvdPath(pathFrom) + renameTo; if (folderPathFrom != folderPathTo) { try { Directory.Move(folderPathFrom, folderPathTo); return(folderPathTo); } catch { return(string.Empty); } } return(folderPathFrom); } string pathTo = Path.GetDirectoryName(pathFrom) + Path.DirectorySeparatorChar + renameTo + Path.GetExtension(pathFrom); try { File.Move(pathFrom, pathTo); } catch { return(pathFrom); } return(pathTo); }
public static string TvSeries(Series series, string replace, string altFirstEpisode = null) { string firstEpisodeFullPath; string seriesName; if (altFirstEpisode != null) { if (altFirstEpisode == string.Empty) { return(string.Empty); } if (MovieNaming.IsDVD(altFirstEpisode)) { firstEpisodeFullPath = MovieNaming.GetDvdPath(altFirstEpisode) + MovieNaming.GetDvdName(altFirstEpisode); } else if (MovieNaming.IsBluRay(altFirstEpisode)) { firstEpisodeFullPath = MovieNaming.GetBluRayPath(altFirstEpisode) + MovieNaming.GetBluRayName(altFirstEpisode); } else { firstEpisodeFullPath = altFirstEpisode; } seriesName = Regex.Match( Path.GetFileNameWithoutExtension(firstEpisodeFullPath), "(?<seriesName>.*?)" + Settings.ConstSettings.DefaultRegex.Tv, RegexOptions.IgnoreCase).Groups["seriesName"].Value.Trim(); } else { firstEpisodeFullPath = series.GetFirstEpisode(); seriesName = Tools.Restructure.FileSystemCharChange.To(series.SeriesName); } string firstEpisodePath; if (MovieNaming.IsDVD(firstEpisodeFullPath)) { firstEpisodePath = MovieNaming.GetDvdPath(firstEpisodeFullPath); } else if (MovieNaming.IsBluRay(firstEpisodeFullPath)) { firstEpisodePath = MovieNaming.GetBluRayPath(firstEpisodeFullPath); } else { firstEpisodePath = Path.GetDirectoryName(firstEpisodeFullPath); } replace = replace.Replace(Settings.Get.InOutCollection.TvSeriesName, seriesName); replace = replace.Replace(Settings.Get.InOutCollection.TvFirstEpisodePathOfSeries, firstEpisodePath); return(replace); }
/// <summary> /// Core find routine /// </summary> /// <param name="name">The name to search for.</param> /// <param name="path">The file path.</param> /// <param name="types">The types.</param> /// <param name="extentions">The extentions.</param> /// <param name="fileList">The file list.</param> /// <returns> /// The find core. /// </returns> private static string FindCore( string name, string path, List <string> types, List <string> extentions, string[] fileList = null) { if (path.Contains("BDMV\\STREAM\\")) { name = MovieNaming.GetBluRayName(path + "name"); path = path.Replace("BDMV\\STREAM\\", string.Empty); fileList = null; } if (path.Contains("VIDEO_TS\\")) { name = MovieNaming.GetDvdName(path + "name"); path = path.Replace("VIDEO_TS\\", string.Empty); fileList = null; } if (fileList == null) { fileList = FindAll(path, SearchOption.TopDirectoryOnly); } foreach (string f in fileList) { string fileMatch = Path.GetFileNameWithoutExtension(f); string matchVideoExtention = Path.GetExtension(f).ToLower().Replace(".", string.Empty); if (extentions.Contains(matchVideoExtention)) { foreach (string type in types) { string replacedType = type.Replace("<fileName>", name); if (replacedType.ToLower() == fileMatch.ToLower()) { return(f); } var a = RemovePart(replacedType).ToLower(); var b = RemovePart(fileMatch).ToLower(); if (a == b) { return(f); } } } } return(string.Empty); }
public static string TvEpisode(Episode episode, string replace, string fromFile, string altEpisode = null) { if (episode == null) { episode = new Episode(); episode.FilePath = new MediaModel { PathAndFilename = @"c:\testshow\season 1\test show.s01e01.avi" }; } string episodePath; string episodeFileName; if (altEpisode == null) { altEpisode = episode.CurrentFilenameAndPath; } if (altEpisode == string.Empty) { return(string.Empty); } if (MovieNaming.IsDVD(altEpisode)) { episodePath = MovieNaming.GetDvdPath(altEpisode); episodeFileName = MovieNaming.GetDvdName(altEpisode); } else if (MovieNaming.IsBluRay(altEpisode)) { episodePath = MovieNaming.GetBluRayPath(altEpisode); episodeFileName = MovieNaming.GetBluRayName(altEpisode); } else { episodePath = Path.GetDirectoryName(altEpisode); episodeFileName = Path.GetFileNameWithoutExtension(altEpisode); } replace = replace.Replace(Settings.Get.InOutCollection.TvEpisodePath, episodePath); replace = replace.Replace(Settings.Get.InOutCollection.TvEpisodeFileName, episodeFileName); return(replace + Path.GetExtension(fromFile)); }
public static string TvEpisode(Episode episode, string replace, string altEpisode = null) { string episodePath; string episodeFileName; if (altEpisode == null) { altEpisode = episode.CurrentFilenameAndPath; } if (altEpisode == string.Empty) { return(string.Empty); } if (MovieNaming.IsDVD(altEpisode)) { episodePath = MovieNaming.GetDvdPath(altEpisode); episodeFileName = MovieNaming.GetDvdName(altEpisode); } else if (MovieNaming.IsBluRay(altEpisode)) { episodePath = MovieNaming.GetBluRayPath(altEpisode); episodeFileName = MovieNaming.GetBluRayName(altEpisode); } else { episodePath = Path.GetDirectoryName(altEpisode); episodeFileName = Path.GetFileNameWithoutExtension(altEpisode); } replace = replace.Replace(Settings.Get.InOutCollection.TvEpisodePath, episodePath); replace = replace.Replace(Settings.Get.InOutCollection.TvEpisodeFileName, episodeFileName); return(replace); }
/// <summary> /// Renames the episode. /// </summary> /// <param name="episode"> /// The episode. /// </param> /// <returns> /// The rename episode. /// </returns> public static string RenameEpisode(Episode episode) { string seriesName = ""; string season1 = string.Empty; string season2 = string.Empty; string episode1 = string.Empty; string episode2 = string.Empty; string episodeName = string.Empty; bool doRename; bool dummy = false; List <Episode> episodesContaining = new List <Episode>(); if (episode != null && episode.ProductionCode == "dummy") { dummy = true; seriesName = "Star Trek: Deep Space Nine"; episode = new Episode { EpisodeNumber = 5, EpisodeName = "Cardassians", SeasonNumber = 2 }; Episode ep2 = new Episode { EpisodeNumber = 6, EpisodeName = "Cardassians2", SeasonNumber = 2 }; Episode ep3 = new Episode { EpisodeNumber = 7, EpisodeName = "Cardassians3", SeasonNumber = 2 }; episodesContaining.Add(episode); episodesContaining.Add(ep2); episodesContaining.Add(ep3); } if (episode == null) { seriesName = "Star Trek: Deep Space Nine"; season1 = "2"; season2 = "02"; episode1 = "5"; episode2 = "05"; episodeName = "Cardassians"; doRename = false; } else { episode1 = string.Empty; episode2 = string.Empty; if (seriesName == "") { seriesName = episode.GetSeriesName(); } int?seasonNumber = episode.SeasonNumber; if (episodesContaining.Count == 0) { episodesContaining = GetEpisodesContainingFile(episode); } season1 = seasonNumber.ToString(); season2 = string.Format("{0:00}", seasonNumber); doRename = false; if (episodesContaining.Count == 1) { episode1 = episode.EpisodeNumber.ToString(); episode2 = string.Format("{0:00}", episode.EpisodeNumber); doRename = true; episodeName = episode.EpisodeName; } else { int count = 0; string multiTemplate = Get.InOutCollection.EpisodeMultiTemplate; multiTemplate = multiTemplate.Replace(EpisodeNumber1Template, "{0}"); multiTemplate = multiTemplate.Replace(EpisodeNumber2Template, "{0:00}"); foreach (Episode ep in episodesContaining) { if (ep.EpisodeNumber == episode.EpisodeNumber && count == 0) { doRename = true; } episode1 += string.Format(multiTemplate, ep.EpisodeNumber); episode2 += string.Format(multiTemplate, ep.EpisodeNumber); count++; } episodeName = episode.EpisodeName; episodeName = episodeName.TrimEnd(); } } string episodeTemplate = Get.InOutCollection.EpisodeNamingTemplate; episodeTemplate = episodeTemplate.Replace(SeriesNameTemplate, seriesName); episodeTemplate = episodeTemplate.Replace(SeasonNumber1Template, season1); episodeTemplate = episodeTemplate.Replace(SeasonNumber2Template, season2); if (episodesContaining.Count <= 1) { episodeTemplate = episodeTemplate.Replace(MultiEpisodeFileTemplate, EpisodeMultiTemplate); episodeTemplate = episodeTemplate.Replace(EpisodeNumber1Template, episode1); episodeTemplate = episodeTemplate.Replace(EpisodeNumber2Template, episode2); } else { if (EpisodeMultiTemplate.Contains(EpisodeNumber1Template)) { episodeTemplate = episodeTemplate.Replace(MultiEpisodeFileTemplate, episode1); } else { episodeTemplate = episodeTemplate.Replace(MultiEpisodeFileTemplate, episode2); } } episodeTemplate = episodeTemplate.Replace(EpisodeNameTemplate, episodeName); if (episode != null) { if (doRename && !dummy) { string newPath = DoRename(episode.FilePath.PathAndFilename, episodeTemplate); if (!string.IsNullOrEmpty(newPath)) { string pathAddition; if (MovieNaming.IsBluRay(episode.FilePath.PathAndFilename)) { pathAddition = episode.FilePath.PathAndFilename.Replace( MovieNaming.GetBluRayPath(episode.FilePath.PathAndFilename) + MovieNaming.GetBluRayName(episode.FilePath.PathAndFilename), string.Empty); episode.FilePath.PathAndFilename = newPath + pathAddition; DatabaseIOFactory.SetDatabaseDirty(); } else if (MovieNaming.IsDVD(episode.FilePath.PathAndFilename)) { pathAddition = episode.FilePath.PathAndFilename.Replace( MovieNaming.GetDvdPath(episode.FilePath.PathAndFilename) + MovieNaming.GetDvdName(episode.FilePath.PathAndFilename), string.Empty); episode.FilePath.PathAndFilename = newPath + pathAddition; DatabaseIOFactory.SetDatabaseDirty(); } else { episode.FilePath.PathAndFilename = newPath; DatabaseIOFactory.SetDatabaseDirty(); } } } } return(episodeTemplate); }
/// <summary> /// Process a file rename /// </summary> /// <param name="pathFrom"> /// Path from. /// </param> /// <param name="renameTo"> /// Rename too. /// </param> /// <returns> /// The remained path. /// </returns> public static string DoRename(string pathFrom, string renameTo) { renameTo = FileSystemCharChange.To(renameTo, FileSystemCharChange.ConvertArea.Tv); var fileName = Path.GetFileNameWithoutExtension(pathFrom); var filePath = Path.GetDirectoryName(pathFrom); // Bluray)) if (MovieNaming.IsBluRay(pathFrom)) { string folderPathFrom = MovieNaming.GetBluRayPath(pathFrom) + MovieNaming.GetBluRayName(pathFrom); string folderPathTo = MovieNaming.GetBluRayPath(pathFrom) + renameTo; if (folderPathFrom != folderPathTo) { try { Directory.Move(folderPathFrom, folderPathTo); MasterMediaDBFactory.ChangeTvFileName(folderPathFrom, folderPathTo); return(folderPathTo); } catch { return(string.Empty); } } return(folderPathFrom); } // DVD if (MovieNaming.IsDVD(pathFrom)) { string folderPathFrom = MovieNaming.GetDvdPath(pathFrom) + MovieNaming.GetDvdName(pathFrom); string folderPathTo = MovieNaming.GetDvdPath(pathFrom) + renameTo; if (folderPathFrom != folderPathTo) { try { Directory.Move(folderPathFrom, folderPathTo); MasterMediaDBFactory.ChangeTvFileName(folderPathFrom, folderPathTo); return(folderPathTo); } catch { return(string.Empty); } } return(folderPathFrom); } // File string pathTo = Path.GetDirectoryName(pathFrom) + Path.DirectorySeparatorChar + renameTo + Path.GetExtension(pathFrom); foreach (var subExt in Get.InOutCollection.SubtitleExtentions) { var possibleFileName = filePath + Path.DirectorySeparatorChar + fileName + "." + subExt; if (File.Exists(possibleFileName)) { try { File.Move(possibleFileName, filePath + Path.DirectorySeparatorChar + renameTo + "." + subExt); } catch { Log.WriteToLog(LogSeverity.Error, 0, "Could not rename", possibleFileName + " -> " + filePath + Path.DirectorySeparatorChar + renameTo + subExt); } } } try { File.Move(pathFrom, pathTo); MasterMediaDBFactory.ChangeTvFileName(pathFrom, pathTo); } catch { return(pathFrom); } return(pathTo); }
/// <summary> /// Saves the movie. /// </summary> /// <param name="movieModel"> /// The movie model. /// </param> public void SaveMovie(MovieModel movieModel) { string actualTrailerFileName = ""; string actualTrailerFileNameExt = ""; string actualFilePath = movieModel.AssociatedFiles.Media[0].FileModel.Path; string actualFileName = movieModel.AssociatedFiles.Media[0].FileModel.FilenameWithOutExt; string currentTrailerUrl = movieModel.CurrentTrailerUrl; MovieSaveSettings movieSaveSettings = Get.InOutCollection.CurrentMovieSaveSettings; string nfoPath = string.IsNullOrEmpty(movieSaveSettings.NfoPath) ? actualFilePath : movieSaveSettings.NfoPath; string posterPath = Downloader.ProcessDownload( movieModel.CurrentPosterImageUrl, DownloadType.Binary, Section.Movies); string fanartPathFrom = Downloader.ProcessDownload( movieModel.CurrentFanartImageUrl, DownloadType.Binary, Section.Movies); string trailerPathFrom = Downloader.ProcessDownload( movieModel.CurrentTrailerUrl, DownloadType.AppleBinary, Section.Movies); string nfoXml = GenerateOutput.GenerateMovieOutput(movieModel); string nfoTemplate; string posterTemplate; string fanartTemplate; string trailerTemplate; string setPosterTemplate; string setFanartTemplate; if (MovieNaming.IsDVD(movieModel.GetBaseFilePath)) { actualFilePath = MovieNaming.GetDvdPath(movieModel.GetBaseFilePath); actualFileName = MovieNaming.GetDvdName(movieModel.GetBaseFilePath); nfoTemplate = movieSaveSettings.DvdNfoNameTemplate; posterTemplate = movieSaveSettings.DvdPosterNameTemplate; fanartTemplate = movieSaveSettings.DvdFanartNameTemplate; trailerTemplate = movieSaveSettings.DvdTrailerNameTemplate; setPosterTemplate = movieSaveSettings.DvdSetPosterNameTemplate; setFanartTemplate = movieSaveSettings.DvdSetFanartNameTemplate; } else if (MovieNaming.IsBluRay(movieModel.GetBaseFilePath)) { actualFilePath = MovieNaming.GetBluRayPath(movieModel.GetBaseFilePath); actualFileName = MovieNaming.GetBluRayName(movieModel.GetBaseFilePath); nfoTemplate = movieSaveSettings.BlurayNfoNameTemplate; posterTemplate = movieSaveSettings.BlurayPosterNameTemplate; fanartTemplate = movieSaveSettings.BlurayFanartNameTemplate; trailerTemplate = movieSaveSettings.BlurayTrailerNameTemplate; setPosterTemplate = movieSaveSettings.BluraySetPosterNameTemplate; setFanartTemplate = movieSaveSettings.BluraySetFanartNameTemplate; } else { nfoTemplate = movieSaveSettings.NormalNfoNameTemplate; posterTemplate = movieSaveSettings.NormalPosterNameTemplate; fanartTemplate = movieSaveSettings.NormalFanartNameTemplate; trailerTemplate = movieSaveSettings.NormalTrailerNameTemplate; setPosterTemplate = movieSaveSettings.NormalSetPosterNameTemplate; setFanartTemplate = movieSaveSettings.NormalSetFanartNameTemplate; } if (!string.IsNullOrEmpty(currentTrailerUrl)) { actualTrailerFileName = currentTrailerUrl.Substring(currentTrailerUrl.LastIndexOf('/') + 1, currentTrailerUrl.LastIndexOf('.') - currentTrailerUrl.LastIndexOf('/') - 1); actualTrailerFileNameExt = currentTrailerUrl.Substring(currentTrailerUrl.LastIndexOf('.') + 1); } string nfoOutputName = nfoTemplate.Replace("<path>", actualFilePath).Replace("<filename>", actualFileName); string posterOutputName = posterTemplate.Replace("<path>", actualFilePath).Replace("<filename>", actualFileName).Replace( "<ext>", "jpg"); string fanartOutputName = fanartTemplate.Replace("<path>", actualFilePath).Replace("<filename>", actualFileName).Replace( "<ext>", "jpg"); string trailerOutputName = trailerTemplate.Replace("<path>", actualFilePath).Replace("<filename>", actualFileName).Replace( "<trailername>", actualTrailerFileName).Replace("<ext>", actualTrailerFileNameExt); string setPosterOutputPath = setPosterTemplate.Replace("<path>", actualFilePath).Replace( "<filename>", actualFileName); string setFanartOutputPath = setFanartTemplate.Replace("<path>", actualFilePath).Replace( "<filename>", actualFileName); // Handle Set Images List <string> sets = MovieSetManager.GetSetsContainingMovie(movieModel); if (sets.Count > 0) { foreach (string setName in sets) { MovieSetModel set = MovieSetManager.GetSet(setName); MovieSetObjectModel setObjectModel = (from s in set.Movies where s.MovieUniqueId == movieModel.MovieUniqueId select s). SingleOrDefault(); string currentSetPosterPath = setPosterOutputPath.Replace("<setname>", setName).Replace( "<ext>", ".jpg"); string currentSetFanartPath = setFanartOutputPath.Replace("<setname>", setName).Replace( "<ext>", ".jpg"); if (setObjectModel.Order == 1) { if (File.Exists(set.PosterUrl)) { File.Copy(set.PosterUrl, currentSetPosterPath); } if (File.Exists(set.FanartUrl)) { File.Copy(set.FanartUrl, currentSetFanartPath); } } else { if (File.Exists(set.PosterUrl) && File.Exists(currentSetPosterPath)) { File.Delete(currentSetPosterPath); } if (File.Exists(set.FanartUrl) && File.Exists(currentSetFanartPath)) { File.Delete(currentSetFanartPath); } } } } if (movieSaveSettings.IoType == MovieIOType.All || movieSaveSettings.IoType == MovieIOType.Nfo) { try { this.WriteNFO(nfoXml, nfoOutputName); movieModel.ChangedText = false; Log.WriteToLog( LogSeverity.Info, 0, "NFO Saved To Disk for " + movieModel.Title, nfoPath + nfoOutputName); } catch (Exception ex) { Log.WriteToLog(LogSeverity.Error, 0, "Saving NFO Failed for " + movieModel.Title, ex.Message); } } if (movieSaveSettings.IoType == MovieIOType.All || movieSaveSettings.IoType == MovieIOType.Poster || movieSaveSettings.IoType == MovieIOType.Images) { try { if (!string.IsNullOrEmpty(movieModel.CurrentPosterImageUrl)) { this.CopyFile(posterPath, posterOutputName); movieModel.ChangedPoster = false; Log.WriteToLog( LogSeverity.Info, 0, "Poster Saved To Disk for " + movieModel.Title, posterPath + " -> " + posterOutputName); } } catch (Exception ex) { Log.WriteToLog(LogSeverity.Error, 0, "Saving Poster Failed for " + movieModel.Title, ex.Message); } } if (movieSaveSettings.IoType == MovieIOType.All || movieSaveSettings.IoType == MovieIOType.Fanart || movieSaveSettings.IoType == MovieIOType.Images) { try { if (!string.IsNullOrEmpty(movieModel.CurrentFanartImageUrl)) { this.CopyFile(fanartPathFrom, fanartOutputName); movieModel.ChangedFanart = false; Log.WriteToLog( LogSeverity.Info, 0, "Fanart Saved To Disk for " + movieModel.Title, fanartPathFrom + " -> " + fanartOutputName); } } catch (Exception ex) { Log.WriteToLog(LogSeverity.Error, 0, "Saving Fanart Failed for " + movieModel.Title, ex.Message); } } if (movieSaveSettings.IoType == MovieIOType.All || movieSaveSettings.IoType == MovieIOType.Trailer) { try { if (!string.IsNullOrEmpty(movieModel.CurrentTrailerUrl)) { this.CopyFile(trailerPathFrom, trailerOutputName); movieModel.ChangedTrailer = false; Log.WriteToLog( LogSeverity.Info, 0, "Trailer Saved To Disk for " + movieModel.Title, trailerPathFrom + " -> " + trailerOutputName); } } catch (Exception ex) { Log.WriteToLog(LogSeverity.Error, 0, "Saving Trailer Failed for " + movieModel.Title, ex.Message); } } }
/// <summary> /// Renames the episode. /// </summary> /// <param name="episode"> /// The episode. /// </param> /// <returns> /// The rename episode. /// </returns> public static string RenameEpisode(Episode episode) { string seriesName; string season1 = string.Empty; string season2 = string.Empty; string episode1 = string.Empty; string episode2 = string.Empty; string episodeName = string.Empty; bool doRename; if (episode == null) { seriesName = "Star Trek: Deep Space Nine"; season1 = "S2"; season2 = "S02"; episode1 = "E5"; episode2 = "E05"; episodeName = "Cardassians"; doRename = false; } else { episode1 = string.Empty; episode2 = string.Empty; seriesName = episode.GetSeriesName(); int?seasonNumber = episode.SeasonNumber; List <Episode> episodesContaining = GetEpisodesContainingFile(episode); season1 = "S" + seasonNumber; season2 = string.Format("S{0:00}", seasonNumber); doRename = false; if (episodesContaining.Count == 1) { episode1 = "E" + episode.EpisodeNumber; episode2 = "E" + string.Format("{0:00}", episode.EpisodeNumber); doRename = true; episodeName = episode.EpisodeName; } else { int count = 0; foreach (Episode ep in episodesContaining) { if (ep.EpisodeNumber == episode.EpisodeNumber && count == 0) { doRename = true; } episode1 += "E" + ep.EpisodeNumber; episode2 += "E" + string.Format("{0:00}", ep.EpisodeNumber); episodeName += string.Format("{0} ", ep.EpisodeName); count++; } episodeName = episodeName.TrimEnd(); } } string episodeTemplate = Get.InOutCollection.EpisodeNamingTemplate; episodeTemplate = episodeTemplate.Replace(SeriesNameTemplate, seriesName); episodeTemplate = episodeTemplate.Replace(SeasonNumber1Template, season1); episodeTemplate = episodeTemplate.Replace(SeasonNumber2Template, season2); episodeTemplate = episodeTemplate.Replace(EpisodeNumber1Template, episode1); episodeTemplate = episodeTemplate.Replace(EpisodeNumber2Template, episode2); episodeTemplate = episodeTemplate.Replace(EpisodeNameTemplate, episodeName); if (episode != null) { if (doRename) { string newPath = DoRename(episode.FilePath.FileNameAndPath, episodeTemplate); if (!string.IsNullOrEmpty(newPath)) { string pathAddition; if (MovieNaming.IsBluRay(episode.FilePath.FileNameAndPath)) { pathAddition = episode.FilePath.FileNameAndPath.Replace( MovieNaming.GetBluRayPath(episode.FilePath.FileNameAndPath) + MovieNaming.GetBluRayName(episode.FilePath.FileNameAndPath), string.Empty); episode.FilePath.FileNameAndPath = newPath + pathAddition; } else if (MovieNaming.IsDVD(episode.FilePath.FileNameAndPath)) { pathAddition = episode.FilePath.FileNameAndPath.Replace( MovieNaming.GetDvdPath(episode.FilePath.FileNameAndPath) + MovieNaming.GetDvdName(episode.FilePath.FileNameAndPath), string.Empty); episode.FilePath.FileNameAndPath = newPath + pathAddition; } else { episode.FilePath.FileNameAndPath = newPath; } } } } return(episodeTemplate); }
/// <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> /// 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); }
public static string TvSeason(Season season, string replace, string fromFile, string altFirstEpisode = null) { string seriesName = "test show"; string firstEpisodeFullPath = @"c:\test show\season 1\test show.s01e01.avi"; bool settings = false; if (season == null) { season = new Season(); season.Episodes.Add(new Episode { FilePath = new MediaModel { PathAndFilename = @"c:\test show\season 1\test show.s01e01.avi" } }); settings = true; } string firstEpisodeOfSeasonPath; string firstEpisodeOfSeason; if (altFirstEpisode != null) { if (altFirstEpisode == string.Empty) { return(string.Empty); } if (MovieNaming.IsDVD(altFirstEpisode)) { firstEpisodeFullPath = MovieNaming.GetDvdPath(altFirstEpisode) + MovieNaming.GetDvdName(altFirstEpisode); firstEpisodeOfSeasonPath = MovieNaming.GetDvdPath(altFirstEpisode); firstEpisodeOfSeason = MovieNaming.GetDvdName(altFirstEpisode); } else if (MovieNaming.IsBluRay(altFirstEpisode)) { firstEpisodeFullPath = MovieNaming.GetBluRayPath(altFirstEpisode) + MovieNaming.GetBluRayName(altFirstEpisode); firstEpisodeOfSeasonPath = MovieNaming.GetBluRayPath(altFirstEpisode); firstEpisodeOfSeason = MovieNaming.GetBluRayName(altFirstEpisode); } else { firstEpisodeFullPath = altFirstEpisode; firstEpisodeOfSeasonPath = Path.GetDirectoryName(altFirstEpisode); firstEpisodeOfSeason = Path.GetFileNameWithoutExtension(altFirstEpisode); } seriesName = Regex.Match(Path.GetFileNameWithoutExtension(firstEpisodeFullPath), "(?<seriesName>.*?)" + Settings.ConstSettings.DefaultRegex.Tv, RegexOptions.IgnoreCase).Groups["seriesName"].Value.Trim(); } else { if (!settings) { firstEpisodeFullPath = season.GetFirstEpisode(); seriesName = Restructure.FileSystemCharChange.To(season.GetSeries().SeriesName, FileSystemCharChange.ConvertArea.Tv); } if (MovieNaming.IsDVD(firstEpisodeFullPath)) { firstEpisodeOfSeasonPath = MovieNaming.GetDvdPath(firstEpisodeFullPath); firstEpisodeOfSeason = MovieNaming.GetDvdName(firstEpisodeFullPath); } else if (MovieNaming.IsBluRay(firstEpisodeFullPath)) { firstEpisodeOfSeasonPath = MovieNaming.GetBluRayPath(firstEpisodeFullPath); firstEpisodeOfSeason = MovieNaming.GetBluRayName(firstEpisodeFullPath); } else { firstEpisodeOfSeasonPath = Path.GetDirectoryName(firstEpisodeFullPath); firstEpisodeOfSeason = Path.GetFileNameWithoutExtension(firstEpisodeFullPath); } } var firstEpisodePath = Path.GetDirectoryName(firstEpisodeFullPath); replace = replace.Replace(Settings.Get.InOutCollection.TvSeriesName, seriesName); replace = replace.Replace(Settings.Get.InOutCollection.TvFirstEpisodePathOfSeries, firstEpisodePath); replace = replace.Replace(Settings.Get.InOutCollection.TvFirstEpisodeOfSeasonPath, firstEpisodeOfSeasonPath); replace = replace.Replace(Settings.Get.InOutCollection.TvFirstEpisodeOfSeason, firstEpisodeOfSeason); replace = replace.Replace(Settings.Get.InOutCollection.TvSeasonNumber, season.SeasonNumber.ToString()); replace = replace.Replace(Settings.Get.InOutCollection.TvSeasonNumber2, string.Format("{0:d2}", season.SeasonNumber)); if (settings) { replace = replace.Replace(Settings.Get.InOutCollection.TvSeriesPath, @"c:\testshow\season 1\"); } else { replace = replace.Replace(Settings.Get.InOutCollection.TvSeriesPath, season.GetSeries().GetSeriesPath()); } return(replace + Path.GetExtension(fromFile));; }
public static string TvSeries(Series series, string replace, string fromFile, string altFirstEpisode = null) { if (series == null) { series = new Series(); series.SeriesName = "Test series"; series.Seasons.Add(1, new Season()); series.Seasons[1].Episodes.Add(new Episode { FilePath = new MediaModel { PathAndFilename = @"c:\testshow\season 1\test show.s01e01.avi" } }); } string firstEpisodeFullPath; string seriesName; if (altFirstEpisode != null) { if (altFirstEpisode == string.Empty) { return(string.Empty); } if (MovieNaming.IsDVD(altFirstEpisode)) { firstEpisodeFullPath = MovieNaming.GetDvdPath(altFirstEpisode) + MovieNaming.GetDvdName(altFirstEpisode); } else if (MovieNaming.IsBluRay(altFirstEpisode)) { firstEpisodeFullPath = MovieNaming.GetBluRayPath(altFirstEpisode) + MovieNaming.GetBluRayName(altFirstEpisode); } else { firstEpisodeFullPath = altFirstEpisode; } seriesName = Regex.Match( Path.GetFileNameWithoutExtension(firstEpisodeFullPath), "(?<seriesName>.*?)" + Settings.ConstSettings.DefaultRegex.Tv, RegexOptions.IgnoreCase).Groups["seriesName"].Value.Trim(); } else { firstEpisodeFullPath = series.GetFirstEpisode(); seriesName = Tools.Restructure.FileSystemCharChange.To(series.SeriesName, FileSystemCharChange.ConvertArea.Tv); } string firstEpisodePath; if (MovieNaming.IsDVD(firstEpisodeFullPath)) { firstEpisodePath = MovieNaming.GetDvdPath(firstEpisodeFullPath); } else if (MovieNaming.IsBluRay(firstEpisodeFullPath)) { firstEpisodePath = MovieNaming.GetBluRayPath(firstEpisodeFullPath); } else { firstEpisodePath = Path.GetDirectoryName(firstEpisodeFullPath); } replace = replace.Replace(Settings.Get.InOutCollection.TvSeriesName, seriesName); replace = replace.Replace(Settings.Get.InOutCollection.TvFirstEpisodePathOfSeries, firstEpisodePath); replace = replace.Replace(Settings.Get.InOutCollection.TvSeriesPath, series.GetSeriesPath()); return(replace + Path.GetExtension(fromFile)); }