示例#1
0
        public override string ToText(Subtitle subtitle, string title)
        {
            if (string.IsNullOrEmpty(title))
            {
                title = "untitled";
            }
            var sb = new StringBuilder("{ \"jobName\": \"" + Json.EncodeJsonText(title) + "\", \"accountId\": \"0\", \"results\": { \"items\": [ ");

            for (var index = 0; index < subtitle.Paragraphs.Count; index++)
            {
                Paragraph p = subtitle.Paragraphs[index];
                if (index > 0)
                {
                    sb.Append(',');
                }

                sb.Append("{ \"start_time\":");
                sb.Append(p.StartTime.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(", \"end_time\":");
                sb.Append(p.EndTime.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(", \"alternatives\": [ { \"confidence\": \"1\", \"content\": \"");
                sb.Append(Json.EncodeJsonText(p.Text) + "\" } ]");
                sb.Append(",\"type\": \"pronunciation\"");
                sb.Append('}');
            }

            sb.Append("]}}");
            return(sb.ToString().Trim());
        }
        public override string ToText(Subtitle subtitle, string title)
        {
            var template = @"{
    'font_size': 0.4,
    'font_color': '#FFFFFF',
    'background_alpha': 0.5,
    'background_color': '#9C27B0',
    'Stroke': 'none',
    'body': [
      LINES
    ]
}".Replace('\'', '"');

            var sb    = new StringBuilder();
            int count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }
                sb.AppendLine();
                sb.Append("\t{ ");
                sb.Append("\"from\":" + p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture) + ", ");
                sb.Append("\"to\":" + p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture) + ", ");
                sb.Append("\"location\": 2, ");
                sb.Append("\"content\":\"" + Json.EncodeJsonText(p.Text) + "\"");
                sb.Append(" }");
                count++;
            }
            return(template.Replace("LINES", sb.ToString()).Trim());
        }
示例#3
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();

            sb.Append("{\"words\":[");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];

                //split words
                string text  = p.Text.Replace(Environment.NewLine, " ").Replace("  ", " ");
                var    words = text.Split(CharSpace, StringSplitOptions.RemoveEmptyEntries);
                var    times = GenerateTimes(words, text, p.StartTime, p.EndTime);
                for (int j = 0; j < words.Length; j++)
                {
                    sb.Append("[\"");
                    sb.Append(times[j]);
                    sb.Append("\",\"");
                    sb.Append(Json.EncodeJsonText(words[j]));
                    sb.Append("\"]");
                    sb.Append(',');
                }
                var next = subtitle.GetParagraphOrDefault(i + 1);
                if (next == null || next.StartTime.TotalMilliseconds - 200 < p.EndTime.TotalMilliseconds)
                {
                    sb.Append("[\"");
                    sb.Append(Convert.ToInt64(p.EndTime.TotalMilliseconds));
                    sb.Append("\",\"");
                    sb.Append("\"]");
                    sb.Append(',');
                }
            }
            return(sb.ToString().Trim().TrimEnd(',') + "],\"paragraphs\":[],\"speakers\":{}}");
        }
示例#4
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            for (int index = 0; index < subtitle.Paragraphs.Count;)
            {
                Paragraph p = subtitle.Paragraphs[index];
                index++;
                if (count > 0)
                {
                    sb.Append(',');
                }
                sb.Append("{\"index\":");
                sb.Append(index);
                sb.Append(",\"start\":\"");
                sb.Append(p.StartTime);
                sb.Append("\",\"end\":\"");
                sb.Append(p.EndTime);
                sb.Append("\",\"text\": [");
                if (!string.IsNullOrEmpty(p.Text))
                {
                    foreach (var line in p.Text.SplitToLines())
                    {
                        sb.Append("\"");
                        sb.Append(Json.EncodeJsonText(line));
                        sb.Append("\"");
                    }
                }
                sb.Append("]}");
                count++;
            }
            sb.Append(']');
            return(sb.ToString().Trim());
        }
