public void LoadMyData() { try { nfoFileType nfofiletype = nfoFileType.Unknown; MyDataInfo = nfoHelper.LoadNfoFile(CurrentMoviePath, out nfofiletype); LoadedNfoFileType = nfoFileType.Unknown; LoadedNfoFileType = nfofiletype; m_IsNFoInfoMissing = MyDataInfo == null || MyDataInfo.IsEmpty; if (LoadedNfoFileType != nfoFileType.Unknown) { Loggy.Logger.Debug("nfo loaded for " + CurrentMoviePath); } if (MyDataInfo != null) { if (MyDataInfo.MediaInfo != null && MediaInfo != null) { // be smart. if the detected mediainfo has new items not present in the .nfo file, use them PatchMediainfo(MyDataInfo.MediaInfo); MediaInfo = MyDataInfo.MediaInfo; } } // load metadata and select it if present this.MetadataInfo = MoviesheetsUpdateManager.CreateManagerForMovie(CurrentMoviePath).GetMovieInfo(); if (this.MetadataInfo != null) { if (this.MetadataInfo.MediaInfo != null && MediaInfo != null) { // be smart. if the detected mediainfo has new items not present in the .nfo file, use them PatchMediainfo(MetadataInfo.MediaInfo); MediaInfo = MetadataInfo.MediaInfo; } } m_IsMetadataInfoMissing = this.MetadataInfo == null || this.MetadataInfo.IsEmpty; // apply imdbinfo to the my own nfo collector if (MyDataInfo != null) { this.MyDataInfo = ApplyIMDbMovieInfoBehaviour(this.MyDataInfo, this.IMDBInfo); } this.SelectInfoSourceByPriority(); } catch (Exception ex) { try { Loggy.Logger.DebugException("Load nfo:", ex); } catch { /*needed for designtime*/ } } }
private void GenerateMetadataButton_Click(object sender, RoutedEventArgs e) { nfoFileType nfotype = nfoFileType.Unknown; string _tmpPath = Helpers.GetUniqueFilename(".jpg"); try { MovieSheetsGenerator _gen = new MovieSheetsGenerator(SheetType.Main, fsMovieFile.Filepath); _gen.SelectedTemplate = this.TemplateSelector.TemplatesCombobox.SelectedItem as TemplateItem; if (_gen.CreateMoviesheetFromCustomData(this.fsBackdrop.Filepath, this.fsCover.Filepath, this.fsFanart1.Filepath, this.fsFanart2.Filepath, this.fsFanart3.Filepath, this.fsNfo.Filepath, this.fsMovieFile.Filepath, _tmpPath, false)) { SaveFileDialog _sfd = new SaveFileDialog(); _sfd.Title = "Select target metadata file name"; _sfd.Filter = this.FindResource("metadataFilter") as string; _sfd.DefaultExt = ".tgmd"; if ((bool)_sfd.ShowDialog()) { MoviesheetsUpdateManager _man = MoviesheetsUpdateManager.CreateManagerFromMetadata(_sfd.FileName, fsMovieFile.Filepath); MoviesheetsUpdateManagerParams _params = new MoviesheetsUpdateManagerParams(fsBackdrop.Filepath, fsFanart1.Filepath, fsFanart2.Filepath, fsFanart3.Filepath, nfoHelper.LoadNfoFile(fsMovieFile.Filepath, fsNfo.Filepath, out nfotype), fsCover.Filepath, _gen.MovieSheetPreviewTempPath); _man.GenerateUpdateFile(_params, _gen.SelectedTemplate.TemplateName); _man = null; } } else { MessageBox.Show(_gen.LastError); } } finally { try { File.Delete(_tmpPath); } catch { } } }
private MovieInfo ExtractMovieInfo(string movieFilePath) { int _key = movieFilePath.GetHashCode(); if (m_InfoCache.ContainsKey(_key)) { return(m_InfoCache[_key]); } else { // check if there is a nfo/metadata file available string _metadataFilename = FileManager.Configuration.GetMoviesheetMetadataPath(movieFilePath, false); string _nfoFilename = FileManager.Configuration.GetMovieInfoPath(movieFilePath, false, MovieinfoType.Export); MovieInfo _info = null; // check metadata if (!string.IsNullOrEmpty(_metadataFilename) && File.Exists(_metadataFilename)) { MoviesheetsUpdateManager _metadataManager = MoviesheetsUpdateManager.CreateManagerForMovie(movieFilePath); _info = _metadataManager.GetMovieInfo(); if (string.IsNullOrEmpty(_info.Name)) { _info = null; } } // check nfo if (_info == null && !string.IsNullOrEmpty(_nfoFilename) && File.Exists(_nfoFilename)) { nfoFileType _nfotype = nfoFileType.Unknown; _info = nfoHelper.LoadNfoFile(movieFilePath, out _nfotype); if (_info != null && string.IsNullOrEmpty(_info.Name)) { _info = null; } } m_InfoCache.Add(movieFilePath.GetHashCode(), _info); return(_info); } }
public static void AppendFullMediaInfoToNfoFile(string nfoFilepath, string movieFilepath) { try { nfoFileType _out = nfoFileType.Unknown; MovieInfo _info = nfoHelper.LoadNfoFile(movieFilepath, nfoFilepath, out _out); if (_out == nfoFileType.ThumbGen) { using (MemoryStream _ms = new MemoryStream()) { if (AppendFullMediaInfoToNfoFile(_info, movieFilepath, _ms)) { if (_ms.Length != 0) { _ms.Position = 0; using (FileStream _fs = new FileStream(nfoFilepath, FileMode.Open, FileAccess.ReadWrite)) { _ms.CopyTo(_fs); } } } else { Loggy.Logger.Debug("Appending mediainfo failed"); } } } else { Loggy.Logger.Debug("Will not add full mediainfo to a non-ThumbGen nfo file: " + nfoFilepath); } } catch (Exception ex) { Loggy.Logger.DebugException("Cannot add full mediainfo to " + nfoFilepath, ex); } }
public static MovieInfo LoadNfoFile(string movieFilename, string nfoFilePath, out nfoFileType nfofiletype) { MovieInfo _result = new MovieInfo(); nfofiletype = nfoFileType.Unknown; string _nfoFilename = nfoFilePath; // if there's no nfo specified if (string.IsNullOrEmpty(_nfoFilename)) { // first try to load from target movieinfo path _nfoFilename = GetNfoFilename(movieFilename, false); if (string.IsNullOrEmpty(_nfoFilename) || !File.Exists(_nfoFilename)) { // try also near the movie _nfoFilename = GetNfoFilename(movieFilename, true); } } if (File.Exists(_nfoFilename)) { using (FileStream _fs = new FileStream(_nfoFilename, FileMode.Open, FileAccess.Read)) { // check first if it is a valid XML XmlDocument _doc = new XmlDocument(); try { _doc.Load(_fs); } catch { // no valid xml, safely jump out return(_result); } bool _loaded = false; // check if it is an ember one _result = TryParse(new EmberNfoHelper(), _nfoFilename, out _loaded, out nfofiletype); // check if maybe it is a xbmc nfo file if (!_loaded) { _result = TryParse(new XBMCNfoHelper(), _nfoFilename, out _loaded, out nfofiletype); } // check if maybe it is a mymovies.dk nfo file if (!_loaded) { _result = TryParse(new MyMoviesNfoHelper(), _nfoFilename, out _loaded, out nfofiletype); } // check if maybe it is a TViXiE nfo file if (!_loaded) { _result = TryParse(new TvixieNfoHelper(), _nfoFilename, out _loaded, out nfofiletype); } if (!_loaded) { try { _fs.Position = 0; XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo)); _result = _xs.Deserialize(_fs) as MovieInfo; nfofiletype = nfoFileType.ThumbGen; } catch (Exception ex) { Loggy.Logger.DebugException("Cannot deserialize nfo:" + _nfoFilename, ex); } } } } return(_result); }
public static MovieInfo LoadNfoFile(string movieFilename, out nfoFileType nfofiletype) { return(LoadNfoFile(movieFilename, null, out nfofiletype)); }
private static MovieInfo TryParse(NfoHelperBase helper, string nfoFilename, out bool loaded, out nfoFileType nfofiletype) { MovieInfo _result = null; loaded = false; nfofiletype = nfoFileType.Unknown; if (helper != null) { MemoryStream _ms = helper.ParseFile(nfoFilename) as MemoryStream; if (_ms != null) { try { _ms.Position = 0; XmlSerializer _xs = new XmlSerializer(typeof(MovieInfo)); _result = _xs.Deserialize(_ms) as MovieInfo; loaded = true; nfofiletype = helper.FileType; } catch (Exception ex) { Loggy.Logger.DebugException(string.Format("Cannot deserialize nfo {0} using {1}", nfoFilename, helper.FileType.ToString()), ex); } } } return(_result); }