for prov in providers:
await mass.music.register_provider(prov)
# get some data
- artists = await mass.music.artists.library()
- print(f"Got {len(artists)} artists in library")
- albums = await mass.music.albums.library()
- print(f"Got {len(albums)} albums in library")
- tracks = await mass.music.tracks.library()
- print(f"Got {len(tracks)} tracks in library")
- radios = await mass.music.radio.library()
- print(f"Got {len(radios)} radio stations in library")
+ artists = await mass.music.artists.count()
+ print(f"Got {artists} artists in library")
+ albums = await mass.music.albums.count()
+ print(f"Got {albums} albums in library")
+ tracks = await mass.music.tracks.count()
+ print(f"Got {tracks} tracks in library")
+ radios = await mass.music.radio.count()
+ print(f"Got {radios} radio stations in library")
playlists = await mass.music.playlists.library()
print(f"Got {len(playlists)} playlists in library")
# register a player
TABLE_SETTINGS, {"key": key, "value": value}
)
+ async def get_count(
+ self,
+ table: str,
+ match: dict = None,
+ db: Optional[Db] = None,
+ ) -> List[Mapping]:
+ """Get row count for given table/query."""
+ async with self.get_db(db) as _db:
+ sql_query = f"SELECT count() FROM {table}"
+ if match is not None:
+ sql_query += " WHERE " + " AND ".join((f"{x} = :{x}" for x in match))
+ if res := await _db.fetch_one(sql_query, match):
+ return res["count()"]
+ return 0
+
async def get_rows(
self,
table: str,
for db_row in await self.mass.database.get_rows(self.db_table, match)
]
+ async def count(self) -> int:
+ """Return number of in-library items for this MediaType."""
+ return await self.mass.database.get_count(self.db_table, {"in_library": 1})
+
async def get(
self,
provider_item_id: str,