示例#1
0
        public static void PopulateMyGalleryResults()
        {
            ResultsListBox.MyGalleryResults = new ObservableCollection <ResultItemBase>();
            List <FileInfo> _temp = new FilesCollector().CollectFiles(FileManager.GetGalleryFolder(), false, ResultsListBox.GalleryImagesSupported).ToList <FileInfo>();

            if (_temp != null && _temp.Count != 0)
            {
                foreach (FileInfo _info in _temp)
                {
                    ResultMovieItem _titem = new ResultMovieItem(null, Path.GetFileNameWithoutExtension(_info.Name), _info.FullName, BaseCollector.GALLERY);
                    ResultsListBox.MyGalleryResults.Add(_titem);
                }
            }
        }
示例#2
0
        private static string fileScanner(DirectoryInfo dir, string filename, bool searchAll)
        {
            string nfoExt = "nfo,txt";

            Char[]   splitters  = new Char[] { ',', ';' };
            string[] extensions = nfoExt.Split(splitters);
            string[] mask       = new string[extensions.Length];

            // combine the filename/mask
            // with the extension list to create
            // a list of files to look for
            for (int i = 0; i < extensions.Length; i++)
            {
                string ext = extensions[i].Trim();
                if (ext.Length > 1)
                {
                    mask[i] = (searchAll ? "*" : filename) + "." + ext;
                }
            }

            FilesCollector _fc = new FilesCollector();

            // iterate through each pattern and get the corresponding files
            foreach (string pattern in mask)
            {
                // if pattern is null or empty continue to next pattern
                if (string.IsNullOrEmpty(pattern))
                {
                    continue;
                }

                // Get all the files specfied by the current pattern from the directory
                FileInfo[] nfoList = dir.GetFiles(pattern.Trim());
                // get all movies in the current folder
                List <FileInfo> _movies = _fc.CollectFiles(dir.FullName, false) as List <FileInfo>;
                // If none continue to the next pattern
                if (nfoList.Length == 0)
                {
                    continue;
                }

                // iterate through the list of files and scan them
                foreach (FileInfo file in nfoList)
                {
                    // if there are more movies inside the folder then name of nfo must match the name of the movie; if only 1 movie then parse any .nfo/.txt inside the folder
                    if (_movies != null)
                    {
                        if (_movies.Count == 1)
                        {
                            // just one movie
                            if (nfoList.Length >= 1 && filename != "*")
                            {
                                // scan file and retrieve result;  if a match is found return the imdb id
                                return(parseFile(file.FullName));
                            }
                        }
                        else
                        {
                            // more movies
                            string _importNfo = FileManager.Configuration.GetMovieInfoPath(filename, false, MovieinfoType.Import);
                            //if ((nfoList.Length >= 1 && filename != "*" && string.Compare(Path.GetFileNameWithoutExtension(file.Name), Path.GetFileNameWithoutExtension(filename)) == 0))
                            if ((nfoList.Length >= 1 && filename != "*" && string.Compare(Path.GetFileNameWithoutExtension(file.Name), Path.GetFileNameWithoutExtension(_importNfo)) == 0))
                            {
                                // scan file and retrieve result;  if a match is found return the imdb id
                                return(parseFile(file.FullName));
                            }
                        }
                    }
                }
            }
            // we found nothing so return empty
            return(null);
        }
示例#3
0
        public static bool Show(Window owner, string folder, string imageUrl)
        {
            BatchApplyFolderBox _box = new BatchApplyFolderBox();

            _box.Owner = owner;
            _box.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            _box.TheFolder.Text        = string.Format(@"{0}\", folder);

            _box.PromptWatermarkText.Visibility = (owner is ResultsListBox) ? (owner as ResultsListBox).Watermark.Visibility : Visibility.Collapsed;

            AsyncImageDownloader.GetImageAsync(_box, imageUrl, SetImageData);

            bool?_res = _box.ShowDialog();

            if (_res.HasValue && _res.Value)
            {
                bool _promptUser = FileManager.Configuration.Options.AddWatermark && (bool)_box.rbManual.IsChecked;
                _box.Dispatcher.BeginInvoke((Action) delegate
                {
                    IEnumerable <FileInfo> _movies = new FilesCollector().CollectFiles(folder, false);
                    string _season = string.Empty;

                    foreach (FileInfo _movie in _movies)
                    {
                        string _destFile = Helpers.GetCorrectThumbnailPath(_movie.FullName, true);
                        if (File.Exists(_destFile) && !_box.OverwriteAllFlag)
                        {
                            continue;
                        }

                        string _text = FileManager.Configuration.Options.WatermarkOptions.Text;

                        if (!_promptUser)
                        {
                            //detect season
                            EpisodeData _epData = EpisodeData.GetEpisodeData(_movie.Name);
                            string _s           = _epData.Season;
                            _season             = string.IsNullOrEmpty(_s) ? _season : _s;
                            // detect episode
                            string _episode = _epData.Episode;
                            if (string.IsNullOrEmpty(_episode))
                            {
                                // detect Cd number
                                _episode = KeywordGenerator.ExtractCDNumber(_movie.Name);
                                if (string.IsNullOrEmpty(_episode))
                                {
                                    // default text
                                    _episode = FileManager.Configuration.Options.WatermarkOptions.Text;
                                }
                            }

                            // apply mask
                            string _mask = FileManager.Configuration.Options.BatchAutoMask;
                            if (string.IsNullOrEmpty(_mask))
                            {
                                _mask = "S$SE$E";
                            }

                            _text = _mask.Replace("$S", _season).Replace("$E", _episode).Trim();
                        }
                        else
                        {
                            InputBoxDialogResult _ibres = InputBox.Show(null, _text,
                                                                        "type text here",
                                                                        "Add custom text for " + System.IO.Path.GetFileName(_movie.FullName),
                                                                        false, false, null, false);
                            if (_ibres.SkipFolder)
                            {
                                return;
                            }
                            if (string.IsNullOrEmpty(_ibres.Keywords))
                            {
                                continue;
                            }
                            _text = _ibres.Keywords;
                        }

                        FileManager.Configuration.Options.WatermarkOptions.Text = string.IsNullOrEmpty(_text) ? FileManager.Configuration.Options.WatermarkOptions.Text : _text;

                        Helpers.CreateThumbnailImage(imageUrl, _destFile, FileManager.Configuration.Options.KeepAspectRatio);
                    }
                }, _promptUser ? DispatcherPriority.Send : DispatcherPriority.Background);
            }
            return((bool)_res);
        }
示例#4
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;
        }
