static void Main(string[] args) { try { var options = new SubbedOptionParser(args); if (options.ActionVerb == Verbs.Help) { options.WriteHelp(); return; } var parserFactory = new SubtitleParserFactory(); ISubtitleParser reader = parserFactory.GetReaderFor(options.InputFile); IEnumerable <ISubtitle> subs = reader.Read(options.InputFile); var subManager = new SubtitleManager(subs); switch (options.ActionVerb) { case Verbs.Extrapolate: ISubtitle targetSub = subs.FirstOrDefault(options.SubtitleSelector); subManager.Extrapolate(targetSub, options.TimeDiff); break; case Verbs.StretchBy: subManager.StretchBy(options.Factor); break; case Verbs.TransposeBy: subManager.TransposeBy(options.TimeDiff); break; } subs = subManager.Subtitles; ISubtitleParser writer = parserFactory.GetWriterFor(options.OutputFile); writer.Write(subs, options.OutputFile); } catch (Exception ex) { Console.WriteLine(ex); } }
async void LoadSubtitle(StorageFile file, Action <List <PickerItem <string, string> > > action) { if (file != null) { //var stream = (file.OpenReadAsync().AsTask().Result).AsStream(); var randomStream = await file.OpenReadAsync(); if (randomStream != null) { var stream = randomStream.AsStream(); var parser = SubtitleParserFactory.CreateParser(file.Name); if (parser != null) { try { Subtitle subtitle = parser.Parse(stream, Settings.Subtitle.DefaultCharset); //인코딩은 되었으나, 데이터를 인식할 수 없어 파싱 결과를 담을 수 없는 경우 초기화 if (subtitle != null && subtitle.EncodingResult == SubtitleEncodingResult.Success && subtitle.Languages.Count == 0) { Settings.Subtitle.DefaultCharset = CodePage.AUTO_DETECT_VALUE; subtitle = parser.Parse(stream, Settings.Subtitle.DefaultCharset); } var subtitleLanguageList = new List <PickerItem <string, string> >(); foreach (var lang in subtitle.Languages.Select(x => new PickerItem <string, string> { Key = x.LanguageClassName, Name = x.LanguageName, Payload = subtitle, Payload2 = SortOrder(subtitle.SubtitleType) })) { //System.Diagnostics.Debug.WriteLine(lang.Name + " - " + subtitle.Title); string langName = lang.Name; if (!string.IsNullOrEmpty(subtitle.Title)) { lang.Name = string.Concat <string>(new string[] { langName, " - ", subtitle.Title }); } subtitleLanguageList.Add(lang); } ; //자막 인코딩 에러 표시 if (subtitleLanguageList.Count > 0 && subtitleLanguageList.Any(x => x.Payload is Subtitle && (x.Payload as Subtitle).EncodingResult != SubtitleEncodingResult.Success)) { DispatcherHelper.CheckBeginInvokeOnUI(async() => { if (App.ContentDlgOp != null) { return; } var contentPanel = new StackPanel(); contentPanel.Children.Add( new TextBlock() { Text = ResourceLoader.GetForCurrentView().GetString("Message/Info/Encoding/Fail"), TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 12, 0, 12) }); MessageDialog contentDlg = new MessageDialog(ResourceLoader.GetForCurrentView().GetString("Message/Info/Encoding/Fail")); contentDlg.CancelCommandIndex = 0; //메세지 창 출력 await contentDlg.ShowAsync(); MessengerInstance.Send <Message>(new Message("SettingsOpened", null), TransportControlViewModel.NAME); }); } //리스트를 전달 action.Invoke(subtitleLanguageList); //MessengerInstance.Send<Message>(new Message("SubtitlesLoaded", subtitleLanguageList), TransportControlViewModel.NAME); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.StackTrace); } } } } }