Skip to content

Commit

Permalink
[ 1.0.62 ] * Added service get_track_recommendations to get track r…
Browse files Browse the repository at this point in the history
…ecommendations for specified criteria.

  * Added the following extra state attribute: `sp_track_is_explicit` - denotes the nowplaying track contains explicit lyrics (true) or not (false).
  • Loading branch information
thlucas1 committed Oct 27, 2024
1 parent 188f1ec commit f4ab736
Show file tree
Hide file tree
Showing 8 changed files with 1,262 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Change are listed in reverse chronological order (newest to oldest).

<span class="changelog">

###### [ 1.0.62 ] - 2024/10/27

* Added service `get_track_recommendations` to get track recommendations for specified criteria.
* Added the following extra state attribute: `sp_track_is_explicit` - denotes the nowplaying track contains explicit lyrics (true) or not (false).

###### [ 1.0.61 ] - 2024/10/22

* Added service `get_audiobook_chapters` to get Spotify catalog information about an audiobook's chapters.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ Check out the [SmartInspect Logging Configuration wiki page](https://github.com/

## Reporting a Problem

Submit a [Bug Report](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/issues/new?assignees=&labels=Bug&projects=&template=bug.yml) to bring the issue to my attention. I receive a notification when a new issue is opened, and will do my best to address it in a prompt and professional manner.
Submit a [Bug Report](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/issues/new?assignees=&labels=bug&projects=&template=bug.yml) to bring the issue to my attention. I receive a notification when a new issue is opened, and will do my best to address it in a prompt and professional manner.

## Request a New Feature

Do you have an idea for a new feature that could be added to the integration? Submit a [Feature Request](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/issues/new?assignees=&labels=Feature%2BRequest&projects=&template=feature_request.yml) to get your idea into the queue. I receive a notification when a new request is opened, and will do my best to turn your idea into the latest and greatest feature.
Do you have an idea for a new feature that could be added to the integration? Submit a [Feature Request](https://github.com/thlucas1/homeassistantcomponent_spotifyplus/issues/new?assignees=&labels=enhancement&projects=&template=feature_request.yml) to get your idea into the queue. I receive a notification when a new request is opened, and will do my best to turn your idea into the latest and greatest feature.

## Contributions are welcome!

Expand Down
135 changes: 134 additions & 1 deletion custom_components/spotifyplus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
SERVICE_SPOTIFY_GET_SPOTIFY_CONNECT_DEVICES:str = 'get_spotify_connect_devices'
SERVICE_SPOTIFY_GET_TRACK:str = 'get_track'
SERVICE_SPOTIFY_GET_TRACK_FAVORITES:str = 'get_track_favorites'
SERVICE_SPOTIFY_GET_TRACK_RECOMMENDATIONS:str = 'get_track_recommendations'
SERVICE_SPOTIFY_GET_TRACKS_AUDIO_FEATURES:str = 'get_tracks_audio_features'
SERVICE_SPOTIFY_GET_USERS_TOP_ARTISTS:str = 'get_users_top_artists'
SERVICE_SPOTIFY_GET_USERS_TOP_TRACKS:str = 'get_users_top_tracks'
Expand Down Expand Up @@ -544,6 +545,59 @@
}
)

