private void ConvertButton_Click(object sender, EventArgs e)
 {
     if (Directory.Exists(outputFolderTextBox.Text))
     {
         logTextBox.Clear();
         SwitchUIControlsEnabled();
         WebvttSubripConverter converter = new WebvttSubripConverter();
         foreach (string inputFilePath in filesListBox.Items)
         {
             logTextBox.Text += inputFilePath + Environment.NewLine;
             try
             {
                 converter.ConvertToSubrip(inputFilePath, outputFolderTextBox.Text);
                 logTextBox.Text += Strings.convertedSuccessfully;
             }
             catch (Exception exception)
             {
                 logTextBox.Text += "Error:: " + exception.Message;
             }
             logTextBox.Text += Environment.NewLine + Environment.NewLine;
         }
         MessageBox.Show(Strings.convertingFinished, "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
         SwitchUIControlsEnabled();
     }
     else
     {
         MessageBox.Show(Strings.noOutputFolder, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#2
0
        private void WalkDirectoryTree(System.IO.DirectoryInfo root, WebvttSubripConverter converter)
        {
            System.IO.FileInfo[]      files   = null;
            System.IO.DirectoryInfo[] subDirs = null;

            try
            {
                files = root.GetFiles("*.vtt");
            }
            catch (UnauthorizedAccessException e)
            {
                MessageBox.Show(Strings.unauthorizedAccess, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            catch (System.IO.DirectoryNotFoundException e)
            {
                MessageBox.Show(Strings.noOutputFolder, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (files != null)
            {
                foreach (System.IO.FileInfo fi in files)
                {
                    logTextBox.Text += fi.FullName + Environment.NewLine;
                    try
                    {
                        converter.ConvertToSubrip(fi.FullName, root.FullName);
                        logTextBox.Text += Strings.convertedSuccessfully;
                    }
                    catch (Exception exception)
                    {
                        logTextBox.Text += "Error:: " + exception.Message;
                    }
                    logTextBox.Text += Environment.NewLine + Environment.NewLine;
                }

                subDirs = root.GetDirectories();

                foreach (System.IO.DirectoryInfo dirInfo in subDirs)
                {
                    WalkDirectoryTree(dirInfo, converter);
                }
            }
        }
示例#3
0
        static void downloadVideo(string url)
        {
            try
            {
                //make request to video page to get vhx embedded video url using login session cookie
                HttpWebRequest vhxRequest = (HttpWebRequest)WebRequest.Create(url);
                vhxRequest.Headers.Set(HttpRequestHeader.Cookie, @"_device=Windows%3AChrome%3ABtsQwYHJ8W361SIgmE5X6Q; _session=" + GsessionCookie + ";");
                HttpWebResponse vhxResponse = (HttpWebResponse)vhxRequest.GetResponse();
                var             doc         = new HtmlDocument();
                doc = new HtmlDocument();
                doc.Load(vhxResponse.GetResponseStream());
                string vhxembed = doc.DocumentNode.SelectSingleNode("//iframe").GetAttributeValue("src", null);

                //make sure filename is valid for windows.
                string videoTitle = MakeValidFileName(doc.DocumentNode.SelectSingleNode("//h1[@class='head primary site-font-primary-color site-font-primary-family margin-bottom-small collection-title video-title']//strong").InnerText);
                Console.WriteLine("Downloading; " + videoTitle);

                //get vimeo link
                HttpWebRequest  vimeoRequest  = (HttpWebRequest)WebRequest.Create(vhxembed);
                HttpWebResponse vimeoResponse = (HttpWebResponse)vimeoRequest.GetResponse();
                doc = new HtmlDocument();
                doc.Load(vimeoResponse.GetResponseStream());
                string   vhxjson   = doc.DocumentNode.SelectSingleNode("//script[contains(.,'window.OTTData')]").InnerText.Replace("window.OTTData = ", "");
                VHX.json vhxobj    = JsonConvert.DeserializeObject <VHX.json>(vhxjson);
                string   vimeoLink = vhxobj.config_url;

                //create new progress bar.
                progress = new ProgressBar();

                //get video info and final mp4 link
                Task.Run(async() =>
                {
                    using (WebClient client = new WebClient())
                    {
                        client.Headers["Referer"]       = vhxembed;
                        client.DownloadProgressChanged += wc_DownloadProgressChanged;

                        string result        = client.DownloadString(vimeoLink);
                        Vimeo.Json vimeojson = JsonConvert.DeserializeObject <Vimeo.Json>(result);

                        //check if video has subtitles, if so, download them and convert to srt file.
                        //i chose to convert them to srt simply because it seems more widely used than the original VTT or any other format.
                        //not all episodes have subtitles for reason, infact, earlier episodes seem to have subtitles
                        //and the latests episodes dont. #logic
                        if (vimeojson.request.text_tracks != null)
                        {
                            WebvttSubripConverter converter = new WebvttSubripConverter();
                            foreach (var subtrack in vimeojson.request.text_tracks)
                            {
                                using (WebClient subclient = new WebClient())
                                {
                                    String vttsub = subclient.DownloadString(subtrack.url);
                                    converter.ConvertToSubrip(vttsub, videoTitle + "." + subtrack.lang + ".srt");
                                }
                            }
                        }

                        // used to find highest quality video available. probably can be done simpler
                        double max    = vimeojson.request.files.progressive.Max(t => t.height);
                        int index     = vimeojson.request.files.progressive.FindIndex(t => t.height == max);
                        string mp4Url = vimeojson.request.files.progressive[index].url;

                        //download mp4 file with name of episode if deosnt already exist.
                        //talking of names of episodes, wtf is up with this website and there naming conventions
                        //having shit like "MSL Season 7 Episode 433V" as the public title of a video is a peciulier move to say the least.
                        //like what is that, msl?, season 7 makes sense, episode 433!!! There is not 433 episodes in season 7, and wtf is the "V" for?
                        //also. I noticed that tvdb only seems to have a half complete season one lisiting, the other seasons are blank,
                        //naming conventions like that probably dont help the matter.
                        //The closest thing this website has to actualy information about the episode is a hardcoded air date
                        //and a little bit of info about whats in the episode.  yay -_-

                        if (!File.Exists(videoTitle + ".mp4"))
                        {
                            await client.DownloadFileTaskAsync(mp4Url, videoTitle + ".mp4");
                        }
                        else
                        {
                            Console.WriteLine(videoTitle + ".mp4 already exists, skipping.");
                        }
                    }
                }).GetAwaiter().GetResult();
                Console.WriteLine();
            }
            catch (WebException ex)
            {
                errorDump(ex);
                throw;
            }
        }