コード例 #1
0
ファイル: Executor.cs プロジェクト: realM4C/thumbgen
        public MovieInfo QueryIMDB(string imdbid, string keywords)
        {
            MovieInfo _temp = null;

            try
            {
                if (!string.IsNullOrEmpty(imdbid))
                {
                    //Country _country = _form.SelectedCollector != null ? _form.SelectedCollector.Country : Country.International;
                    string _country  = FileManager.Configuration.Options.IMDBOptions.CertificationCountry;
                    string _cacheKey = imdbid + _country;

                    if (ResultsListBox.IMDbMovieInfoCache.ContainsKey(_cacheKey))
                    {
                        IMDBMovieInfoCacheItem _cacheItem = ResultsListBox.IMDbMovieInfoCache[_cacheKey];
                        if (_cacheItem != null && string.Compare(_cacheItem.CountryCode, _country, true) == 0)
                        {
                            _temp = _cacheItem.MovieInfo;
                        }
                    }
                    if (_temp == null)
                    {
                        _temp = new IMDBMovieInfo().GetMovieInfo(imdbid, _country);
                        ResultsListBox.IMDbMovieInfoCache.Add(_cacheKey, new IMDBMovieInfoCacheItem(_country, _temp));
                    }
                }
            }
            catch { }

            return(_temp);
        }
コード例 #2
0
        public static ChooseMovieDialogResult GetCorrectMovie(Window owner, string keywords, string year, bool imdbSelection)
        {
            if (!string.IsNullOrEmpty(keywords))
            {
                List <MovieInfo> _list = new IMDBMovieInfo().GetMovies(keywords, year, FileManager.Configuration.Options.IMDBOptions.MaxCountResults);
                if (_list != null && _list.Count > 0)
                {
                    BindingList <MovieInfo> _candidates = new BindingList <MovieInfo>();
                    foreach (MovieInfo _movie in _list)
                    {
                        _candidates.Add(_movie);
                    }
                    return(GetCorrectMovie(owner, _candidates, keywords, imdbSelection));
                }
            }

            return(new ChooseMovieDialogResult());
        }
コード例 #3
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();
                    }
                }
            }
コード例 #4
0
        public MovieInfo GetMovieInfo(string imdbId, string countryCode)
        {
            MovieInfo _result = new MovieInfo();

            if (!string.IsNullOrEmpty(imdbId))
            {
                MovieInfo _originalInfo = new MovieInfo();
                if (this.Language != "com")
                {
                    _originalInfo = new IMDBMovieInfo("com").GetMovieInfo(imdbId, countryCode);
                }

                string _moviePage = Helpers.GetPage(string.Format("{0}/title/{1}/", m_CountryFactory.TargetHost, imdbId), null, m_CountryFactory.GetEncoding, "", true, false, m_CountryFactory.Language);
                if (!string.IsNullOrEmpty(_moviePage))
                {
                    _result.IMDBID        = imdbId;
                    _result.Name          = GetTitle(_moviePage);
                    _result.Name          = string.IsNullOrEmpty(_result.Name) ? _originalInfo.Name : _result.Name;
                    _result.OriginalTitle = GetOriginalTitle(_moviePage);
                    _result.OriginalTitle = string.IsNullOrEmpty(_result.OriginalTitle) ? (string.IsNullOrEmpty(_originalInfo.OriginalTitle) ? _result.Name : _originalInfo.OriginalTitle) : _result.OriginalTitle;
                    _result.Year          = GetYear(_moviePage);
                    _result.Year          = string.IsNullOrEmpty(_result.Year) ? _originalInfo.Year : _result.Year;
                    _result.Runtime       = GetRunTime(_moviePage);
                    _result.Runtime       = string.IsNullOrEmpty(_result.Runtime) ? _originalInfo.Runtime : _result.Runtime;

                    DateTimeFormatInfo _dtfi = new DateTimeFormatInfo()
                    {
                        DateSeparator = " ", ShortDatePattern = "dd MMMM yyyy"
                    };
                    if (string.IsNullOrEmpty(_originalInfo.ReleaseDate))
                    {
                        _result.SetReleaseDate(Helpers.GetFormattedDate(GetReleaseDate(imdbId), _dtfi));
                    }
                    else
                    {
                        _result.ReleaseDate = _originalInfo.ReleaseDate;
                    }
                    DateTime _out = DateTime.MinValue;
                    if (DateTime.TryParse(_result.ReleaseDate, out _out) && _out != DateTime.MinValue)
                    {
                        _result.ReleaseDate = Helpers.GetFormattedDate(_out);
                    }
                    _result.Rating    = GetRating(_moviePage);
                    _result.Rating    = string.IsNullOrEmpty(_result.Rating) ? _originalInfo.Rating : _result.Rating;
                    _result.MPAA      = GetMPAA(_moviePage);
                    _result.MPAA      = string.IsNullOrEmpty(_result.MPAA) ? _originalInfo.MPAA : _result.MPAA;
                    _result.Tagline   = GetTagline(_moviePage);
                    _result.Tagline   = string.IsNullOrEmpty(_result.Tagline) ? _originalInfo.Tagline : _result.Tagline;
                    _result.Metascore = GetMetascore(_moviePage);
                    _result.Metascore = string.IsNullOrEmpty(_result.Metascore) ? _originalInfo.Metascore : _result.Metascore;
                    _result.Trailer   = GetTrailerLink(_moviePage);
                    _result.Trailer   = string.IsNullOrEmpty(_result.Trailer) ? _originalInfo.Trailer : _result.Trailer;
                    if (!string.IsNullOrEmpty(_result.Trailer) && !_result.Trailer.StartsWith("http"))
                    {
                        _result.Trailer = "http://www.imdb.com" + _result.Trailer;
                    }
                    _result.Overview = GetOverview(imdbId);
                    if (string.IsNullOrEmpty(_result.Overview))
                    {
                        _result.Overview = GetPlot(_moviePage);
                    }
                    _result.Overview      = string.IsNullOrEmpty(_result.Overview) ? _originalInfo.Overview : _result.Overview;
                    _result.Genre         = GetGenres(_moviePage);
                    _result.Genre         = _result.Genre.Count == 0 ? _originalInfo.Genre : _result.Genre;
                    _result.Cast          = GetActors(_moviePage).ToTrimmedList();
                    _result.Cast          = _result.Cast.Count == 0 ? _originalInfo.Cast : _result.Cast;
                    _result.Director      = GetDirectors(_moviePage);
                    _result.Director      = _result.Director.Count == 0 ? _originalInfo.Director : _result.Director;
                    _result.Countries     = GetCountries(_moviePage);
                    _result.Countries     = _result.Countries.Count == 0 ? _originalInfo.Countries : _result.Countries;
                    _result.Certification = GetCertification(countryCode, _moviePage, imdbId);
                    _result.Certification = string.IsNullOrEmpty(_result.Certification) ? _originalInfo.Certification : _result.Certification;
                    _result.Studios       = GetCompanies(_moviePage);
                    _result.Studios       = _result.Studios.Count == 0 ? _originalInfo.Studios : _result.Studios;
                }
            }

            return(_result);
        }