Пример #1
0
 private void ImportBackground(MovieSheetsGenerator generator, MoviesheetsUpdateManager metadatamanager)
 {
     if (!FileManager.Configuration.Options.MovieSheetsOptions.DoNotAutopopulateBackdrop)
     {
         bool _backgrDone = AutoloadBackdrop(generator, FileManager.Configuration.Options.MovieSheetsOptions.AutopopulateFromMetadata,
                                             metadatamanager,
                                             FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanartjpgAsBackground,
                                             FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanartjpgAsBackgroundName,
                                             MoviesheetImageType.Background);
         if (!_backgrDone)
         {
             if (Backdrops != null && Backdrops.Count() != 0)
             {
                 //update backdrop (if no backdrop selected then choose first one)
                 if (!File.Exists(generator.BackdropTempPath))
                 {
                     string _backPath = ChooseARandomBackdrop(false);
                     if (!string.IsNullOrEmpty(_backPath))
                     {
                         generator.UpdateBackdrop(MoviesheetImageType.Background, _backPath);
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        private void RefreshMetadataPreview(string filePath)
        {
            MetadataControl.MovieSheetSmallImage.Source = null;
            MoviesheetsUpdateManager _man = MoviesheetsUpdateManager.CreateManagerFromMetadata(filePath, fsMovieFile.Filepath);

            MetadataControl.MovieSheetSmallImage.Source = Helpers.LoadImage(_man.GetPreview());
        }
Пример #3
0
        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*/ }
            }
        }
Пример #4
0
        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 { }
            }
        }
Пример #5
0
        public ImagesProcessor(string moviePath)
        {
            MoviePath = moviePath;
            IsMyOwnThumbnailFromDiskImageRequired = false;
            Backdrops    = new List <BackdropBase>();
            OwnBackdrops = new List <BackdropBase>();

            string _metadataFilename = FileManager.Configuration.GetMoviesheetMetadataPath(MoviePath, false);

            if (!string.IsNullOrEmpty(_metadataFilename) && File.Exists(_metadataFilename))
            {
                MetadataManager = MoviesheetsUpdateManager.CreateManagerForMovie(MoviePath);
            }
            string _spareMetadataFilename = FileManager.Configuration.GetParentFolderMetadataPath(MoviePath, false);

            if (!string.IsNullOrEmpty(_spareMetadataFilename) && File.Exists(_spareMetadataFilename))
            {
                SpareMetadataManager = MoviesheetsUpdateManager.CreateManagerForParentFolder(MoviePath);
            }
        }
Пример #6
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);
         }
     }
 }
Пример #7
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();
                    }
                }
            }
Пример #8
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);
        }
Пример #9
0
        private void ImportFanarts(MovieSheetsGenerator generator, MoviesheetsUpdateManager metadatamanager)
        {
            if (!FileManager.Configuration.Options.MovieSheetsOptions.DoNotAutopopulateFanart)
            {
                bool _f1done = AutoloadBackdrop(generator, FileManager.Configuration.Options.MovieSheetsOptions.AutopopulateFromMetadata,
                                                metadatamanager,
                                                FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanart1jpgAsBackground,
                                                FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanart1jpgAsBackgroundName,
                                                MoviesheetImageType.Fanart1);
                bool _f2done = AutoloadBackdrop(generator, FileManager.Configuration.Options.MovieSheetsOptions.AutopopulateFromMetadata,
                                                metadatamanager,
                                                FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanart2jpgAsBackground,
                                                FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanart2jpgAsBackgroundName,
                                                MoviesheetImageType.Fanart2);
                bool _f3done = AutoloadBackdrop(generator, FileManager.Configuration.Options.MovieSheetsOptions.AutopopulateFromMetadata,
                                                metadatamanager,
                                                FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanart3jpgAsBackground,
                                                FileManager.Configuration.Options.MovieSheetsOptions.AutoSelectFanart3jpgAsBackgroundName,
                                                MoviesheetImageType.Fanart3);


                if (Backdrops != null && Backdrops.Count() != 0)
                {
                    if (!_f1done)
                    {
                        string _s = ChooseARandomBackdrop(false);
                        if (!string.IsNullOrEmpty(_s))
                        {
                            generator.UpdateBackdrop(MoviesheetImageType.Fanart1, _s);
                        }
                    }
                    if (!_f2done)
                    {
                        string _s = null;
                        if (FileManager.Configuration.Options.GetBannerAsFanart2)
                        {
                            BackdropBase _banner = GetSpecialBackdrop(false, true);
                            if (_banner != null)
                            {
                                _s = _banner.OriginalUrl;
                            }
                        }
                        if (string.IsNullOrEmpty(_s))
                        {
                            _s = ChooseARandomBackdrop(false);
                        }
                        if (!string.IsNullOrEmpty(_s))
                        {
                            generator.UpdateBackdrop(MoviesheetImageType.Fanart2, _s);
                        }
                    }
                    if (!_f3done)
                    {
                        string _s = null;
                        if (FileManager.Configuration.Options.RetrieveEpisodeScreenshots)
                        {
                            BackdropBase _screenshot = GetSpecialBackdrop(true, false);
                            if (_screenshot != null)
                            {
                                _s = _screenshot.OriginalUrl;
                            }
                        }
                        if (string.IsNullOrEmpty(_s))
                        {
                            _s = ChooseARandomBackdrop(false);
                        }
                        if (!string.IsNullOrEmpty(_s))
                        {
                            generator.UpdateBackdrop(MoviesheetImageType.Fanart3, _s);
                        }
                    }
                }
            }
        }
