Esempio n. 1
0
        public void ImportCover(MovieSheetsGenerator generator, bool IsLoadFromMetadata, MoviesheetsUpdateManager metadatamanager)
        {
            if (!string.IsNullOrEmpty(this.CoverPath))
            {
                generator.UpdateCover(this.CoverPath);
                return;
            }

            bool _coverDone = false;

            //process cover
            // if import is selected and mask is not empty
            if (FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFolderjpgAsCover &&
                !string.IsNullOrEmpty(FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFolderjpgAsCoverName))
            {
                string _coverPath = null;
                if (ConfigHelpers.CheckIfFileExists(MoviePath, FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFolderjpgAsCoverName, out _coverPath))
                {
                    CoverPath = _coverPath;
                    // signal that MyOwnThumbnailFromDiskImage should be updated
                    IsMyOwnThumbnailFromDiskImageRequired = true;
                    // update the sheets generators
                    if (generator != null)
                    {
                        generator.UpdateCover(_coverPath);
                    }
                    _coverDone = true;
                }
            }

            if (metadatamanager == null)
            {
                metadatamanager = MetadataManager;
            }

            if (!_coverDone && IsLoadFromMetadata && metadatamanager != null)
            {
                string _tmpCover = Helpers.GetUniqueFilename(".jpg");
                FileManager.AddToGarbageFiles(_tmpCover);
                _coverDone = metadatamanager.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCover);
                if (generator != null)
                {
                    generator.UpdateCover(_tmpCover);
                }
                CoverPath = _tmpCover;
                IsMyOwnThumbnailFromDiskImageRequired = true;

                _coverDone = true;
            }

            if (!_coverDone && generator != null)
            {
                generator.UpdateCover(DefaultCoverPath);
            }
        }
