Exemplo n.º 1
0
        /// <summary>
        /// The add movie to set.
        /// </summary>
        /// <param name="movie">The movie.</param>
        /// <param name="setName">The set name.</param>
        /// <param name="order">The order.</param>
        public static void AddMovieToSet(MovieModel movie, string setName, int?order = null)
        {
            MovieSetModel check = (from m in database where m.SetName == setName select m).SingleOrDefault();

            var movieSetObjectModel = new MovieSetObjectModel {
                MovieUniqueId = movie.MovieUniqueId
            };

            if (order != null)
            {
                movieSetObjectModel.Order = (int)order;
            }

            if (check == null)
            {
                var movieSetModel = new MovieSetModel();

                movieSetModel.Movies.Add(movieSetObjectModel);
                movieSetModel.SetName = setName;

                database.Add(movieSetModel);
            }
            else
            {
                check.AddMovie(movie, order);
            }

            movie.ChangedText = true;

            SetAllMoviesChangedInCurrentSet();
        }
Exemplo n.º 2
0
        /// <summary>
        /// The switch up down buttons.
        /// </summary>
        public void SwitchUpDownButtons()
        {
            MovieSetObjectModel currentRow = this.GetCurrentRow();

            this.btnMoveUp.Enabled   = true;
            this.btnMoveDown.Enabled = true;
            this.btnTrash.Enabled    = true;

            if (currentRow == null)
            {
                this.btnMoveUp.Enabled   = false;
                this.btnMoveDown.Enabled = false;
                this.btnTrash.Enabled    = false;
                return;
            }

            if (currentRow.Order == 1)
            {
                this.btnMoveUp.Enabled = false;
            }

            if (currentRow.Order == MovieSetManager.GetCurrentSet.Movies.Count)
            {
                this.btnMoveDown.Enabled = false;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes from set.
        /// </summary>
        /// <param name="id">The id of the set to remove</param>
        public static void RemoveFromSet(string id)
        {
            MovieSetObjectModel setObj =
                (from m in currentSet.Movies where m.MovieUniqueId == id select m).SingleOrDefault();

            if (setObj != null)
            {
                currentSet.Movies.Remove(setObj);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds the movie to current set.
        /// </summary>
        /// <param name="movie">The movie to add to set</param>
        public static void AddMovieToCurrentSet(MovieModel movie)
        {
            MovieSetObjectModel check =
                (from m in currentSet.Movies where m.MovieUniqueId == movie.MovieUniqueId select m).SingleOrDefault();

            if (check != null)
            {
                XtraMessageBox.Show(string.Format("{0} already exists in set {1}", movie.Title, currentSet.SetName));
                return;
            }

            currentSet.AddMovie(movie);
            InvokeCurrentSetMoviesChanged(new EventArgs());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the Click event of the btnMoveUp control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="System.EventArgs"/> instance containing the event data.
        /// </param>
        private void btnMoveUp_Click(object sender, EventArgs e)
        {
            MovieSetObjectModel currentRow = this.GetCurrentRow();

            if (currentRow == null)
            {
                return;
            }

            MovieSetManager.GetCurrentSet.MoveMovieUp(currentRow.MovieUniqueId);

            this.RefreshAndReorder();
            this.SwitchUpDownButtons();
            MovieSetManager.SetAllMoviesChangedInCurrentSet();
        }
Exemplo n.º 6
0
        /// <summary>
        /// The add movie to set.
        /// </summary>
        /// <param name="movie">The movie.</param>
        /// <param name="setName">The set name.</param>
        /// <param name="order">The order.</param>
        public static void AddMovieToSet(MovieModel movie, string setName, int? order = null)
        {
            MovieSetModel check = (from m in database where m.SetName == setName select m).SingleOrDefault();

            var movieSetObjectModel = new MovieSetObjectModel { MovieUniqueId = movie.MovieUniqueId };

            if (order != null)
            {
                movieSetObjectModel.Order = (int)order;
            }

            if (check == null)
            {
                var movieSetModel = new MovieSetModel();

                movieSetModel.Movies.Add(movieSetObjectModel);
                movieSetModel.SetName = setName;

                database.Add(movieSetModel);
            }
            else
            {
                check.AddMovie(movie, order);
            }

            movie.ChangedText = true;

            SetAllMoviesChangedInCurrentSet();
        }
Exemplo n.º 7
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);
                }
            }
        }