e
This commit is contained in:
parent
c8e49d9fbb
commit
00000d9077
7 changed files with 25 additions and 113 deletions
|
|
@ -4,7 +4,7 @@ from pathlib import Path
|
|||
|
||||
import httpx
|
||||
|
||||
from .utils import LOGOS, get_logger, now
|
||||
from .utils import LOGOS, get_logger, load_cache
|
||||
|
||||
log = get_logger(__name__)
|
||||
|
||||
|
|
@ -15,14 +15,6 @@ BASE_URL = "https://tvpass.org/playlist/m3u"
|
|||
CACHE_FILE = Path(__file__).parent / "caches" / "tvpass.json"
|
||||
|
||||
|
||||
def load_cache() -> dict[str, str]:
|
||||
try:
|
||||
data = json.loads(CACHE_FILE.read_text(encoding="utf-8"))
|
||||
return {} if now.hour <= 12 else data
|
||||
except (FileNotFoundError, json.JSONDecodeError):
|
||||
return {}
|
||||
|
||||
|
||||
async def fetch_m3u8(client: httpx.AsyncClient) -> list[str]:
|
||||
try:
|
||||
r = await client.get(BASE_URL)
|
||||
|
|
@ -35,7 +27,7 @@ async def fetch_m3u8(client: httpx.AsyncClient) -> list[str]:
|
|||
|
||||
|
||||
async def main(client: httpx.AsyncClient) -> None:
|
||||
if cached := load_cache():
|
||||
if cached := load_cache(CACHE_FILE, hour=12):
|
||||
urls.update(cached)
|
||||
log.info(f"Collected {len(urls)} event(s) from cache")
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue