Beispiel #1
0
    private byte[] ConvertToVttIfNeeded(byte[] srtData)
    {
        if (Encoding.ASCII.GetString(srtData).Contains("WEBVTT"))
        {
            return(srtData);
        }

        return(Encoding.ASCII.GetBytes(SubtitleConverter.ConvertSrtToVtt(Encoding.ASCII.GetString(srtData))));
    }
Beispiel #2
0
    private string ConvertToVttIfNeeded(string srtData)
    {
        if (srtData.Contains("WEBVTT"))
        {
            return(srtData);
        }

        return(SubtitleConverter.ConvertSrtToVtt(srtData));
    }
    public async Task ReturnsVttGivenSrtTest()
    {
        var srt = await TestFileHelper.BuildSrtAsync();

        var expectedVtt = await TestFileHelper.BuildVttAsync();

        var vtt = SubtitleConverter.ConvertSrtToVtt(srt);

        vtt.RemoveSpecialCharacters().ShouldBe(expectedVtt.RemoveSpecialCharacters());
    }
Beispiel #4
0
 private void Button_OK(object sender, RoutedEventArgs e)
 {
     if (inputPath == null || inputPath == "" || outputPath == null || outputPath == "")
     {
         MessageBox.Show("Selecione um VTT!");
     }
     else
     {
         SubtitleConverter subConv = new SubtitleConverter();
         subConv.ConvertSubtitle(inputPath, outputPath, cssline);
         mahouka.Content = "OK!  :v";
     }
 }
 /// <summary>
 /// Downloads a subtitle
 /// </summary>
 /// <param name="subtileUrl">The location of the subtitle</param>
 /// <param name="fileNameSub">File name to save</param>
 /// <param name="fileType">The type to convert to (null or empty to not convert)</param>
 private void DownloadSubtitle(string subtileUrl, string fileNameSub, string fileType)
 {
     using (WebClient webClient = new WebClient())
     {
         webClient.DownloadFile(new Uri(subtileUrl), fileNameSub + Path.GetExtension(subtileUrl));
     }
     if (Properties.Settings.Default.ConvertSubtitle && !string.IsNullOrEmpty(fileType))
     {
         SubtitleConverter conv = new SubtitleConverter();
         conv.EncodingRead = Encoding.UTF8;
         conv.ConvertSubtitle(fileNameSub + Path.GetExtension(subtileUrl), fileNameSub + fileType);
     }
 }
Beispiel #6
0
        public ActionResult Subtitle(string path)
        {
            if (!path.IsNullOrEmpty())
            {
                string physicalPath;
                string category;
                Global.GetPhysicalPathAndCategory(path, out physicalPath, out category);

                if (SubtitleConverter.Extract(ref path, physicalPath))
                {
                    return(Redirect(Request.GetMediaUrl(path)));
                }
            }
            return(HttpNotFound());
        }
Beispiel #7
0
        public ActionResult Play(string path, bool isAudioOnly = false)
        {
            if (!path.IsNullOrEmpty())
            {
                string physicalPath;
                string category;
                Global.GetPhysicalPathAndCategory(path, out physicalPath, out category);

                if (!physicalPath.IsNullOrEmpty())
                {
                    if (isAudioOnly && !AudioExtractor.Extract(ref path, physicalPath))
                    {
                        return(null);
                    }

                    Player player = Request.GetPlayer(path);
                    string parent = Path.GetDirectoryName(physicalPath);
                    switch (player)
                    {
                    case Player.Html5Video:
                        string[] subs = Directory.EnumerateFiles(parent, "{0}.*".FormatWith(Path.GetFileNameWithoutExtension(physicalPath)))
                                        .Where(s => SubtitleConverter.CanExtract(s))
                                        .Select(s => GetPathForUrl(s, category)).ToArray();
                        Html5VideoModel model = new Html5VideoModel {
                            Title             = Path.GetFileNameWithoutExtension(path),
                            Url               = Request.GetMediaUrl(path),
                            SubtitleLanguages = subs.ToSubtitleLanguages(),
                            Parent            = Url.Action(Global.ActionName.Index, GetPathForUrl(parent, category).GetRouteValues()),
                        };
                        FileModel[] files = GetFiles(new DirectoryInfo(parent), category);
                        int         index = Array.FindIndex(files, f => f.PathForUrl.Equals(path, StringComparison.OrdinalIgnoreCase));
                        if (index > 0)
                        {
                            model.Previous = Url.Action(Global.ActionName.Play, files[index - 1].PathForUrl.GetRouteValues());
                        }
                        if (index < (files.Length - 1))
                        {
                            model.Next = Url.Action(Global.ActionName.Play, files[index + 1].PathForUrl.GetRouteValues());
                        }
                        return(View(player.GetViewName(), playerMasterPageName, model));

                    case Player.Html5Audio:
                        return(View(player.GetViewName(), playerMasterPageName, new Html5AudioModel {
                            Title = Path.GetFileNameWithoutExtension(path),
                            Url = Request.GetMediaUrl(path),
                            Parent = Url.Action(Global.ActionName.Index, GetPathForUrl(parent, category).GetRouteValues()),
                        }));

                    case Player.Silverlight:
                    case Player.Flash:
                        return(View(player.GetViewName(), playerMasterPageName, new MediaModel {
                            Title = Path.GetFileNameWithoutExtension(path),
                            Url = Request.GetMediaUrl(path),
                        }));

                    case Player.None:
                        return(Redirect(Request.GetMediaUrl(path)));
                    }
                }
            }
            return(HttpNotFound());
        }