chandler-stimson / live-stream-downloader

Download M3U8 live streams to the local disk
https://webextension.org/listing/hls-downloader.html
201 stars 70 forks source link

Is there an API? #53

Closed Sneffel closed 5 months ago

Sneffel commented 5 months ago

I want to get the results of a webpage through an API. Is it available? Can I get the same results on my machine using Python?

Sneffel commented 5 months ago

It was actually super easy to do

` driver.get(website_url)

cookie_button = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, '//button[contains(text(), "I Agree")]')))        
cookie_button.click()

# Add a delay to allow the page to fully load (adjust as needed)
time.sleep(5)  # 5 seconds delay

# Define the JavaScript snippet to get network requests
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)

first_m3u8_link = None
for n in network_requests:
    if n["name"].endswith("playlist.m3u8") or n["name"].endswith("index.m3u8"):
        first_m3u8_link = n["name"]
        break

if first_m3u8_link is None:
    print('Couldn\'t find m3u8 file')
    offline = True
    break

`