forked from lekoOwO/auto-ytarchive-raw
-
Notifications
You must be signed in to change notification settings - Fork 7
/
getm3u8.py
27 lines (23 loc) · 826 Bytes
/
getm3u8.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import re
import utils
def get_m3u8(url):
use_cookie=False
try:
with utils.urlopen(url, use_cookie=use_cookie) as response:
html = response.read().decode()
regex = r"hlsManifestUrl\":\"([^\"]+)"
result = re.search(regex, html).group(1)
except AttributeError:
use_cookie=True
with utils.urlopen(url, use_cookie=use_cookie) as response:
html = response.read().decode()
regex = r"hlsManifestUrl\":\"([^\"]+)"
try:
result = re.search(regex, html).group(1)
except AttributeError as att_error:
print(f"[ERROR] {att_error}")
return result, use_cookie
def get_m3u8_id(m3u8_url):
regex = r"/id/(.+?)/"
result = re.search(regex, m3u8_url).group(1)
return result