private async void LoadCC_Tapped(object sender, TappedRoutedEventArgs e) { var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/secondCC.srt")); if (file == null) { return; } try { Stream stream = await file.OpenStreamForReadAsync(); var parser = new SubParser(); var fileName = Path.GetFileName(file.Path); SubtitleEncoding Subencoding = SubtitleEncodingHelper.GetSubtitleEncoding(stream); Encoding encoding = new UTF8Encoding(); if (Subencoding == SubtitleEncoding.ASCII) { encoding = new ASCIIEncoding(); } else if (Subencoding == SubtitleEncoding.Unicode) { encoding = new UnicodeEncoding(); } else if (Subencoding == SubtitleEncoding.UTF8) { encoding = new UTF8Encoding(); } else if (Subencoding == SubtitleEncoding.Windows1256) { encoding = new CustomCP1256Encoding(); } else if (Subencoding == SubtitleEncoding.UTF7) { encoding = new UTF7Encoding(); } else if (Subencoding == SubtitleEncoding.UTF32) { encoding = Encoding.UTF32; } else if (Subencoding == SubtitleEncoding.BigEndianUnicode) { encoding = Encoding.BigEndianUnicode; } var mostLikelyFormat = parser.GetMostLikelyFormat(fileName, stream, encoding); Debug.WriteLine("mostLikelyFormat: " + mostLikelyFormat.Name); SubtitleList = parser.ParseStream(await file.OpenStreamForReadAsync(), encoding, mostLikelyFormat); dt.Start(); } catch (Exception ex) { } }
public void Throw_on_parse() { foreach (var filePath in TestFiles.InvalidFiles) { var fileName = Path.GetFileName(filePath); using (var fileStream = File.OpenRead(filePath)) { var mostLikelyFormat = parser.GetMostLikelyFormat(fileName); Assert.Throws <FormatException>(() => parser.ParseStream(fileStream, Encoding.UTF8, mostLikelyFormat)); } } }
public void Parse_successfully() { foreach (var filePath in TestFiles.ValidFiles) { var fileName = Path.GetFileName(filePath); using (var fileStream = File.OpenRead(filePath)) { var mostLikelyFormat = parser.GetMostLikelyFormat(fileName); _ = parser.ParseStream(fileStream, Encoding.UTF8, mostLikelyFormat); } } }
async public void ImportSubtitle(StorageFile file) { try { if (file == null) { return; } Stream stream = await file.OpenStreamForReadAsync(); var parser = new SubParser(); var fileName = Path.GetFileName(file.Path); SubtitleEncoding Subencoding = HelperUP.GetSubtitleEncoding(stream); Encoding encoding = new UTF8Encoding(); if (Subencoding == SubtitleEncoding.ASCII) { encoding = new ASCIIEncoding(); } else if (Subencoding == SubtitleEncoding.Unicode) { encoding = new UnicodeEncoding(); } else if (Subencoding == SubtitleEncoding.UTF8) { encoding = new UTF8Encoding(); } else if (Subencoding == SubtitleEncoding.Windows1256) { encoding = new CustomCP1256Encoding(); } else if (Subencoding == SubtitleEncoding.UTF7) { encoding = new UTF7Encoding(); } else if (Subencoding == SubtitleEncoding.UTF32) { encoding = Encoding.UTF32; } else if (Subencoding == SubtitleEncoding.BigEndianUnicode) { encoding = Encoding.BigEndianUnicode; } var mostLikelyFormat = parser.GetMostLikelyFormat(fileName, stream, encoding); HelperUP.Output("mostLikelyFormat: " + mostLikelyFormat.Name); SubtitleList = parser.ParseStream(await file.OpenStreamForReadAsync(), encoding, mostLikelyFormat); dt.Start(); } catch (Exception ex) { HelperUP.Output("ImportSubtitle ex: " + ex.Message); } }