1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-10-31 21:37:30 +00:00
NewLeaf/tools/extractors.py
Cadence Ember 861f441f9f
Fix search
2020-10-24 00:36:20 +13:00

13 lines
413 B
Python

import re
import json
r_yt_initial_data = re.compile(r"""^(?:\s*window\["ytInitialData"\]|var ytInitialData) = (\{.*\});\s*\n?$""", re.M)
def extract_yt_initial_data(content):
m_yt_initial_data = re.search(r_yt_initial_data, content)
if m_yt_initial_data:
yt_initial_data = json.loads(m_yt_initial_data.group(1))
return yt_initial_data
else:
raise Exception("Could not match ytInitialData in content")