Пример #1
0
        public MoviesheetInfo GetMetadataInfo()
        {
            MoviesheetInfo _result = null;

            if (!string.IsNullOrEmpty(TargetFilename) && File.Exists(TargetFilename))
            {
                Stream _st = ZipHelper.ExtractStreamFromZip(TargetFilename, INFO_STREAM_NAME);
                if (_st != null && _st.CanSeek)
                {
                    _st.Position = 0;
                    try
                    {
                        _result = MoviesheetInfo.LoadInfo(_st);
                    }
                    catch { }
                }
            }
            return(_result);
        }
Пример #2
0
            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();
                    }
                }
            }
Пример #3
0
        public void GenerateUpdateFile(MoviesheetsUpdateManagerParams parameters, string templateName)
        {
            /* update file
             * contains:
             *  - info
             *  - background
             *  - .nfo file
             *  - fanart1
             *  - fanart2
             *  - fanart3
             *  - cover
             */

            string _backup = null;

            try
            {
                if (!string.IsNullOrEmpty(TargetFilename) && File.Exists(TargetFilename))
                {
                    // backup current .tgmd file by renaming it to .tgmdbackup
                    _backup = Path.ChangeExtension(TargetFilename, ".tgmdbackup");
                    File.Move(TargetFilename, _backup);
                }

                // make new one
                MoviesheetInfo _info = new MoviesheetInfo();
                _info.FileVersion  = "1";
                _info.TemplateName = templateName;
                _info.MovieName    = string.IsNullOrEmpty(m_movieFilename) ? string.Empty : HttpUtility.HtmlEncode(Path.GetFileName(m_movieFilename));
                try
                {
                    _info.MovieHash = Subtitles.SubtitlesManager.GetMovieHash(m_movieFilename);
                }
                catch { }
                try
                {
                    AddPart(BACKGROUND_STREAM_NAME, parameters.BackgroundPath);
                    _info.BackgroundExtension = Path.GetExtension(parameters.BackgroundPath);
                    AddPart(COVER_STREAM_NAME, parameters.CoverPath);
                    _info.CoverExtension = Path.GetExtension(parameters.CoverPath);
                    AddPart(FANART1_STREAM_NAME, parameters.Fanart1Path);
                    _info.Fanart1Extension = Path.GetExtension(parameters.Fanart1Path);
                    AddPart(FANART2_STREAM_NAME, parameters.Fanart2Path);
                    _info.Fanart2Extension = Path.GetExtension(parameters.Fanart2Path);
                    AddPart(FANART3_STREAM_NAME, parameters.Fanart3Path);
                    _info.Fanart3Extension = Path.GetExtension(parameters.Fanart3Path);
                    AddPart(PREVIEW_STREAM_NAME, parameters.PreviewPath);
                    _info.PreviewExtension = Path.GetExtension(parameters.PreviewPath);

                    using (MemoryStream _ms = new MemoryStream())
                    {
                        parameters.nfo.Save(_ms, this.m_movieFilename, true);
                        AddPart(NFO_STREAM_NAME, _ms);
                    }
                }
                finally
                {
                    using (MemoryStream _ms = new MemoryStream())
                    {
                        _info.SaveInfo(_ms);
                        AddPart(INFO_STREAM_NAME, _ms);
                    }
                }
            }
            finally
            {
                if (_backup != null)
                {
                    // remove the old file
                    Helpers.RemoveFile(_backup);
                }
            }
        }