示例#5
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder("{\"vostf\":[");
            int count = 0;

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }

                sb.Append("{\"startTime\":");
                sb.Append(p.StartTime.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"endTime\":");
                sb.Append(p.EndTime.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"positionAlign\":");
                sb.Append("\"middle\"");
                sb.Append(",\"lineAlign\":");
                sb.Append("\"start\"");
                sb.Append(",\"text\":\"");
                sb.Append(Json.EncodeJsonText(p.Text));
                sb.Append("\"}");
                count++;
            }
            sb.Append("]}");
            return(sb.ToString().Trim());
        }
示例#6
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }

                sb.Append("{\"duration\":");
                sb.Append(p.Duration.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"content\":\"");
                sb.Append(Json.EncodeJsonText(p.Text) + "\"");
                sb.Append(",\"startOfParagraph\":false");
                sb.Append(",\"startTime\":");
                sb.Append(p.StartTime.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append('}');
                count++;
            }
            sb.Append(']');
            return(sb.ToString().Trim());
        }
示例#7
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            string guid          = Guid.NewGuid().ToString();
            string segmentTypeId = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 24);

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                string id = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, 24);
                if (count > 0)
                {
                    sb.Append(',');
                }
                sb.Append("{\"hitType\":\"tag\",\"subTrack\":null,\"tags\":[],\"track\":\"Closed Captioning\",\"startTime\":");
                sb.Append(p.StartTime.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"guid\":\"" + guid + "\",\"segmentTypeId\":\"" + segmentTypeId + "\",\"endTime\":");
                sb.Append(p.EndTime.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"id\":\"" + id + "\",\"metadata\":{\"Text\":\"");
                sb.Append(Json.EncodeJsonText(p.Text) + "\"");

                sb.Append(",\"ID\":\"\",\"Language\":\"en\"}}");
                count++;
            }
            sb.Append(']');
            return(sb.ToString().Trim());
        }
示例#8
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }
                sb.AppendLine();
                sb.Append("{");
                sb.Append("\"endTime\": { \"f\": " + MillisecondsToFramesMaxFrameRate(p.EndTime.Milliseconds) + ", \"h\": " + p.EndTime.Hours + ", \"m\": " + p.EndTime.Minutes + ", \"s\": " + p.EndTime.Seconds + " },");
                sb.Append("\"id\":\"" + GenerateId() + "\",");
                sb.Append("\"isSequelToNextSubtitle\":false,");
                sb.Append("\"isSequelToPrevSubtitle\":false,");
                sb.Append("\"isStartingNewSmartText\":false,");
                sb.Append("\"speechOptions\":null,");
                sb.Append("\"startTime\": { \"f\": " + MillisecondsToFramesMaxFrameRate(p.StartTime.Milliseconds) + ", \"h\": " + p.StartTime.Hours + ", \"m\": " + p.StartTime.Minutes + ", \"s\": " + p.StartTime.Seconds + " },");
                sb.Append("\"text\":\"" + Json.EncodeJsonText(p.Text) + "\"");
                sb.Append("}");
                count++;
            }
            sb.AppendLine();
            sb.Append(']');
            return(sb.ToString().Trim());
        }
示例#9
0
        private string GetTextArray(string text)
        {
            var sb = new StringBuilder();

            foreach (var line in text.SplitToLines())
            {
                sb.Append("\"" + Json.EncodeJsonText(line) + "\", ");
            }

            return(sb.ToString().Trim().TrimEnd(','));
        }