SERVICE_SPOTIFY_GET_TRACK_RECOMMENDATIONS_SCHEMA = vol.Schema(
{
vol.Required("entity_id"): cv.entity_id,
vol.Optional("limit", default=20): vol.All(vol.Range(min=0,max=50)),
vol.Optional("market"): cv.string,
vol.Optional("seed_artists"): cv.string,
vol.Optional("seed_genres"): cv.string,
vol.Optional("seed_tracks"): cv.string,
vol.Optional("min_acousticness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_acousticness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_acousticness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("min_danceability", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_danceability", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_danceability", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("min_duration_ms", default=0): vol.All(vol.Range(min=0,max=999999999)),
vol.Optional("max_duration_ms", default=0): vol.All(vol.Range(min=0,max=999999999)),
vol.Optional("target_duration_ms", default=0): vol.All(vol.Range(min=0,max=999999999)),
vol.Optional("min_energy", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_energy", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_energy", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("min_instrumentalness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_instrumentalness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_instrumentalness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("min_key", default=0): vol.All(vol.Range(min=0,max=11)),
vol.Optional("max_key", default=0): vol.All(vol.Range(min=0,max=11)),
vol.Optional("target_key", default=0): vol.All(vol.Range(min=0,max=11)),
vol.Optional("min_liveness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_liveness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_liveness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("min_loudness", default=0): vol.All(vol.Range(min=-1000.0,max=1000.0)),
vol.Optional("max_loudness", default=0): vol.All(vol.Range(min=-1000.0,max=1000.0)),
vol.Optional("target_loudness", default=0): vol.All(vol.Range(min=-1000.0,max=1000.0)),
vol.Optional("min_mode", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_mode", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_mode", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("min_popularity", default=0): vol.All(vol.Range(min=0,max=100)),
vol.Optional("max_popularity", default=0): vol.All(vol.Range(min=0,max=100)),
vol.Optional("target_popularity", default=0): vol.All(vol.Range(min=0,max=100)),
vol.Optional("min_speechiness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_speechiness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_speechiness", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("min_tempo", default=0): vol.All(vol.Range(min=0,max=99999)),
vol.Optional("max_tempo", default=0): vol.All(vol.Range(min=0,max=99999)),
vol.Optional("target_tempo", default=0): vol.All(vol.Range(min=0,max=99999)),
vol.Optional("min_time_signature", default=0): vol.All(vol.Range(min=0,max=99999)),
vol.Optional("max_time_signature", default=0): vol.All(vol.Range(min=0,max=99999)),
vol.Optional("target_time_signature", default=0): vol.All(vol.Range(min=0,max=99999)),
vol.Optional("min_valence", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("max_valence", default=0): vol.All(vol.Range(min=0,max=1.0)),
vol.Optional("target_valence", default=0): vol.All(vol.Range(min=-0,max=1.0)),
}
)

SERVICE_SPOTIFY_GET_TRACKS_AUDIO_FEATURES_SCHEMA = vol.Schema(
{
vol.Required("entity_id"): cv.entity_id,
Expand Down Expand Up @@ -1669,7 +1723,7 @@ async def service_handle_spotify_serviceresponse(service: ServiceCall) -> Servic

elif service.service == SERVICE_SPOTIFY_GET_TRACK_FAVORITES:

# get spotify album favorites.
# get spotify track favorites.
limit = service.data.get("limit")
offset = service.data.get("offset")
market = service.data.get("market")
Expand All @@ -1678,6 +1732,76 @@ async def service_handle_spotify_serviceresponse(service: ServiceCall) -> Servic
_logsi.LogVerbose(STAppMessages.MSG_SERVICE_EXECUTE % (service.service, entity.name))
response = await hass.async_add_executor_job(entity.service_spotify_get_track_favorites, limit, offset, market, limit_total, sort_result)

elif service.service == SERVICE_SPOTIFY_GET_TRACK_RECOMMENDATIONS:

# get spotify track recommendations.
limit = service.data.get("limit")
market = service.data.get("market")
seed_artists = service.data.get("seed_artists")
seed_genres = service.data.get("seed_genres")
seed_tracks = service.data.get("seed_tracks")
min_acousticness = service.data.get("min_acousticness")
max_acousticness = service.data.get("max_acousticness")
target_acousticness = service.data.get("target_acousticness")
min_danceability = service.data.get("min_danceability")
max_danceability = service.data.get("max_danceability")
target_danceability = service.data.get("target_danceability")
min_duration_ms = service.data.get("min_duration_ms")
max_duration_ms = service.data.get("max_duration_ms")
target_duration_ms = service.data.get("target_duration_ms")
min_energy = service.data.get("min_energy")
max_energy = service.data.get("max_energy")
target_energy = service.data.get("target_energy")
min_instrumentalness = service.data.get("min_instrumentalness")
max_instrumentalness = service.data.get("max_instrumentalness")
target_instrumentalness = service.data.get("target_instrumentalness")
min_key = service.data.get("min_key")
max_key = service.data.get("max_key")
target_key = service.data.get("target_key")
min_liveness = service.data.get("min_liveness")
max_liveness = service.data.get("max_liveness")
target_liveness = service.data.get("target_liveness")
min_loudness = service.data.get("min_loudness")
max_loudness = service.data.get("max_loudness")
target_loudness = service.data.get("target_loudness")
min_mode = service.data.get("min_mode")
max_mode = service.data.get("max_mode")
target_mode = service.data.get("target_mode")
min_popularity = service.data.get("min_popularity")
max_popularity = service.data.get("max_popularity")
target_popularity = service.data.get("target_popularity")
min_speechiness = service.data.get("min_speechiness")
max_speechiness = service.data.get("max_speechiness")
target_speechiness = service.data.get("target_speechiness")
min_tempo = service.data.get("min_tempo")
max_tempo = service.data.get("max_tempo")
target_tempo = service.data.get("target_tempo")
min_time_signature = service.data.get("min_time_signature")
max_time_signature = service.data.get("max_time_signature")
target_time_signature = service.data.get("target_time_signature")
min_valence = service.data.get("min_valence")
max_valence = service.data.get("max_valence")
target_valence = service.data.get("target_valence")
_logsi.LogVerbose(STAppMessages.MSG_SERVICE_EXECUTE % (service.service, entity.name))
response = await hass.async_add_executor_job(
entity.service_spotify_get_track_recommendations,
limit, market,
seed_artists, seed_genres, seed_tracks,
min_acousticness, max_acousticness, target_acousticness,
min_danceability, max_danceability, target_danceability,
min_duration_ms, max_duration_ms, target_duration_ms,
min_energy, max_energy, target_energy,
min_instrumentalness, max_instrumentalness, target_instrumentalness,
min_key, max_key, target_key,
min_liveness, max_liveness, target_liveness,
min_loudness, max_loudness, target_loudness,
min_mode, max_mode, target_mode,
min_popularity, max_popularity, target_popularity,
min_speechiness, max_speechiness, target_speechiness,
min_tempo, max_tempo, target_tempo,
min_time_signature, max_time_signature, target_time_signature,
min_valence, max_valence, target_valence)

elif service.service == SERVICE_SPOTIFY_GET_TRACKS_AUDIO_FEATURES:

# get spotify album favorites.
Expand Down Expand Up @@ -2308,6 +2432,15 @@ def _GetEntityFromServiceData(hass:HomeAssistant, service:ServiceCall, field_id:
supports_response=SupportsResponse.ONLY,
)

_logsi.LogObject(SILevel.Verbose, STAppMessages.MSG_SERVICE_REQUEST_REGISTER % SERVICE_SPOTIFY_GET_TRACK_RECOMMENDATIONS, SERVICE_SPOTIFY_GET_TRACK_RECOMMENDATIONS_SCHEMA)
hass.services.async_register(
DOMAIN,
SERVICE_SPOTIFY_GET_TRACK_RECOMMENDATIONS,
service_handle_spotify_serviceresponse,
schema=SERVICE_SPOTIFY_GET_TRACK_RECOMMENDATIONS_SCHEMA,
supports_response=SupportsResponse.ONLY,
)

_logsi.LogObject(SILevel.Verbose, STAppMessages.MSG_SERVICE_REQUEST_REGISTER % SERVICE_SPOTIFY_GET_TRACKS_AUDIO_FEATURES, SERVICE_SPOTIFY_GET_TRACKS_AUDIO_FEATURES_SCHEMA)
hass.services.async_register(
DOMAIN,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/spotifyplus/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"urllib3>=1.21.1,<1.27",
"zeroconf>=0.132.2"
],
"version": "1.0.61",
"version": "1.0.62",
"zeroconf": [ "_spotify-connect._tcp.local." ]
}
Loading

0 comments on commit f4ab736

Please sign in to comment.