コード例 #1
0
        public string GetImdbIdByMovieHash(string movieFilename)
        {
            string _result = null;

            if (FileManager.DisableOpenSubtitles)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(movieFilename) && File.Exists(movieFilename) && m_osdbProxy != null && m_Token != null)
            {
                subInfo[] subs = new subInfo[1];
                subs[0]               = new subInfo();
                subs[0].imdbid        = string.Empty;
                subs[0].sublanguageid = "";
                subs[0].moviehash     = GetMovieHash(movieFilename);
                subs[0].moviebytesize = new FileInfo(movieFilename).Length.ToString();
                subs[0].query         = string.Empty;

                subrt subrt = null;
                try
                {
                    subrt = m_osdbProxy.SearchSubtitles(m_Token, subs);
                }
                catch { }
                if (subrt != null && subrt.data.Length != 0)
                {
                    _result = "tt" + subrt.data[0].IDMovieImdb.PadLeft(7, '0');
                }
            }
            return(_result);
        }
コード例 #2
0
        private subrt DoSearch(string movieFilename, string sumCD, string language, string imdbid, string query, OSSearchType searchType)
        {
            subrt _result = null;

            if (!string.IsNullOrEmpty(movieFilename) && File.Exists(movieFilename) && m_osdbProxy != null && m_Token != null)
            {
                subInfo[] subs = new subInfo[1];
                subs[0] = new subInfo();
                subs[0].sublanguageid = language;

                switch (searchType)
                {
                case OSSearchType.MovieHashAndSize:
                    subs[0].moviehash     = GetMovieHash(movieFilename);
                    subs[0].moviebytesize = new FileInfo(movieFilename).Length.ToString();
                    subs[0].imdbid        = string.Empty;
                    subs[0].query         = string.Empty;
                    break;

                case OSSearchType.IMDbId:
                    subs[0].moviehash     = string.Empty;
                    subs[0].moviebytesize = string.Empty;
                    subs[0].imdbid        = string.IsNullOrEmpty(imdbid) ? string.Empty : imdbid;
                    subs[0].query         = string.Empty;
                    break;

                case OSSearchType.Query:
                    subs[0].moviehash     = string.Empty;
                    subs[0].moviebytesize = string.Empty;
                    subs[0].imdbid        = string.Empty;
                    subs[0].query         = string.IsNullOrEmpty(query) ? string.Empty : query;
                    break;

                default:
                    break;
                }

                try
                {
                    _result = m_osdbProxy.SearchSubtitles(m_Token, subs);
                }
                catch { }
            }

            return(_result);
        }
コード例 #3
0
        public bool GetSubtitle(string movieFilename, string sumCD, string language, string imdbid, string query)
        {
            bool _result = false;

            imdbid = FixImdbId(imdbid);

            if (FileManager.DisableOpenSubtitles)
            {
                return(false);
            }

            if (m_Token == null)
            {
                m_Token = Login();
            }

            if (!string.IsNullOrEmpty(movieFilename) && File.Exists(movieFilename) && m_osdbProxy != null && m_Token != null)
            {
                // search by moviehash and size
                subrt subrt = DoSearch(movieFilename, sumCD, language, imdbid, query, OSSearchType.MovieHashAndSize);
                if (subrt == null)
                {
                    // search by imdbid (if any)
                    subrt = DoSearch(movieFilename, sumCD, language, imdbid, query, OSSearchType.IMDbId);
                    if (subrt == null)
                    {
                        // search by keywords (if any)
                        subrt = DoSearch(movieFilename, sumCD, language, imdbid, query, OSSearchType.Query);
                    }
                }

                if (subrt != null && subrt.data != null && subrt.data.Length != 0)
                {
                    BindingList <subRes> _results = new BindingList <subRes>(subrt.data);
                    subRes _winner = null;
                    BindingList <subRes> _candidates = new BindingList <subRes>();
                    foreach (subRes _subRes in _results)
                    {
                        if (_subRes.SubSumCD == sumCD)
                        {
                            _candidates.Add(_subRes);
                        }
                    }
                    // if the candidates list has only one match, declare it a winner - TOO DANGEROUS
                    //if (_candidates.Count == 1)
                    //{
                    //    _winner = _candidates[0];
                    //}
                    // several candidates available => must show dialog and ask user to choose (if application wants this)
                    if (_winner == null && _candidates.Count >= 1 && NeedUserConfirmation != null)
                    {
                        // ask user
                        _winner = NeedUserConfirmation(_candidates);
                    }
                    if (_winner != null)
                    {
                        subdata _subdata = null;
                        try
                        {
                            _subdata = m_osdbProxy.DownloadSubtitles(m_Token, new string[] { _winner.IDSubtitleFile });
                        }
                        catch { }
                        if (_subdata != null)
                        {
                            foreach (subtitle _subtitle in _subdata.data)
                            {
                                if (_winner.IDSubtitleFile == _subtitle.idsubtitlefile)
                                {
                                    string _targetName = Path.ChangeExtension(movieFilename, Path.GetExtension(_winner.SubFileName));
                                    byte[] _data       = DecodeAndDecompress(_subtitle.data);
                                    // maybe check here if subtitle exists...
                                    SaveSubtitle(_targetName, true, _data);
                                    _data   = null;
                                    _result = true;
                                }
                            }
                        }
                    }
                }
            }
            return(_result);
        }