diff --git a/main.py b/main.py index 4f63f97..6c8db1b 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ import sys import asyncio import pyatv import aiohttp -from async_lru import alru_cache +from cache import AsyncTTL import json @@ -51,7 +51,7 @@ async def process_playstatus(playstatus, apikey, rc, app, web_session, categorie await time_to_segment(segments, playstatus.position, rc) -@alru_cache(maxsize = 5) +@AsyncTTL(time_to_live=300, maxsize=5) async def get_vid_id(title, artist, api_key, web_session): url = f"https://youtube.googleapis.com/youtube/v3/search?q={title} - {artist}&key={api_key}&maxResults=1" async with web_session.get(url) as response: @@ -59,8 +59,8 @@ async def get_vid_id(title, artist, api_key, web_session): vid_id = response["items"][0]["id"]["videoId"] return vid_id -@listToTuple -@alru_cache(maxsize = 5) +@listToTuple +@AsyncTTL(time_to_live=300, maxsize=5) async def get_segments(vid_id, web_session, categories = ["sponsor"]): params = {"videoID": vid_id, "category": categories, @@ -133,4 +133,4 @@ def load_config(config_file="config.json"): if __name__ == "__main__": atv_config, apikey, categories = load_config() event_loop = asyncio.get_event_loop() - event_loop.run_until_complete(loop_atv(event_loop, atv_config, apikey, categories)) \ No newline at end of file + event_loop.run_until_complete(loop_atv(event_loop, atv_config, apikey, categories)) diff --git a/requirements.txt b/requirements.txt index dec2adc..9ae5311 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ pyatv aiohttp[speedups] aiodns -async_lru +async-cache