Esempio n. 2
0
 private void ImportFromMetadata(MoviesheetsUpdateManager metadatamanager)
 {
     // if there is a .tgmd file add images from inside to the own backdrops pool
     if (metadatamanager != null && File.Exists(metadatamanager.TargetFilename))
     {
         string _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.BACKGROUND_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
         _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.FANART1_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
         _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.FANART2_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
         _path = Helpers.GetUniqueFilename(".jpg");
         if (metadatamanager.GetImage(MoviesheetsUpdateManager.FANART3_STREAM_NAME, _path))
         {
             FileManager.AddToGarbageFiles(_path);
             // add it to the pool too
             BackdropItem _item = PrepareBackdropItem(_path, false);
             AddBackdropToLists(_item, true);
         }
     }
 }
            public void ThreadPoolCallback()
            {
                try
                {
                    try
                    {
                        Loggy.Logger.Debug(string.Format("Entering Thread {0}", Thread.CurrentThread.ManagedThreadId));
                        Loggy.Logger.Factory.Flush();

                        try
                        {
                            MovieItem _movieItem = FileManager.GetMovieByFilePath(this.MoviePath);
                            FileManager.SetMovieItemStatus(_movieItem, MovieItemStatus.Querying);
                        }
                        catch { }

                        MoviesheetsUpdateManager _man = new MoviesheetsUpdateManager(this.MetadataFile, this.MoviePath);

                        MoviesheetInfo _metadataInfo = _man.GetMetadataInfo();

                        string _ext          = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.CoverExtension) ? _metadataInfo.CoverExtension : ".jpg";
                        string _tmpCoverPath = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.BackgroundExtension) ? _metadataInfo.BackgroundExtension : ".jpg";
                        string _tmpBackgroundPath = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.Fanart1Extension) ? _metadataInfo.Fanart1Extension : ".jpg";
                        string _tmpFanart1Path = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.Fanart2Extension) ? _metadataInfo.Fanart2Extension : ".jpg";
                        string _tmpFanart2Path = Helpers.GetUniqueFilename(_ext);
                        _ext = _metadataInfo != null && !string.IsNullOrEmpty(_metadataInfo.Fanart3Extension) ? _metadataInfo.Fanart3Extension : ".jpg";
                        string _tmpFanart3Path = Helpers.GetUniqueFilename(_ext);

                        MovieInfo     _movieinfo = _man.GetMovieInfo();
                        MediaInfoData _mediainfo = _movieinfo != null ? _movieinfo.MediaInfo : null;

                        Action ExtractImagesIfNeeded = new Action(delegate
                        {
                            if (!File.Exists(_tmpCoverPath))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCoverPath);
                            }
                            if (!File.Exists(_tmpBackgroundPath))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.BACKGROUND_STREAM_NAME, _tmpBackgroundPath);
                            }
                            if (!File.Exists(_tmpFanart1Path))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.FANART1_STREAM_NAME, _tmpFanart1Path);
                            }
                            if (!File.Exists(_tmpFanart2Path))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.FANART2_STREAM_NAME, _tmpFanart2Path);
                            }
                            if (!File.Exists(_tmpFanart3Path))
                            {
                                _man.GetImage(MoviesheetsUpdateManager.FANART3_STREAM_NAME, _tmpFanart3Path);
                            }
                        });

                        try
                        {
                            foreach (UpdateItem _item in Items)
                            {
                                // if cancellation was approved, jump out
                                if (CancelProcessing.WaitOne(20))
                                {
                                    return;
                                }

                                switch (_item.ItemType)
                                {
                                case UpdateItemType.Moviesheet:
                                case UpdateItemType.Extrasheet:
                                case UpdateItemType.ParentFoldersheet:
                                    if (_item.Template != null)
                                    {
                                        SheetType _sheetType = _item.ItemType == UpdateItemType.Extrasheet ? SheetType.Extra : _item.ItemType == UpdateItemType.ParentFoldersheet ? SheetType.Spare : SheetType.Main;

                                        MovieSheetsGenerator _Generator = new MovieSheetsGenerator(_sheetType, this.MoviePath);

                                        _Generator.SelectedTemplate = _item.Template;

                                        // call the Action responsible to extract images if missing
                                        ExtractImagesIfNeeded.Invoke();

                                        // try to get latest IMDB rating for the movie
                                        if (_movieinfo != null && FileManager.Configuration.Options.UpdateIMDbRating)
                                        {
                                            try
                                            {
                                                string _newRating = new IMDBMovieInfo().GetIMDbRating(_movieinfo.IMDBID);
                                                if (!string.IsNullOrEmpty(_newRating))
                                                {
                                                    _movieinfo.Rating = _newRating;
                                                    try
                                                    {
                                                        // update back the metadata (as the rating is needed for playlists)
                                                        using (MemoryStream _ms = new MemoryStream())
                                                        {
                                                            _movieinfo.Save(_ms, this.MoviePath, true);
                                                            _man.AddPart(NFO_STREAM_NAME, _ms);
                                                        }
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Loggy.Logger.DebugException("Updating Rating into .tgmd.", ex);
                                                    }
                                                }
                                            }
                                            catch { }
                                        }

                                        // set items

                                        _Generator.MovieInfo = _movieinfo;
                                        _Generator.MediaInfo = _mediainfo;
                                        _Generator.UpdateCover(_tmpCoverPath);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Background, _tmpBackgroundPath);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Fanart1, _tmpFanart1Path);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Fanart2, _tmpFanart2Path);
                                        _Generator.UpdateBackdrop(MoviesheetImageType.Fanart3, _tmpFanart3Path);

                                        _Generator.RenderAndReplicateMoviesheet(_item.TargetPath, true);
                                        _Generator.Dispose();
                                        _Generator.MovieInfo        = null;
                                        _Generator.MediaInfo        = null;
                                        _Generator.SelectedTemplate = null;
                                        _Generator = null;
                                    }
                                    break;

                                case UpdateItemType.Thumbnail:
                                    if (!File.Exists(_tmpCoverPath))
                                    {
                                        _man.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCoverPath);
                                    }
                                    Helpers.CreateThumbnailImage(_tmpCoverPath, _item.TargetPath, FileManager.Configuration.Options.KeepAspectRatio);
                                    break;

                                case UpdateItemType.ExtraThumbnail:
                                    if (!File.Exists(_tmpCoverPath))
                                    {
                                        _man.GetImage(MoviesheetsUpdateManager.COVER_STREAM_NAME, _tmpCoverPath);
                                    }
                                    Helpers.CreateExtraThumbnailImage(_tmpCoverPath, _item.TargetPath);
                                    break;

                                case UpdateItemType.Nfo:
                                    if (_movieinfo != null)
                                    {
                                        nfoHelper.GenerateNfoFile(_item.MoviePath, _movieinfo, _movieinfo.MediaInfo != null ? _movieinfo.MediaInfo : null);
                                    }
                                    break;

                                case UpdateItemType.ImagesExport:
                                    Executor _executor = new Executor(_item.MoviePath);
                                    // make sure the images are extracted to their temp locations (as maybe no sheet needs to be generated, only export is wanted
                                    ExtractImagesIfNeeded.Invoke();
                                    // export images (that are required)
                                    _executor.ExportCover(_tmpCoverPath);
                                    _executor.ExportBackdrop(_tmpBackgroundPath, MoviesheetImageType.Background);
                                    _executor.ExportBackdrop(_tmpFanart1Path, MoviesheetImageType.Fanart1);
                                    _executor.ExportBackdrop(_tmpFanart2Path, MoviesheetImageType.Fanart2);
                                    _executor.ExportBackdrop(_tmpFanart3Path, MoviesheetImageType.Fanart3);
                                    break;
                                }
                            } // foreach

                            try
                            {
                                MovieItem _movieItem = FileManager.GetMovieByFilePath(this.MoviePath);
                                _movieItem.MovieItemStatus = MovieItemStatus.Done;
                            }
                            catch (Exception ex)
                            {
                                Loggy.Logger.DebugException("Set movieitem status:", ex);
                            }
                            _man = null;
                        }
                        finally
                        {
                            Helpers.RemoveFile(_tmpCoverPath);
                            Helpers.RemoveFile(_tmpBackgroundPath);
                            Helpers.RemoveFile(_tmpFanart1Path);
                            Helpers.RemoveFile(_tmpFanart2Path);
                            Helpers.RemoveFile(_tmpFanart3Path);
                        }
                    }

                    catch (Exception ex)
                    {
                        try
                        {
                            MovieItem _movieItem = FileManager.GetMovieByFilePath(this.MoviePath);
                            FileManager.SetMovieItemStatus(_movieItem, MovieItemStatus.Exception);
                            Loggy.Logger.DebugException(string.Format("Processing file {0}", this.MoviePath), ex);
                        }
                        catch { }
                    }
                }
                finally
                {
                    if (this.DoneEvent != null)
                    {
                        this.DoneEvent.Set();
                    }
                }
            }