示例#10
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var language = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
            var userId   = "0";
            var duration = "0";
            var last     = subtitle.Paragraphs.LastOrDefault();

            if (last != null)
            {
                duration = (last.StartTime.TotalSeconds + last.Duration.TotalSeconds).ToString(CultureInfo.InvariantCulture);
            }

            var createdAt = "";
            var id        = "0";
            var sb        = new StringBuilder();

            sb.AppendLine("{" + Environment.NewLine +
                          "  \"job\": {" + Environment.NewLine +
                          "    \"lang\": \"" + language + "\"," + Environment.NewLine +
                          "    \"user_id\": \"" + userId + "\"," + Environment.NewLine +
                          "    \"name\": \"" + Json.EncodeJsonText(title) + "\"," + Environment.NewLine +
                          "    \"duration\": \"" + duration + "\"," + Environment.NewLine +
                          "    \"created_at\": \"" + createdAt + "\"," + Environment.NewLine +
                          "    \"id\": \"" + id + "\"," + Environment.NewLine +
                          "  }," + Environment.NewLine +
                          "  \"speakers\": [");

            int count = 0;

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.AppendLine(", ");
                }

                sb.AppendLine("  {");
                sb.AppendLine("    \"duration\": \"" + p.Duration.TotalSeconds.ToString(CultureInfo.InvariantCulture) + "\",");
                sb.AppendLine("    \"confidence\": null,");
                sb.AppendLine("    \"name\": \"" + Json.EncodeJsonText(p.Text) + "\",");
                sb.AppendLine("    \"time\": \"" + p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture) + "\"");
                sb.Append("  }");
                count++;
            }
            sb.AppendLine();
            sb.AppendLine("  ],");
            sb.AppendLine("  \"format\": \"1.0\"");
            sb.AppendLine("}");
            return(sb.ToString().Trim());
        }
        public override string ToText(Subtitle subtitle, string title)
        {
            var data = new TwentyThreeJson().ToText(subtitle, title);

            var encodedData = Json.EncodeJsonText(data
                                                  .Replace(Environment.NewLine, " ")
                                                  .Replace("\t", " ")
                                                  );

            var sb = new StringBuilder();

            sb.AppendLine("{");
            sb.AppendLine($"  \"data\": \"{encodedData}\"");
            sb.AppendLine("}");
            return(sb.ToString().Trim());
        }
        public override string ToText(Subtitle subtitle, string title)
        {
            var data = new SubRip().ToText(subtitle, title);

            data = data.Replace("\t", " ");
            var encodedData = Json.EncodeJsonText(data);

            encodedData = encodedData.Replace("<br />", "\\n");

            var sb = new StringBuilder();

            sb.AppendLine("{");
            sb.AppendLine($"  \"data\": {{ \"websrt\" : \"{encodedData}\" }} ");
            sb.AppendLine("}");
            return(sb.ToString().Trim());
        }
示例#13
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();

            sb.Append("{\"start\": [");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                sb.Append(p.StartTime.TotalMilliseconds);
                if (i < subtitle.Paragraphs.Count - 1)
                {
                    sb.Append(',');
                }
            }
            sb.AppendLine("],");

            sb.Append("{\"end\": [");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                sb.Append(p.EndTime.TotalMilliseconds);
                if (i < subtitle.Paragraphs.Count - 1)
                {
                    sb.Append(',');
                }
            }
            sb.AppendLine("],");

            sb.Append("\"text\": [");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                sb.Append('"');
                sb.Append(Json.EncodeJsonText(Utilities.UnbreakLine(p.Text)));
                sb.Append('"');
                if (i < subtitle.Paragraphs.Count - 1)
                {
                    sb.Append(',');
                }
            }
            sb.Append("]");
            sb.Append('}');
            return(sb.ToString().Trim());
        }
示例#14
0
        public override string ToText(Subtitle subtitle, string title)
        {
            Guid subtitleId;

            if (subtitle.Header == null || !Guid.TryParse(subtitle.Header, out subtitleId))
            {
                subtitleId = Guid.NewGuid();
            }

            var sb = new StringBuilder();

            sb.Append("{\"header\": { \"subtitleId\": \"" + subtitleId + "\" },");
            sb.Append("\"subtitles\": [");

            int count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }

                sb.Append("{\"start\":");
                sb.Append(p.StartTime.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"end\":");
                sb.Append(p.EndTime.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));

                sb.Append(",\"text\":\"");
                sb.Append(Json.EncodeJsonText(p.Text));
                sb.Append("\"}");

                if (!string.IsNullOrWhiteSpace(p.Extra))
                {
                    sb.Append(",\"comment\":\"");
                    sb.Append(Json.EncodeJsonText(p.Extra));
                    sb.Append("\"}");
                }

                count++;
            }
            sb.Append("]}");
            return(sb.ToString().Trim());
        }
