2

I am looking for video files via the *.m3u4 or 8 extension, but I never get the extension?

enter image description here

Func<NameValueCollection, bool> headersProcessingFunc = new Func<NameValueCollection, bool>(ProcessHeaders);

chromiumWebBrowser1.RequestHandler = new HeadersProcessingRequestHandler(headersProcessingFunc);

private static bool ProcessHeaders(NameValueCollection headers)
{

foreach(string header in headers)
if (headers[header].Contains(".m3"))
MessageBox.Show(header + "\r\n" + headers[header]);
return true;
}

I do get other files, "content" and so on:

alt-svc
cf-cache-status
cf-ray
content-encoding
content-type
date
nel
report-to
server
vary
x-frame-options

I know this might be somewhat controversial, this post, but hey, its a Tech Question, its valid, and people deserve to know about this sort of thing, and to be able to work with it! I realise you need CefSharp to have Codecs enabled: 1 and 2 and 3

Of course, the point is to be able to use ffmpeg to get the Link and Download the Video or Audio.

Rusty Nail
  • 2,692
  • 3
  • 34
  • 55
  • What are you trying to achieve? What header are you trying to get exactly? Resources are generally identified by their Content-Type. – amaitland Jan 12 '23 at 01:00
  • 1
    The file extension is a property of the file on the file system, not something that is *in* the file. It is a hint for the OS as to which application to use when opening the file. What are you trying to create? I assume this is a web crawler, but we need you to describe this in more detail in order to help – Andrew Williamson Jan 15 '23 at 22:15
  • @AndrewWilliamson - No its not for a Crawler. Its an app I want to use in my toolkit, all I want is the File Path, to the *.m3u4 or what ever file. Try: https://odysee.com/@fireship:6/the-official-javascript-tier-list-is:3 and open the Developer, togo network add filter*.m3 and you will see the master.m3u4 file. Its a Header Request/Response. – Rusty Nail Jan 15 '23 at 22:52
  • This may give some insight to those that have no idea what I am talking about: https://stackoverflow.com/a/49835269/1183804 – Rusty Nail Jan 15 '23 at 23:04
  • This is a bit more: https://stackoverflow.com/a/53363200/1183804 but not related to the actual question. All I want is the Header. – Rusty Nail Jan 15 '23 at 23:07
  • 1
    You can obtain the request url via https://cefsharp.github.io/api/107.1.x/html/P_CefSharp_IRequest_Url.htm – amaitland Jan 16 '23 at 00:05
  • Request url is not in the headers – Evk Jan 16 '23 at 08:37
  • 1
    m3u8 files should have a "application/x-mpegURL" or "vnd.apple.mpegURL" content type. If you are actually looking for m3u4 files, you need to tell us what that is first. – Anon Coward Jan 17 '23 at 04:36

1 Answers1

1

You want to hook the event where a response to an interesting request comes back. First define the handler to look at each request and decide if its response should be streamed to your custom handler:

    public class MyRequestHandler : CefSharp.Handler.RequestHandler
    {
        protected override IResourceRequestHandler GetResourceRequestHandler(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
        {
            if (request.Url.EndsWith(".m3u4"))
            {
                return new MyResourceRequestHandler();
            }
            return null;
        }
    }

Then attach to your browser:

chromiumWebBrowser1.RequestHandler = new MyRequestHandler();

Your might want a more complicated set of rules to match, but if you can identify your required resource to be intercepted and downloaded, MyResourceRequestHandler will just be called for those.

The code for the custom resource request handler then gets called for interesting responses. If you want the data streamed to you, add a filter and then grab the stream once the response completes.

    public class MyResourceRequestHandler : CefSharp.Handler.ResourceRequestHandler
    {
        private readonly System.IO.MemoryStream responseData = new System.IO.MemoryStream();

        protected override IResponseFilter GetResourceResponseFilter(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response)
        {
            return new CefSharp.ResponseFilter.StreamResponseFilter(responseData);
        }
        
        protected override void OnResourceLoadComplete(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, IResponse response, UrlRequestStatus status, long receivedContentLength)
        {
            var bytes = responseData.ToArray();
            Console.WriteLine("Got {0} for {1}", responseData.Length, request.Url);
        }
    }
ricardkelly
  • 2,003
  • 1
  • 1
  • 18
  • I have not tested this code yet, but I have awarded answer for thoroughness! Its the only answer as of today anyway! Congrads! +250! – Rusty Nail Jan 22 '23 at 22:34