Added sources functionality + pre-commit

This commit is contained in:
2021-11-18 21:59:37 +01:00
parent 2e007a6fb3
commit 316f3bacc9
11 changed files with 170 additions and 21 deletions
+22
View File
@@ -33,3 +33,25 @@ class Playlist:
@staticmethod
async def random(redis: Redis, amount: Optional[int] = 1) -> List[str]:
return await redis.srandmember(f"{redis_prefix}:playlist", amount)
@staticmethod
async def add_bulk(redis: Redis, urls: list[str]):
await redis.sadd(f"{redis_prefix}:playlist", *urls)
@staticmethod
async def clear(redis: Redis):
await redis.delete(f"{redis_prefix}:playlist")
class PlaylistSource:
@staticmethod
async def get_all(redis: Redis) -> list[str]:
return await redis.smembers(f"{redis_prefix}:sources")
@staticmethod
async def add(redis: Redis, source_url: str):
await redis.sadd(f"{redis_prefix}:sources", source_url)
@staticmethod
async def remove(redis: Redis, source_url: str) -> bool:
return await redis.srem(f"{redis_prefix}:sources", source_url)