Пример #10
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);
            }
        }
Пример #11
0
        public static void ProcessMovies(ObservableCollection <CollectorNode> selectedCollectors,
                                         ThumbGenMainWindow mainWindow, IList <string> rootPaths,
                                         StartActionType actionType)
        {
            CurrentSeriesHelper.Reset();

            FolderToSkip          = null;
            FolderCompleteSkipped = false;

            if (actionType == StartActionType.Unknown)
            {
                return;
            }
            m_OverwriteExisting = Configuration.Options.OverwriteExistingThumbs;
            m_Progress          = mainWindow.progressBar1;
            m_ProgressText      = mainWindow.textBlock1;
            Movies.Clear();
            mainWindow.progressListBox.DataContext = Movies;
            //(mainWindow.FindResource("MoviesCollectionView") as CollectionViewSource).Source = Movies;

            bool _aborted = false;

            m_ProgressText.Text = "Collecting movies...";
            try
            {
                ShowAdorner("Collecting movies...", false);
                Helpers.DoEvents();

                List <FileInfo> _files = null;
                if (rootPaths.Count != 0)
                {
                    mainWindow.Dispatcher.Invoke((Action) delegate
                    {
                        FilesCollector _fc = new FilesCollector();
                        _files             = new List <FileInfo>();
                        // new approach, scan the given folders fully
                        foreach (string _item in rootPaths)
                        {
                            if (Directory.Exists(_item))
                            {
                                // collect all movies
                                List <FileInfo> _tmp = _fc.CollectFiles(_item, true, false).ToList <FileInfo>();

                                if (_tmp.Count != 0)
                                {
                                    _files.AddRange(_tmp);
                                }
                            }
                            else
                            {
                                if (File.Exists(_item))
                                {
                                    _files.Add(new FileInfo(_item));
                                }
                            }
                        }
                    }, DispatcherPriority.Background);
                }
                else
                {
                    return;
                }

                switch (actionType)
                {
                case StartActionType.Process:
                case StartActionType.ProcessAutomatic:
                case StartActionType.ProcessSemiautomatic:
                case StartActionType.ProcessFeelingLucky:
                case StartActionType.GenerateRandomThumbs:
                    foreach (FileInfo _file in _files)
                    {
                        Movies.Add(new MovieItem(_file.FullName));
                        Thread.Sleep(0);
                    }
                    break;

                case StartActionType.FixNetworkShares:
                    MP4Tagger.MP4Manager.ApplyBatchFix(_files);
                    break;

                case StartActionType.UnfixNetworkShares:
                    MP4Tagger.MP4Manager.ApplyBatchUnFix(_files);
                    break;

                case StartActionType.GenerateDummyFile:
                    FileManager.GenerateDummyFiles(_files);
                    break;

                case StartActionType.UpdateMoviesheetsTemplate:
                    foreach (FileInfo _file in _files)
                    {
                        Movies.Add(new MovieItem(_file.FullName));
                        Thread.Sleep(0);
                    }
                    MoviesheetsUpdateManager.ApplyNewTemplate(_files, MoviesheetsUpdateManager.SelectedTemplates);
                    break;

                case StartActionType.CreatePlaylist:
                    foreach (FileInfo _file in _files)
                    {
                        Movies.Add(new MovieItem(_file.FullName));
                        Thread.Sleep(0);
                    }

                    ShowAdorner("Generating playlists... Please wait...", false);
                    using (Playlists.PlaylistManager _manager = new Playlists.PlaylistManager())
                    {
                        _manager.CreatePlaylists(_files, FileManager.Configuration.Options.PlaylistsJobs);
                    }

                    break;
                }
            }
            finally
            {
                HideAdorners();
            }
            if (Movies != null && Movies.Count != 0 &&
                (actionType == StartActionType.Process ||
                 actionType == StartActionType.ProcessAutomatic ||
                 actionType == StartActionType.ProcessSemiautomatic ||
                 actionType == StartActionType.ProcessFeelingLucky ||
                 actionType == StartActionType.GenerateRandomThumbs))
            {
                m_Progress.Minimum = 0;
                m_Progress.Maximum = Movies.Count;
                m_Progress.Value   = 0;

                List <BaseCollector> _collectors = new List <BaseCollector>();
                if (actionType != StartActionType.GenerateRandomThumbs)
                {
                    foreach (CollectorNode _node in selectedCollectors)
                    {
                        if (_node.Collector != null)
                        {
                            // if it is a XMLImportCollectorBase derived collector then call Load
                            XMLImportCollectorBase _xmlCol = _node.Collector as XMLImportCollectorBase;
                            if (_xmlCol != null)
                            {
                                _xmlCol.Load();
                            }

                            // check if online
                            try
                            {
                                IPHostEntry _inetServer = Dns.GetHostEntry(_node.Collector.Host.Replace("http://", String.Empty));
                                // add it if online
                                _collectors.Add(_node.Collector);
                            }
                            catch
                            {
                                MessageBox.Show(String.Format("Unable to connect to {0}.\n\nThe {1} collector will be disabled for this session.", _node.Collector.Host, _node.Collector.CollectorName), "Connection error", MessageBoxButton.OK, MessageBoxImage.Warning);
                                _node.IsSelected = false; // disable the collector
                            }
                        }
                    }
                }
                else
                {
                    //_collectors.Add(new RandomSnapshotsCollector());
                }
                CurrentCollector            = new AllProvidersCollector(_collectors);
                CurrentCollector.MainWindow = mainWindow;

                if (CurrentCollector != null)
                {
                    CurrentCollector.Processing       += new EventHandler(_collector_Processing);
                    CurrentCollector.Processed        += new EventHandler(_collector_Processed);
                    CurrentCollector.ThumbnailCreated += new EventHandler(_collector_ThumbnailCreated);
                }

                _aborted = DoProcessMovies(Movies, mainWindow, actionType);
            }

            CurrentSeriesHelper.Reset();

            m_Progress.Value = 0;

            if (!_aborted && (actionType == StartActionType.ProcessAutomatic || actionType == StartActionType.ProcessFeelingLucky))
            {
                // chkeck if there are "Not found" movies and ask user maybe he wants to reprocess them manually
                var _notFoundMovies = from c in Movies
                                      where c.MovieItemStatus == MovieItemStatus.NotFound || c.MovieItemStatus == MovieItemStatus.Exception
                                      select c;
                if (_notFoundMovies != null && _notFoundMovies.Count() != 0)
                {
                    if (MessageBox.Show(string.Format("Not found: {0} movie(s)\r\n\r\nWould you like to manually process them?", _notFoundMovies.Count()),
                                        "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
                    {
                        ObservableCollection <MovieItem> _movies = new ObservableCollection <MovieItem>(_notFoundMovies);
                        FileManager.Mode = ProcessingMode.Manual;
                        _aborted         = DoProcessMovies(_movies, mainWindow, StartActionType.Process);
                    }
                }
            }

            if (!_aborted)
            {
                m_ProgressText.Text = "Done.";
            }

            CurrentSeriesHelper.Reset();

            m_Progress.Value = 0;
        }