示例#15
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder("{" + Environment.NewLine + "  \"events\": [ ");
            int count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                sb.AppendLine(count > 0 ? ", {" : "  {");
                sb.AppendLine("    \"tStartMs\": " + p.StartTime.TotalMilliseconds.ToString(CultureInfo.InvariantCulture) + ",");
                sb.AppendLine("    \"dDurationMs\": " + p.Duration.TotalMilliseconds.ToString(CultureInfo.InvariantCulture) + ",");
                sb.AppendLine("    \"segs\": [ {");
                sb.AppendLine("      \"utf8\": \"" + Json.EncodeJsonText(p.Text).Replace("<br />", "\\n") + "\"");
                sb.AppendLine("    } ]");
                sb.Append("  }");
                count++;
            }
            sb.AppendLine("]");
            sb.AppendLine("}");
            return(sb.ToString().Trim());
        }
示例#16
0
        public override string ToText(Subtitle subtitle, string title)
        {
            string languageCode;
            string languageDisplayName;

            try
            {
                languageCode = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
                var ci = new CultureInfo(languageCode);
                languageDisplayName = ci.DisplayName;
            }
            catch
            {
                languageCode        = "en";
                languageDisplayName = "English";
            }

            var sb    = new StringBuilder("{\"subtitle\":[{\"captions\":[");
            int count = 0;

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }

                sb.Append("{\"duration\":");
                sb.Append(p.Duration.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"content\":\"");
                sb.Append(Json.EncodeJsonText(p.Text) + "\"");
                sb.Append(",\"startOfParagraph\":true");
                sb.Append(",\"startTime\":");
                sb.Append(p.StartTime.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append('}');
                count++;
            }
            sb.Append("],\"lang\":\"" + languageCode + "\", \"langDisplayName\":\"" + languageDisplayName + "\"}],\"introDuration\":0}");
            return(sb.ToString().Trim());
        }
示例#17
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }
                sb.Append("{\"start_millis\":");
                sb.Append(p.StartTime.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"end_millis\":");
                sb.Append(p.EndTime.TotalMilliseconds.ToString(System.Globalization.CultureInfo.InvariantCulture));

                sb.Append(",\"start_of_paragraph\":");
                sb.Append(p.StartOfParagraph.ToString(System.Globalization.CultureInfo.InvariantCulture));

                sb.Append(",\"start_of_statement\":");
                sb.Append(p.StartOfStatement.ToString(System.Globalization.CultureInfo.InvariantCulture));

                sb.Append(",\"isolate_mean\":");
                sb.Append(p.IsolateMean.ToString(System.Globalization.CultureInfo.InvariantCulture));

                sb.Append(",\"end_of_statement\":");
                sb.Append(p.EndOfStatement.ToString(System.Globalization.CultureInfo.InvariantCulture));

                sb.Append(",\"end_of_paragraph\":");
                sb.Append(p.EndOfParagraph.ToString(System.Globalization.CultureInfo.InvariantCulture));


                sb.Append(",\"text\":\"");
                sb.Append(Json.EncodeJsonText(p.Text));
                sb.Append("\"}");
                count++;
            }
            sb.Append(']');
            return(sb.ToString().Trim());
        }
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();

            sb.AppendLine("{" + Environment.NewLine + "\t\"subtitles\": [");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                if (i > 0)
                {
                    sb.AppendLine("\t,");
                }

                sb.AppendLine("\t{");
                sb.AppendLine("\t\t\"text\": [");
                Paragraph p     = subtitle.Paragraphs[i];
                var       lines = p.Text.SplitToLines();
                for (int j = 0; j < lines.Count; j++)
                {
                    sb.Append("\t\t");
                    sb.Append('"');
                    sb.Append(Json.EncodeJsonText(lines[j]));
                    sb.Append('"');
                    if (j < lines.Count - 1)
                    {
                        sb.Append(',');
                    }
                    sb.AppendLine();
                }
                sb.AppendLine("\t\t],");

                sb.AppendLine($"\t\t\"timestamp_begin\": {p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture)}, ");
                sb.AppendLine($"\t\t\"timestamp_end\": {p.EndTime.TotalSeconds.ToString(CultureInfo.InvariantCulture)}");
                sb.AppendLine("\t}");
            }

            sb.AppendLine("\t]");
            sb.Append("}");
            return(sb.ToString().Trim());
        }
