public void TestValidComputeMovieHash()
        {
            var content      = "[0518/172433.716:ERROR:crash_report_database_win.cc(429)] unexpected header";
            var contentBytes = Encoding.UTF8.GetBytes(content);
            var ms           = new MemoryStream(contentBytes);

            var hash    = MovieHasher.ComputeMovieHash(ms);
            var hashHex = MovieHasher.ToHexadecimal(hash);

            Assert.AreEqual(hashHex, "c4a8fd66878c7903");
        }
Esempio n. 2
0
        public List <Subtitle> FindSubtitleByHash(string[] files)
        {
            List <Subtitle> subtitleList = null;

            try
            {
                foreach (string file in files)
                {
                    byte[] moviehash = MovieHasher.ComputeMovieHash(file);
                    string hexString = MovieHasher.ToHexadecimal(moviehash);

                    string languageCode = Language.GetLanguageCode(Properties.Settings.Default.DefaultLanguage);
                    SubtitleClient.DownloadSubtitleByHash(hexString, languageCode);   // Svi rezultati pretrage za odabrani fajl

                    FileInfo selectedFile = new FileInfo(file);

                    if (subtitleList != null && subtitleList.Count > 0)
                    {
                        if (Properties.Settings.Default.IFeelLucky) // Dohvati samo prvi rezultat
                        {
                            Subtitle subtitle = subtitleList.FirstOrDefault();
                            MapFileInfoToSubtitle(selectedFile, subtitle);
                            DownloadFirstResultOnly(subtitle);
                        }
                        else // Dohvati sve rezultate i proslijedi ih u novu formu
                        {
                            subtitleList.ForEach(item =>
                            {
                                MapFileInfoToSubtitle(selectedFile, item);
                            });

                            OnSearchResultsFound(this, new SearchResultsArgs(subtitleList, this.SubtitleClient));
                        }
                    }
                    else
                    {
                        OnSubtitlesNotFound(this, new SubtitleFoundArgs(file, new FileInfo(file)));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(subtitleList);
        }