Esempio n. 4
0
        private bool AutoloadBackdrop(MovieSheetsGenerator generator, bool loadFromMetadata, MoviesheetsUpdateManager metadatamanager, bool doSelect,
                                      string mask, MoviesheetImageType imgType)
        {
            bool _result = false;

            // check if must populate from masked existing file
            if (doSelect && !string.IsNullOrEmpty(mask))
            {
                string _jpgPath = null;
                if (ConfigHelpers.CheckIfFileExists(MoviePath, mask, out _jpgPath))
                {
                    generator.UpdateBackdrop(imgType, _jpgPath);
                    // add it to the pool too
                    BackdropItem _item = PrepareBackdropItem(_jpgPath, false);
                    AddBackdropToLists(_item, true);
                    _result = true;
                }
            }

            // check if must populate from metadata
            if (!_result && loadFromMetadata && metadatamanager != null)
            {
                string _itemType = null;
                string _path     = null;
                switch (imgType)
                {
                case MoviesheetImageType.Background:
                    _itemType = MoviesheetsUpdateManager.BACKGROUND_STREAM_NAME;
                    _path     = generator.BackdropTempPath;
                    break;

                case MoviesheetImageType.Fanart1:
                    _itemType = MoviesheetsUpdateManager.FANART1_STREAM_NAME;
                    _path     = generator.Fanart1TempPath;
                    break;

                case MoviesheetImageType.Fanart2:
                    _itemType = MoviesheetsUpdateManager.FANART2_STREAM_NAME;
                    _path     = generator.Fanart2TempPath;
                    break;

                case MoviesheetImageType.Fanart3:
                    _itemType = MoviesheetsUpdateManager.FANART3_STREAM_NAME;
                    _path     = generator.Fanart3TempPath;
                    break;
                }

                if (!string.IsNullOrEmpty(_itemType))
                {
                    _result = metadatamanager.GetImage(_itemType, _path);
                    if (_result && File.Exists(_path))
                    {
                        generator.UpdateBackdrop(imgType, _path);
                        // add it to the pool too
                        BackdropItem _item = PrepareBackdropItem(_path, false);
                        AddBackdropToLists(_item, true);
                    }
                }
            }

            return(_result);
        }