Home Assistant Unofficial Reference 2024.12.1
const.py
Go to the documentation of this file.
1 """Constants for the DLNA DMR component."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Mapping
6 import logging
7 from typing import Final
8 
9 from async_upnp_client.profiles.dlna import PlayMode as _PlayMode
10 
11 from homeassistant.components.media_player import MediaType, RepeatMode
12 
13 LOGGER = logging.getLogger(__package__)
14 
15 DOMAIN: Final = "dlna_dmr"
16 
17 CONF_LISTEN_PORT: Final = "listen_port"
18 CONF_CALLBACK_URL_OVERRIDE: Final = "callback_url_override"
19 CONF_POLL_AVAILABILITY: Final = "poll_availability"
20 CONF_BROWSE_UNFILTERED: Final = "browse_unfiltered"
21 
22 DEFAULT_NAME: Final = "DLNA Digital Media Renderer"
23 
24 CONNECT_TIMEOUT: Final = 10
25 
26 PROTOCOL_HTTP: Final = "http-get"
27 PROTOCOL_RTSP: Final = "rtsp-rtp-udp"
28 PROTOCOL_ANY: Final = "*"
29 STREAMABLE_PROTOCOLS: Final = [PROTOCOL_HTTP, PROTOCOL_RTSP, PROTOCOL_ANY]
30 
31 # Map UPnP class to media_player media_content_type
32 MEDIA_TYPE_MAP: Mapping[str, MediaType] = {
33  "object": MediaType.URL,
34  "object.item": MediaType.URL,
35  "object.item.imageItem": MediaType.IMAGE,
36  "object.item.imageItem.photo": MediaType.IMAGE,
37  "object.item.audioItem": MediaType.MUSIC,
38  "object.item.audioItem.musicTrack": MediaType.MUSIC,
39  "object.item.audioItem.audioBroadcast": MediaType.MUSIC,
40  "object.item.audioItem.audioBook": MediaType.PODCAST,
41  "object.item.videoItem": MediaType.VIDEO,
42  "object.item.videoItem.movie": MediaType.MOVIE,
43  "object.item.videoItem.videoBroadcast": MediaType.TVSHOW,
44  "object.item.videoItem.musicVideoClip": MediaType.VIDEO,
45  "object.item.playlistItem": MediaType.PLAYLIST,
46  "object.item.textItem": MediaType.URL,
47  "object.item.bookmarkItem": MediaType.URL,
48  "object.item.epgItem": MediaType.EPISODE,
49  "object.item.epgItem.audioProgram": MediaType.EPISODE,
50  "object.item.epgItem.videoProgram": MediaType.EPISODE,
51  "object.container": MediaType.PLAYLIST,
52  "object.container.person": MediaType.ARTIST,
53  "object.container.person.musicArtist": MediaType.ARTIST,
54  "object.container.playlistContainer": MediaType.PLAYLIST,
55  "object.container.album": MediaType.ALBUM,
56  "object.container.album.musicAlbum": MediaType.ALBUM,
57  "object.container.album.photoAlbum": MediaType.ALBUM,
58  "object.container.genre": MediaType.GENRE,
59  "object.container.genre.musicGenre": MediaType.GENRE,
60  "object.container.genre.movieGenre": MediaType.GENRE,
61  "object.container.channelGroup": MediaType.CHANNELS,
62  "object.container.channelGroup.audioChannelGroup": MediaType.CHANNELS,
63  "object.container.channelGroup.videoChannelGroup": MediaType.CHANNELS,
64  "object.container.epgContainer": MediaType.TVSHOW,
65  "object.container.storageSystem": MediaType.PLAYLIST,
66  "object.container.storageVolume": MediaType.PLAYLIST,
67  "object.container.storageFolder": MediaType.PLAYLIST,
68  "object.container.bookmarkFolder": MediaType.PLAYLIST,
69 }
70 
71 # Map media_player media_content_type to UPnP class. Not everything will map
72 # directly, in which case it's not specified and other defaults will be used.
73 MEDIA_UPNP_CLASS_MAP: Mapping[MediaType | str, str] = {
74  MediaType.ALBUM: "object.container.album.musicAlbum",
75  MediaType.ARTIST: "object.container.person.musicArtist",
76  MediaType.CHANNEL: "object.item.videoItem.videoBroadcast",
77  MediaType.CHANNELS: "object.container.channelGroup",
78  MediaType.COMPOSER: "object.container.person.musicArtist",
79  MediaType.CONTRIBUTING_ARTIST: "object.container.person.musicArtist",
80  MediaType.EPISODE: "object.item.epgItem.videoProgram",
81  MediaType.GENRE: "object.container.genre",
82  MediaType.IMAGE: "object.item.imageItem",
83  MediaType.MOVIE: "object.item.videoItem.movie",
84  MediaType.MUSIC: "object.item.audioItem.musicTrack",
85  MediaType.PLAYLIST: "object.item.playlistItem",
86  MediaType.PODCAST: "object.item.audioItem.audioBook",
87  MediaType.SEASON: "object.item.epgItem.videoProgram",
88  MediaType.TRACK: "object.item.audioItem.musicTrack",
89  MediaType.TVSHOW: "object.item.videoItem.videoBroadcast",
90  MediaType.URL: "object.item.bookmarkItem",
91  MediaType.VIDEO: "object.item.videoItem",
92 }
93 
94 # Translation of MediaMetadata keys to DIDL-Lite keys.
95 # See https://developers.google.com/cast/docs/reference/messages#MediaData via
96 # https://www.home-assistant.io/integrations/media_player/ for HA keys.
97 # See http://www.upnp.org/specs/av/UPnP-av-ContentDirectory-v4-Service.pdf for
98 # DIDL-Lite keys.
99 MEDIA_METADATA_DIDL: Mapping[str, str] = {
100  "subtitle": "longDescription",
101  "releaseDate": "date",
102  "studio": "publisher",
103  "season": "episodeSeason",
104  "episode": "episodeNumber",
105  "albumName": "album",
106  "trackNumber": "originalTrackNumber",
107 }
108 
109 # For (un)setting repeat mode, map a combination of shuffle & repeat to a list
110 # of play modes in order of suitability. Fall back to _PlayMode.NORMAL in any
111 # case. NOTE: This list is slightly different to that in SHUFFLE_PLAY_MODES,
112 # due to fallback behaviour when turning on repeat modes.
113 REPEAT_PLAY_MODES: Mapping[tuple[bool, RepeatMode], list[_PlayMode]] = {
114  (False, RepeatMode.OFF): [
115  _PlayMode.NORMAL,
116  ],
117  (False, RepeatMode.ONE): [
118  _PlayMode.REPEAT_ONE,
119  _PlayMode.REPEAT_ALL,
120  _PlayMode.NORMAL,
121  ],
122  (False, RepeatMode.ALL): [
123  _PlayMode.REPEAT_ALL,
124  _PlayMode.REPEAT_ONE,
125  _PlayMode.NORMAL,
126  ],
127  (True, RepeatMode.OFF): [
128  _PlayMode.SHUFFLE,
129  _PlayMode.RANDOM,
130  _PlayMode.NORMAL,
131  ],
132  (True, RepeatMode.ONE): [
133  _PlayMode.REPEAT_ONE,
134  _PlayMode.RANDOM,
135  _PlayMode.SHUFFLE,
136  _PlayMode.NORMAL,
137  ],
138  (True, RepeatMode.ALL): [
139  _PlayMode.RANDOM,
140  _PlayMode.REPEAT_ALL,
141  _PlayMode.SHUFFLE,
142  _PlayMode.NORMAL,
143  ],
144 }
145 
146 # For (un)setting shuffle mode, map a combination of shuffle & repeat to a list
147 # of play modes in order of suitability. Fall back to _PlayMode.NORMAL in any
148 # case.
149 SHUFFLE_PLAY_MODES: Mapping[tuple[bool, str], list[_PlayMode]] = {
150  (False, RepeatMode.OFF): [
151  _PlayMode.NORMAL,
152  ],
153  (False, RepeatMode.ONE): [
154  _PlayMode.REPEAT_ONE,
155  _PlayMode.REPEAT_ALL,
156  _PlayMode.NORMAL,
157  ],
158  (False, RepeatMode.ALL): [
159  _PlayMode.REPEAT_ALL,
160  _PlayMode.REPEAT_ONE,
161  _PlayMode.NORMAL,
162  ],
163  (True, RepeatMode.OFF): [
164  _PlayMode.SHUFFLE,
165  _PlayMode.RANDOM,
166  _PlayMode.NORMAL,
167  ],
168  (True, RepeatMode.ONE): [
169  _PlayMode.RANDOM,
170  _PlayMode.SHUFFLE,
171  _PlayMode.REPEAT_ONE,
172  _PlayMode.NORMAL,
173  ],
174  (True, RepeatMode.ALL): [
175  _PlayMode.RANDOM,
176  _PlayMode.SHUFFLE,
177  _PlayMode.REPEAT_ALL,
178  _PlayMode.NORMAL,
179  ],
180 }