Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***********************************************************
- ** **
- ** Codesnippets written by Madwin for MMP 2023 **
- ** **
- ** Not to be used freely. the code still has errors **
- ** It's intended to be used as starting point. **
- ** Code has not been checked and might still need **
- ** (a lot of) work. **
- ** **
- ** © MadMedia Productions 2023 **
- ** **
- ***********************************************************/
- /*
- C# class that you can use to get the URL of a video stream
- playing in a web browser:
- */
- using System;
- using System.Windows.Forms;
- namespace VideoStreamGetter
- {
- public class VideoStreamGetter
- {
- private WebBrowser webBrowser;
- public VideoStreamGetter(WebBrowser webBrowser)
- {
- this.webBrowser = webBrowser;
- this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
- }
- private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
- {
- foreach (HtmlElement videoElement in webBrowser.Document.GetElementsByTagName("video"))
- {
- string src = videoElement.GetAttribute("src");
- Console.WriteLine("Video URL: " + src);
- }
- }
- }
- }
- /*
- This class takes a WebBrowser object as a parameter in its
- constructor. It then attaches an event handler to the
- DocumentCompleted event of the web browser, which will be called
- when the web page finishes loading.
- In the DocumentCompleted event handler, the class looks for
- all video elements in the web page using the GetElementsByTagName
- method of the HtmlDocument class. For each video element found,
- it retrieves the value of the src attribute using the GetAttribute
- method of the HtmlElement class, and prints it to the console.
- To use this class, you can create an instance of it and pass
- in a WebBrowser object that you have already navigated to the
- web page containing the video stream. For example:
- */
- WebBrowser webBrowser = new WebBrowser();
- webBrowser.Navigate("https://example.com/video");
- VideoStreamGetter videoStreamGetter = new VideoStreamGetter(webBrowser);
- /*
- Note that this class assumes that there is only one video element
- in the web page. If there are multiple video elements, you will
- need to modify the code to handle them appropriately.
- Updated version of the C# class that retrieves the URL of a
- video stream playing in a WebBrowser control, this time by
- getting it from a metafile instead of directly from the video element:
- */
- using System;
- using System.Windows.Forms;
- namespace VideoStreamGetter
- {
- public class VideoStreamGetter
- {
- private WebBrowser webBrowser;
- public VideoStreamGetter(WebBrowser webBrowser)
- {
- this.webBrowser = webBrowser;
- this.webBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(DocumentCompleted);
- }
- private void DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
- {
- foreach (HtmlElement metaElement in webBrowser.Document.GetElementsByTagName("meta"))
- {
- if (metaElement.GetAttribute("name") == "twitter:player:stream")
- {
- string src = metaElement.GetAttribute("content");
- Console.WriteLine("Video URL: " + src);
- }
- }
- }
- }
- }
- /*
- This class works similarly to the previous version, but instead of
- looking for video elements, it looks for meta elements with the name
- attribute set to "twitter:player:stream". This is a common way of
- specifying a video stream URL in a web page.
- For each meta element found, the class retrieves the value of the
- content attribute using the GetAttribute method of the HtmlElement
- class, and prints it to the console.
- To use this class, you can create an instance of it and pass in a
- WebBrowser object that you have already navigated to the web page
- containing the video stream. For example:
- */
- WebBrowser webBrowser = new WebBrowser();
- webBrowser.Navigate("https://example.com/video");
- VideoStreamGetter videoStreamGetter = new VideoStreamGetter(webBrowser);
- /*
- Note that this class assumes that there is only one meta element with the
- name attribute set to "twitter:player:stream". If there are multiple such
- elements, you will need to modify the code to handle them appropriately.
- */
Advertisement
Add Comment
Please, Sign In to add comment