示例#5
0
        public static ExternalSubtitlesInfo CollectExternalSubtitles(string movieFilename, bool doJustDetection)
        {
            ExternalSubtitlesInfo _result = new ExternalSubtitlesInfo();

            List <FileInfo> _temp = new FilesCollector().CollectFiles(Path.GetDirectoryName(movieFilename), false, SubtitlesManager.SubtitlesSupported).ToList <FileInfo>();

            if (_temp != null && _temp.Count != 0)
            {
                bool _hasIdxSub = false;
                // detect if .idx file is present
                foreach (FileInfo _info in _temp)
                {
                    if (_info.Extension == ".idx")
                    {
                        _hasIdxSub = true;
                        break;
                    }
                }

                foreach (FileInfo _info in _temp)
                {
                    // if we have an .idx file to process skip existing .sub as it does not contain a candidate sub
                    if (_hasIdxSub && _info.Extension == ".sub")
                    {
                        continue;
                    }

                    ExtSubData _data = null;
                    if (_info.Extension == ".idx")
                    {
                        // process special case: .idx/.sub
                        // try to load the file
                        string _input = File.ReadAllText(_info.FullName);
                        if (!string.IsNullOrEmpty(_input))
                        {
                            Regex _reg = new Regex("id: ([a-zA-Z]+), index:", RegexOptions.Multiline | RegexOptions.IgnoreCase);
                            foreach (Match _match in _reg.Matches(_input))
                            {
                                string _code = _match.Groups[1].Value.Trim();
                                if (!string.IsNullOrEmpty(_code) && _code.Length == 2 && !CodeExists(_code, _result.SubFiles))
                                {
                                    _data          = new ExtSubData();
                                    _data.Format   = "IDX/SUB";
                                    _data.Filename = _info.FullName;
                                    _data.TwoLetterLanguageCode = _code;
                                    _data.MovieName             = Path.GetFileNameWithoutExtension(_info.Name);
                                    if (string.Compare(_data.MovieName, Path.GetFileNameWithoutExtension(movieFilename), true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        _result.SubFiles.Add(_data);
                                        if (doJustDetection)
                                        {
                                            return(_result);
                                        }
                                    }
                                }
                            }
                        }
                        _input = null;
                    }
                    else
                    {
                        // process standard subtitles
                        // remove the extension
                        string _name = Path.GetFileNameWithoutExtension(_info.Name).ToLowerInvariant();
                        if (!string.IsNullOrEmpty(_name))
                        {
                            _data          = new ExtSubData();
                            _data.Format   = Path.GetExtension(_info.Name).Trim('.').ToUpperInvariant();
                            _data.Filename = _info.FullName;

                            // try to get the language code
                            string _code = Path.GetExtension(_name).Trim('.');
                            if (!string.IsNullOrEmpty(_code))
                            {
                                CultureInfo _ci = _code.Length == 2 ? Helpers.GetCultureInfo(_code) : Helpers.GetCultureInfoFromEnglishName(_code);
                                if (_ci != null && _ci != CultureInfo.InvariantCulture)
                                {
                                    // the file has a language code
                                    _data.TwoLetterLanguageCode = _ci.TwoLetterISOLanguageName;
                                    // what is before the language code is the moviename
                                    _data.MovieName = Path.GetFileNameWithoutExtension(_name);
                                }
                            }
                            if (string.IsNullOrEmpty(_data.MovieName))
                            {
                                // there is no language code, use the default one OR use Google Translate?
                                _data.TwoLetterLanguageCode = FileManager.Configuration.Options.MovieSheetsOptions.DefaultExternalSubtitlesLanguage;

                                // the movie file name is easy
                                _data.MovieName = Path.GetFileNameWithoutExtension(_info.Name);
                            }
                            if (string.Compare(_data.MovieName, Path.GetFileNameWithoutExtension(movieFilename), true, CultureInfo.InvariantCulture) == 0)
                            {
                                _result.SubFiles.Add(_data);
                                if (doJustDetection)
                                {
                                    return(_result);
                                }
                            }
                        }
                    }
                }
            }


            return(_result);
        }