Fetch tracks resolving pagination and included items. https://tidal-music.github.io/tidal-api-reference/#/tracks/get_tracks
(
self,
ids: list[str] | None = None,
isrcs: list[str] | None = None,
include: list[str] | None = None,
country_code: str = "US",
)
| 72 | ) |
| 73 | |
| 74 | def get_tracks( |
| 75 | self, |
| 76 | ids: list[str] | None = None, |
| 77 | isrcs: list[str] | None = None, |
| 78 | include: list[str] | None = None, |
| 79 | country_code: str = "US", |
| 80 | ) -> TrackDocument: |
| 81 | """Fetch tracks resolving pagination and included items. |
| 82 | |
| 83 | https://tidal-music.github.io/tidal-api-reference/#/tracks/get_tracks |
| 84 | """ |
| 85 | ids = ids or [] |
| 86 | isrcs = isrcs or [] |
| 87 | |
| 88 | # Tidal allows at max 20 filters per request. This needs a bit of extra |
| 89 | # logic sadly. |
| 90 | doc: TrackDocument = {"data": [], "included": []} |
| 91 | for id_batch, isrc_batch in zip_longest( |
| 92 | _batched(ids, MAX_FILTER_SIZE), |
| 93 | _batched(isrcs, MAX_FILTER_SIZE), |
| 94 | fillvalue=(), |
| 95 | ): |
| 96 | params: dict[str, Any] = {"countryCode": country_code} |
| 97 | if id_batch: |
| 98 | params["filter[id]"] = id_batch |
| 99 | if isrc_batch: |
| 100 | params["filter[isrc]"] = isrc_batch |
| 101 | |
| 102 | doc = self.merge_multiresource_pagination( |
| 103 | doc, |
| 104 | self.get_paginated( |
| 105 | f"{API_BASE}/tracks", include, params=params |
| 106 | ), |
| 107 | ) |
| 108 | |
| 109 | return doc |
| 110 | |
| 111 | def get_albums( |
| 112 | self, |
no test coverage detected