/
/
/
1"""Shared helpers for the music controller tests."""
2
3from __future__ import annotations
4
5from music_assistant_models.enums import ExternalID
6from music_assistant_models.media_items import (
7 Album,
8 Artist,
9 AudioFormat,
10 ItemMapping,
11 ProviderMapping,
12 Track,
13 UniqueList,
14)
15
16ISRC = "USRC17607839"
17
18
19def create_track(
20 provider_instance: str,
21 item_id: str,
22 name: str = "Test Track",
23 isrc: str = ISRC,
24 duration: int = 200,
25) -> Track:
26 """
27 Create a Track as it would be received from a music provider.
28
29 :param provider_instance: The provider instance id the track originates from.
30 :param item_id: The item id of the track on the provider.
31 :param name: The track name.
32 :param isrc: The ISRC external id to attach to the track.
33 :param duration: The track duration in seconds.
34 """
35 provider_domain = provider_instance.split("_", maxsplit=1)[0]
36 return Track(
37 item_id=item_id,
38 provider=provider_instance,
39 name=name,
40 duration=duration,
41 external_ids={(ExternalID.ISRC, isrc)},
42 provider_mappings={
43 ProviderMapping(
44 item_id=item_id,
45 provider_domain=provider_domain,
46 provider_instance=provider_instance,
47 audio_format=AudioFormat(),
48 )
49 },
50 artists=UniqueList(
51 [
52 Artist(
53 item_id=f"{item_id}_artist",
54 provider=provider_instance,
55 name="Test Artist",
56 provider_mappings={
57 ProviderMapping(
58 item_id=f"{item_id}_artist",
59 provider_domain=provider_domain,
60 provider_instance=provider_instance,
61 audio_format=AudioFormat(),
62 )
63 },
64 )
65 ]
66 ),
67 )
68
69
70def create_album(
71 provider_instance: str,
72 item_id: str,
73 name: str = "Test Album",
74 artist_name: str | None = "Test Artist",
75 artist_item_id: str | None = None,
76) -> Album:
77 """
78 Create an Album as it would be received from a music provider.
79
80 :param provider_instance: The provider instance id the album originates from.
81 :param item_id: The item id of the album on the provider.
82 :param name: The album name.
83 :param artist_name: The album artist name, or None for an album without artists.
84 :param artist_item_id: The item id of the album artist on the provider,
85 defaults to one derived from the album item id.
86 """
87 provider_domain = provider_instance.split("_", maxsplit=1)[0]
88 artists: UniqueList[Artist | ItemMapping] = UniqueList()
89 if artist_name is not None:
90 artist_id = artist_item_id or f"{item_id}_artist"
91 artists.append(
92 Artist(
93 item_id=artist_id,
94 provider=provider_instance,
95 name=artist_name,
96 provider_mappings={
97 ProviderMapping(
98 item_id=artist_id,
99 provider_domain=provider_domain,
100 provider_instance=provider_instance,
101 audio_format=AudioFormat(),
102 )
103 },
104 )
105 )
106 return Album(
107 item_id=item_id,
108 provider=provider_instance,
109 name=name,
110 provider_mappings={
111 ProviderMapping(
112 item_id=item_id,
113 provider_domain=provider_domain,
114 provider_instance=provider_instance,
115 audio_format=AudioFormat(),
116 )
117 },
118 artists=artists,
119 )
120