mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-06 03:46:44 +03:00
Changed alru cache to AsyncTTL. Now segments are only cached for 5 minutes. If new segments are submitted they'll be found after that time.
This commit is contained in:
10
main.py
10
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))
|
||||
event_loop.run_until_complete(loop_atv(event_loop, atv_config, apikey, categories))
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
pyatv
|
||||
aiohttp[speedups]
|
||||
aiodns
|
||||
async_lru
|
||||
async-cache
|
||||
|
||||
Reference in New Issue
Block a user