コード例 #1
0
        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");
        }
コード例 #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);
        }
コード例 #3
0
        /// <summary>
        /// Find the available Open Subtitles subtitles for a specific movie.
        /// </summary>
        /// <param name="movieFileName">The name of the movie file.</param>
        /// <returns>Task which returns a <see cref="FindResponse"/> containing the available subtitles.</returns>
        private async Task <FindResponse> FindOpenSubtitlesByMovieAsync(string movieFileName)
        {
            await LoginOpenSubtitles();

            var findRequest = new FindRequest()
            {
                MovieHash         = MovieHasher.ComputeMovieHash(movieFileName),
                Query             = Path.GetFileNameWithoutExtension(movieFileName),
                Type              = TypeFilterEnum.All,
                Languages         = Settings.OpenSubtitles.LanguageFilter,
                HearingImpaired   = FilterEnum.Exclude,
                TrustedSources    = FilterEnum.Only,
                MachineTranslated = FilterEnum.Exclude,
                AiTranslated      = FilterEnum.Exclude,
            };

            return(await openSubtitlesApi.FindAsync(findRequest));
        }
コード例 #4
0
ファイル: SeJobExport.cs プロジェクト: hugok79/subtitleedit
        private void buttonSave_Click(object sender, EventArgs e)
        {
            var model = new SeJobModel
            {
                Version            = "1.0",
                JobId              = textBoxJobId.Text,
                JobName            = textBoxJobName.Text.Trim(),
                Message            = textBoxJobDescription.Text.Trim(),
                SubtitleFileFormat = _subtitleFormat.Name,
                SubtitleFileName   = textBoxSubtitleFileName.Text.Trim(),
                SubtitleContent    = _subtitle.ToText(_subtitleFormat),
                VideoStreamingUrl  = textBoxVideoUrl.Text.Trim(),
            };

            if (!string.IsNullOrEmpty(_videoFileName))
            {
                model.VideoHash = Path.GetFileNameWithoutExtension(WavePeakGenerator.GetPeakWaveFileName(_videoFileName));
                if (!string.IsNullOrEmpty(model.VideoStreamingUrl))
                {
                    model.VideoHash = MovieHasher.GenerateHashFromString(model.VideoStreamingUrl);
                }
            }

            if (checkBoxOriginal.Checked && _subtitleOriginal?.Paragraphs.Count > 0)
            {
                model.SubtitleFileNameOriginal = _subtitleOriginal.FileName;
                model.SubtitleContentOriginal  = _subtitleOriginal.ToText(_subtitleFormat);
            }

            if (checkBoxIncludeWaveform.Checked && _waveform?.PeakMins.Count > 0)
            {
                model.Waveform = _waveform;
            }

            if (checkBoxIncludeShotChanges.Checked && _shotChanges?.Count > 0)
            {
                model.ShotChanges = _shotChanges;
            }

            if (checkBoxIncludeBookmarks.Checked)
            {
                model.Bookmarks = new List <SeJobBookmark>();
                foreach (var p in _subtitle?.Paragraphs.Where(p => !string.IsNullOrEmpty(p.Bookmark)))
                {
                    model.Bookmarks.Add(new SeJobBookmark
                    {
                        Idx = _subtitle.GetIndex(p),
                        Txt = p.Bookmark,
                    });
                }
            }

            if (checkBoxIncludeRules.Checked)
            {
                model.Rules = new SeJobRules
                {
                    MaxNumberOfLines                    = (int)numericUpDownMaxNumberOfLines.Value,
                    SubtitleLineMaximumLength           = (int)numericUpDownSubtitleLineMaximumLength.Value,
                    SubtitleMaximumCharactersPerSeconds = numericUpDownMaxCharsSec.Value,
                    SubtitleMinimumDisplayMilliseconds  = (int)numericUpDownDurationMin.Value,
                    SubtitleMaximumDisplayMilliseconds  = (int)numericUpDownDurationMax.Value,
                    MinimumMillisecondsBetweenLines     = (int)numericUpDownMinGapMs.Value,
                    SubtitleMaximumWordsPerMinute       = numericUpDownMaxWordsMin.Value,
                    SubtitleOptimalCharactersPerSeconds = numericUpDownOptimalCharsSec.Value,
                };
            }

            using (var saveDialog = new SaveFileDialog {
                FileName = Path.GetFileNameWithoutExtension(model.SubtitleFileName), Filter = "se-job|*.se-job"
            })
            {
                if (saveDialog.ShowDialog() == DialogResult.OK)
                {
                    File.WriteAllBytes(saveDialog.FileName, SeJobHandler.SaveSeJob(model));
                    DialogResult = DialogResult.OK;
                }
            }
        }