Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        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);
        }
Example #4
0
        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));
        }
Example #5
0
        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);
        }
Example #6
0
        /// <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);
        }
Example #7
0
        /// <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);
        }
Example #8
0
        /// <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);
                }
            }
        }
Example #9
0
        /// <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);
        }
Example #10
0
        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));;
        }
Example #11
0
        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));
        }