示例#19
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            foreach (Paragraph p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }

                sb.Append("{\"displayTimeOffset\":");
                sb.Append(p.StartTime.TotalSeconds.ToString(System.Globalization.CultureInfo.InvariantCulture));
                sb.Append(",\"text\":\"");
                sb.Append(Json.EncodeJsonText(p.Text));
                sb.Append("\"}");
                count++;
            }
            sb.Append(']');
            return(sb.ToString().Trim());
        }
示例#20
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder("{ \"captionGroups\": [");
            int count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(", ");
                }
                sb.Append("{ \"t\":\"");
                sb.Append(Json.EncodeJsonText(p.Text.Replace(Environment.NewLine, "\\n")));
                sb.Append("\", \"s\":");
                sb.Append(p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                sb.Append(", \"e\":");
                sb.Append(p.EndTime.TotalSeconds.ToString(CultureInfo.InvariantCulture));
                sb.Append(" }");
                count++;
            }
            sb.Append("]}");
            return(sb.ToString().Trim());
        }
示例#21
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }
                count++;
                sb.AppendLine();
                sb.AppendLine("  {");
                sb.AppendLine($"    \"s\": {p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture)},");
                sb.AppendLine($"    \"d\": {p.Duration.TotalSeconds.ToString(CultureInfo.InvariantCulture)},");
                sb.AppendLine($"    \"n\": \"{Json.EncodeJsonText(p.Text, "\\n")}\"");
                sb.Append("  }");
            }
            sb.AppendLine();
            sb.Append(']');
            return(sb.ToString().Trim());
        }
示例#22
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"{
    'results': [
        {
            'alternatives': [
                {
                    'confidence': 1.0,
                    'transcript': '...', 
                    'words': [".Replace('\'', '"'));
            var count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }

                count++;
                sb.AppendLine();
                sb.AppendLine("                        {");
                sb.AppendLine($"                            \"startTime\": {p.StartTime.TotalSeconds.ToString(CultureInfo.InvariantCulture)},");
                sb.AppendLine($"                            \"endTime\": {p.EndTime.TotalSeconds.ToString(CultureInfo.InvariantCulture)},");
                sb.AppendLine($"                            \"word\": \"{Json.EncodeJsonText(p.Text, "\\n")}\"");
                sb.Append("                        }");
            }
            sb.Append(@"
                    ]
                } 
            ]
        }
    ]
}");
            return(sb.ToString().Trim());
        }
示例#23
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb    = new StringBuilder(@"[");
            int count = 0;

            foreach (var p in subtitle.Paragraphs)
            {
                if (count > 0)
                {
                    sb.Append(',');
                }
                count++;
                sb.AppendLine();
                sb.Append("{");
                sb.Append("\"text\": [ ");
                var list = p.Text.SplitToLines();
                for (var index = 0; index < list.Count; index++)
                {
                    var line = list[index];
                    if (index > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append($"\"{Json.EncodeJsonText(line)}\"");
                }

                sb.Append(" ], ");
                sb.Append($"\"index\":{count},");
                sb.Append($"\"start\": {p.StartTime.TotalMilliseconds}, ");
                sb.Append($"\"end\": {p.EndTime.TotalMilliseconds} ");
                sb.Append("}");
            }
            sb.AppendLine();
            sb.Append(']');
            return(sb.ToString().Trim());
        }
