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; }
private bool GetSeries(string keywords) { m_Series.Clear(); MemoryStream _stream = null; XmlDocument _doc = new XmlDocument(); // if we are processing same series then use cache if (IsSameSeriesBeingProcessed()) { try { _doc.LoadXml(CurrentSeriesHelper.GetSeriesDataXML); } catch { } } else { // if u have imdbid then USE IT!! if (!string.IsNullOrEmpty(m_IMDbId)) { // sample: http://thetvdb.com/api/GetSeriesByRemoteID.php?imdbid=tt0411008 string _seriesUrl = string.Format("{0}/api/GetSeriesByRemoteID.php?imdbid={1}&language={2}", m_MirrorPath, m_IMDbId, FileManager.Configuration.Options.MovieSheetsOptions.TVShowsLanguage); _stream = SendRequest(_seriesUrl); if (_stream == null || _stream.Length == 0) { _seriesUrl = string.Format("{0}/api/GetSeriesByRemoteID.php?imdbid={1}", m_MirrorPath, m_IMDbId); _stream = SendRequest(_seriesUrl); } } else // no imdbid, use keywords { string _seriesUrl = string.Format("{0}/api/GetSeries.php?seriesname={1}&language={2}", m_MirrorPath, keywords, FileManager.Configuration.Options.MovieSheetsOptions.TVShowsLanguage); _stream = SendRequest(_seriesUrl); if (_stream == null || _stream.Length == 0) { _seriesUrl = string.Format("{0}/api/GetSeries.php?seriesname={1}", m_MirrorPath, keywords); _stream = SendRequest(_seriesUrl); } } if (_stream != null && _stream.Length > 0) { _stream.Position = 0; try { _doc.Load(_stream); _stream.Dispose(); _stream = null; } catch { } } } XmlNodeList _series = _doc.SelectNodes("//Series"); if (_series.Count != 0) { foreach (XmlNode _item in _series) { int _id = Convert.ToInt32(Helpers.GetValueFromXmlNode(_item, "seriesid")); string _title = HttpUtility.HtmlDecode(Helpers.GetValueFromXmlNode(_item, "SeriesName")); string _imdb = Helpers.GetValueFromXmlNode(_item, "IMDB_ID"); string _year = GetSeriesYear(_item); if (string.IsNullOrEmpty(_imdb) && !IsValidYear(_year)) { continue; } // if I have an imdbid and it is not matching the found one, skip this series if (!string.IsNullOrEmpty(m_IMDbId) /*&& !string.IsNullOrEmpty(_imdb)*/ && m_IMDbId.ToLowerInvariant() != _imdb.ToLowerInvariant()) { // this series does not match the provided imdbid continue; } bool _addIt = true; if (IsSameSeriesBeingProcessed()) { // if we have series data, we use it for filtering if (!string.IsNullOrEmpty(CurrentSeriesHelper.SeriesID) && (string.Compare(CurrentSeriesHelper.SeriesID, _id.ToString(), true) != 0)) { // different ID do not add it _addIt = false; } } else { // we are not anymore in the same series RootFolder, reset CurrentSeriesHelper data CurrentSeriesHelper.Reset(); // remember the new series root CurrentSeriesHelper.SeriesRootFolder = GetCurrentSeriesRootFolder(); // cache result of the current GetSeriesData CurrentSeriesHelper.GetSeriesDataXML = _doc.OuterXml.ToString(); } if (_addIt) { MovieInfo _movieInfo = GetMovieInfo(_item, _id.ToString()); if (!m_Series.ContainsKey(_id)) { TheTVDBSerieItem _new = new TheTVDBSerieItem(_id, _title, _imdb); _new.MovieInfo = _movieInfo; m_Series.Add(_id, _new); } } } } return(m_Series.Count != 0); }
private void clearSeriesCacheBtn_Click(object sender, RoutedEventArgs e) { CurrentSeriesHelper.Reset(); GC.Collect(); }