haruhi-dl/haruhi_dl/playwright.py
2021-01-18 22:59:11 +01:00

32 lines
750 B
Python

# coding: utf-8
from __future__ import unicode_literals
from .utils import (
ExtractorError,
)
class PlaywrightHelper():
_pw = None
_pw_version = None
@classmethod
def _real_import_pw(cls):
from playwright import sync_playwright, _repo_version
cls._pw = sync_playwright
cls._pw_version = _repo_version.version
@classmethod
def _import_pw(cls, fatal=True):
try:
cls._real_import_pw()
except ImportError:
if fatal is True:
raise ExtractorError('Playwright could not be imported', expected=True)
@classmethod
def _version(cls):
if not cls._pw_version:
cls._import_pw(fatal=False)
return cls._pw_version