mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-09 05:16:47 +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 asyncio
|
||||||
import pyatv
|
import pyatv
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from async_lru import alru_cache
|
from cache import AsyncTTL
|
||||||
import json
|
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)
|
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):
|
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"
|
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:
|
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"]
|
vid_id = response["items"][0]["id"]["videoId"]
|
||||||
return vid_id
|
return vid_id
|
||||||
|
|
||||||
@listToTuple
|
@listToTuple
|
||||||
@alru_cache(maxsize = 5)
|
@AsyncTTL(time_to_live=300, maxsize=5)
|
||||||
async def get_segments(vid_id, web_session, categories = ["sponsor"]):
|
async def get_segments(vid_id, web_session, categories = ["sponsor"]):
|
||||||
params = {"videoID": vid_id,
|
params = {"videoID": vid_id,
|
||||||
"category": categories,
|
"category": categories,
|
||||||
@@ -133,4 +133,4 @@ def load_config(config_file="config.json"):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
atv_config, apikey, categories = load_config()
|
atv_config, apikey, categories = load_config()
|
||||||
event_loop = asyncio.get_event_loop()
|
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
|
pyatv
|
||||||
aiohttp[speedups]
|
aiohttp[speedups]
|
||||||
aiodns
|
aiodns
|
||||||
async_lru
|
async-cache
|
||||||
|
|||||||
Reference in New Issue
Block a user