/// <summary>Creates <see cref="Subtitles" /> by opening the plain text file at the specified path.</summary> /// <remarks>The properties of the opened file are accessible with <see cref="FileProperties" />, after opening.</remarks> /// <returns>The opened lines turned into subtitles.</returns> /// <exception cref="EncodingNotSupportedException">Thrown if a detected encoding is not supported by the platform.</exception> /// <exception cref="UnknownSubtitleFormatException">Thrown if a subtitle format could not be detected.</exception> public Subtitles OpenPlain(string path, bool withCharacterNames, TimingMode timingMode, string lineSeparator) { string text = String.Empty; Encoding fileEncoding = null; SubtitleInput input = new SubtitleInput(fallbackEncoding, subtitleType); if (encoding == null) { text = input.ReadPlain(path, out fileEncoding); } else { text = input.ReadPlain(path, encoding); fileEncoding = encoding; } if (IsTextEmpty(text)) { return(EmptySubtitles(path)); } else { return(ParsedSubtitlesPlain(path, fileEncoding, text, withCharacterNames, timingMode, lineSeparator)); } }
private async ValueTask PopulateSubtitleInputsAsync( string baseFilePath, IReadOnlyList <ClosedCaptionTrackInfo> closedCaptionTrackInfos, ICollection <SubtitleInput> subtitleInputs, IProgress <double>?progress = null, CancellationToken cancellationToken = default) { var progressMuxer = progress?.Pipe(p => new ProgressMuxer(p)); var progresses = closedCaptionTrackInfos.Select(_ => progressMuxer?.CreateInput()).ToArray(); var lastIndex = 0; foreach (var(trackInfo, trackProgress) in closedCaptionTrackInfos.Zip(progresses)) { var subtitleInput = new SubtitleInput( trackInfo, $"{baseFilePath}.subtitles-{lastIndex++}.tmp" ); subtitleInputs.Add(subtitleInput); await _videoClient.ClosedCaptions.DownloadAsync( trackInfo, subtitleInput.FilePath, trackProgress, cancellationToken ); } progress?.Report(1); }
/// <summary>Creates <see cref="Subtitles" /> by opening the file at the specified path.</summary> /// <remarks>The properties of the opened file are accessible with <see cref="FileProperties" />, after opening.</remarks> /// <returns>The opened subtitles.</returns> /// <exception cref="EncodingNotSupportedException">Thrown if a detected encoding is not supported by the platform.</exception> /// <exception cref="UnknownSubtitleFormatException">Thrown if a subtitle format could not be detected.</exception> public Subtitles Open(string path) { SubtitleFormat format = null; string text = String.Empty; Encoding fileEncoding = null; if (maxFileSize != -1) { FileInfo info = new FileInfo(path); if (info.Length > maxFileSize) { throw new FileTooLargeException(String.Format("The file size ({0:n} bytes) is larger than the maximum limit ({1:n} bytes).", info.Length, maxFileSize)); } } SubtitleInput input = new SubtitleInput(fallbackEncoding, subtitleType); if (encoding == null) { text = input.Read(path, out fileEncoding, out format); } else { text = input.Read(path, encoding, out format); fileEncoding = encoding; } if (IsTextEmpty(text)) { return(EmptySubtitles(path)); } else { return(ParsedSubtitles(path, fileEncoding, format, inputFrameRate, text)); } }