/// <summary> /// The set all movies changed in set. /// </summary> /// <param name="set">The set to alter.</param> private static void SetAllMoviesChangedInSet(MovieSetModel set) { var movies = GetMoviesInSets(set); foreach (var movie in movies) { movie.ChangedText = true; } }
/// <summary> /// Add new set. /// </summary> /// <param name="response">The response.</param> public static void AddNewSet(string response) { var newSetModel = new MovieSetModel { SetName = response }; CurrentDatabase.Add(newSetModel); SetCurrentSet(newSetModel); }
/// <summary> /// Checks existence of a set with a particular name /// </summary> /// <param name="response">The response.</param> /// <returns></returns> public static bool HasSetWithName(string response) { MovieSetModel find = (from s in database where s.SetName.ToLower() == response.ToLower() select s).SingleOrDefault(); if (find == null) { return(false); } return(true); }
/// <summary> /// Removes the set. /// </summary> /// <param name="setName">The Set Name.</param> public static void RemoveSet(string setName) { MovieSetModel find = (from s in database where s.SetName == setName select s).SingleOrDefault(); if (find == null) { return; } SetAllMoviesChangedInSet(find); database.Remove(find); InvokeSetListChanged(new EventArgs()); SetCurrentSet(new MovieSetModel()); }
/// <summary> /// Gets the order of movie in set. /// </summary> /// <param name="setName">The movie set model name.</param> /// <param name="movieModel">The movie model.</param> /// <returns> /// The order the movie falls in the set /// </returns> public static int?GetOrderOfMovieInSet(string setName, MovieModel movieModel) { MovieSetModel movieSetModel = (from s in database where s.SetName == setName select s).SingleOrDefault(); if (movieSetModel == null) { return(null); } var check = (from m in movieSetModel.Movies where m.MovieUniqueId == movieModel.MovieUniqueId select m.Order).ToList(); if (check.Count() > 0) { return(check[0]); } return(null); }
/// <summary> /// Sets the current set. /// </summary> /// <param name="movieSetModel">The movie set model.</param> public static void SetCurrentSet(MovieSetModel movieSetModel) { currentSet = movieSetModel; InvokeCurrentSetChanged(new EventArgs()); }
/// <summary> /// Returns the movies in sets. /// </summary> /// <param name="movieSetModel">The movie set model.</param> /// <returns>Collection of movies in a set</returns> public static List <MovieModel> GetMoviesInSets(MovieSetModel movieSetModel) { return(movieSetModel.Movies.Select(movieSetObect => MovieDBFactory.GetMovie(movieSetObect.MovieUniqueId)).Where(movie => movie != null).ToList()); }
/// <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); } } }