示例#24
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var language = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
            var sb       = new StringBuilder();
            var header   = @"
{
    'SubtitleLanguages': [
        {
            'IsForced': false,
            'ClassName': '[LANGUAGE_CODE]',
            'Name': '[LANGUAGE_ENGLISH]',
            'NativeName': '[LANGUAGE_NATIVE]',
            'SubtitleItems': ["
                           .Replace('\'', '"')
                           .Replace("[LANGUAGE_CODE]", language);

            try
            {
                var ci = new CultureInfo(language);
                header = header.Replace("[LANGUAGE_ENGLISH]", ci.EnglishName);
                header = header.Replace("[LANGUAGE_NATIVE]", ci.NativeName);
            }
            catch
            {
                header = header.Replace("[LANGUAGE_ENGLISH]", "unknown");
                header = header.Replace("[LANGUAGE_NATIVE]", "unknown");
            }

            sb.AppendLine(header);

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                if (i > 0)
                {
                    sb.AppendLine("\t\t,");
                }

                sb.AppendLine("\t\t{");
                sb.AppendLine("\t\t\t\"TextLines\": [");
                Paragraph p     = subtitle.Paragraphs[i];
                var       lines = p.Text.SplitToLines();
                for (int j = 0; j < lines.Count; j++)
                {
                    sb.Append("\t\t\t");
                    sb.Append('"');
                    sb.Append(Json.EncodeJsonText(lines[j]));
                    sb.Append('"');
                    if (j < lines.Count - 1)
                    {
                        sb.Append(',');
                    }
                    sb.AppendLine();
                }
                sb.AppendLine("\t\t\t],");

                sb.AppendLine($"\t\t\t\"ClassName\": \"{language}\", ");
                sb.AppendLine($"\t\t\t\"ShowTime\": {p.StartTime.TotalMilliseconds}, ");
                sb.AppendLine($"\t\t\t\"HideTime\": {p.EndTime.TotalMilliseconds}");
                sb.AppendLine("\t\t}");
            }

            sb.Append(@"
            ],
            'ReturnCode': {
                'Id': 1,
                'Code': 'SUCCESS'
            }
        }
    ]
}").Replace('\'', '"');

            return(sb.ToString().Trim());
        }
示例#25
0
        public override string ToText(Subtitle subtitle, string title)
        {
            var sb = new StringBuilder();

            sb.Append("{\"text_tees\":[");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p = subtitle.Paragraphs[i];
                sb.Append(p.StartTime.TotalMilliseconds);
                sb.Append(',');
                sb.Append(p.EndTime.TotalMilliseconds);
                if (i < subtitle.Paragraphs.Count - 1)
                {
                    sb.Append(',');
                }
            }
            sb.Append("],");

            sb.Append("\"text_target\":[");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                sb.Append("[\"w1\",\"w3\"],[\"w1\",\"w3\"]");
                if (i < subtitle.Paragraphs.Count - 1)
                {
                    sb.Append(',');
                }
            }
            sb.Append("],");

            sb.Append("\"text_content\":[");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                sb.Append('[');
                Paragraph p     = subtitle.Paragraphs[i];
                var       lines = p.Text.Replace(Environment.NewLine, "\n").Split('\n');
                for (int j = 0; j < lines.Length; j++)
                {
                    sb.Append('"');
                    sb.Append(Json.EncodeJsonText(lines[j]));
                    sb.Append('"');
                    if (j < lines.Length - 1)
                    {
                        sb.Append(',');
                    }
                }
                sb.Append("],");
                if (i < subtitle.Paragraphs.Count - 1)
                {
                    sb.Append("[\"\",\"\"],");
                }
                else
                {
                    sb.Append("[\"\",\"\"]");
                }
            }
            sb.Append("],");

            sb.Append("\"text_styles\":[");
            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                sb.Append("[\"s1\",\"s2\"],[\"s1\",\"s2\"]");
                if (i < subtitle.Paragraphs.Count - 1)
                {
                    sb.Append(',');
                }
            }
            sb.Append("],");

            sb.Append("\"timerange\":[");
            Paragraph timerageP = subtitle.GetParagraphOrDefault(0);

            if (timerageP == null)
            {
                sb.Append('0');
            }
            else
            {
                sb.Append(timerageP.StartTime.TotalMilliseconds);
            }

            sb.Append(',');
            timerageP = subtitle.GetParagraphOrDefault(subtitle.Paragraphs.Count - 1);
            if (timerageP == null)
            {
                sb.Append('0');
            }
            else
            {
                sb.Append(timerageP.EndTime.TotalMilliseconds);
            }

            sb.Append(']');

            sb.Append('}');

            return(sb.ToString().Trim());
        }