How to find .m3u8 file from URL and download it

Viewed 3837

I'm trying to find and download a m3u8 file from a given website URL. How would I would I do this? I've looked into the page source and couldn't find any links to any m3u8 files, though I could see a network GET request being sent to download a m3u8 file in Chrome's dev tool network tab.

So anyone know how to detect a URL linking to a m3u8 file from a given website URL and how to download it?

1 Answers

.m3u8 and .mpd links are special elements and not part of HTML.

You can find them in network requests, and usually they appear after you click Play Button on the video. They are used to stream content in pieces instead of giving you access to the video file.

Here is a snippet I have been using for a while with Selenium to retrieve them. it does not work for 100% cases, but it still works on many websites:

JS_get_network_requests = "var performance = window.performance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return network;"
network_requests = driver.execute_script(JS_get_network_requests)
for n in network_requests:
    if ".m3u8" in n["name"]: 
        print(n["name"])

P.S. if video is embeded in iframe, you have to switch to iframe to be able to get network requests from the video.

Related