-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search, view tracks websocket endpoints, service to like media. #489
Merged
Merged
Changes from 2 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
fbc89e9
Adds a generic get method
86beb1e
Adds a generic get method. Which abuses the _get method of spotipy
6ee3bcc
Add missing import
c39a817
Generic get => view_handler, adds a search endpoint
2bc9eb8
Merge branch 'dev' of https://github.com/fondberg/spotcast into gener…
df4727a
Fix syntax
891eb4a
Fix url
5f7decc
Fix mistakes
3dbd616
Add account in search handler
de2ff8f
Remove locale in search
104848f
song => track
adfe849
Add HREF to search result.
5cb754c
Use already existing search method. Added comments as explanation
c91a8ee
Remove unused partial import
9855836
Align search with new return time.
c699e59
Merge branch 'dev' of https://github.com/fondberg/spotcast into gener…
885eeaa
pr comments
f0fd2d5
Merge branch 'dev' of https://github.com/fondberg/spotcast into gener…
590eb15
Merge branch 'generic_get_ws' of https://github.com/mikevanes/spotcas…
1d7199b
Added description to view and search and trackshandler
3172652
href => uri
4f2bc8e
Adds a method to like a song.
62b8d97
Expire liked songs cache after adding liked songs
e2730ca
Adds websocket to retrieve liked media.
d55dfc6
Merge branch 'dev' into generic_get_ws
fcusson a2b2d5d
refactoring unit test
fcusson b6d66a7
full unit test on websocket handlers
fcusson 55cf26d
added service definition
fcusson 73f8e8f
Merge pull request #1 from fcusson/feature/generic_get_ws
acac78e
Adds documentation
39a8be6
typo
fcusson 1b79898
moved config and option flow to config_flow.py for hassfest validation
fcusson 1ff1a9e
tweaked github actions
fcusson 78d4ce7
typo
fcusson 3494ddf
reorg selector strings to fit documentation
fcusson c82db7f
fixed issue with selector definition
fcusson 9cb29ce
fixed config flow and options flow test with new python module structure
fcusson d475bb7
added pylint to dev requirements
fcusson 335c33e
fixed option flow for HASS2024.12
fcusson e8f66e0
bumped minimal version due to breaking change in 2024.12 for option f…
fcusson f9fd6c3
added pythonpath to linter definition
fcusson 74fa79f
moved location of pythonpath definition
fcusson 097d39d
typo
fcusson d85a0d3
Fix documentation
f3f6407
Merge pull request #2 from fcusson/feature/generic_get_ws
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import voluptuous as vol | ||
from homeassistant.helpers import config_validation as cv | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.components.websocket_api import ActiveConnection | ||
|
||
from custom_components.spotcast.utils import get_account_entry, search_account | ||
from custom_components.spotcast.spotify.account import SpotifyAccount | ||
from custom_components.spotcast.websocket.utils import websocket_wrapper | ||
from custom_components.spotcast.spotify.utils import select_image_url | ||
|
||
ENDPOINT = "spotcast/search" | ||
SCHEMA = vol.Schema( | ||
{ | ||
vol.Required("id"): cv.positive_int, | ||
vol.Required("type"): ENDPOINT, | ||
vol.Required("query"): cv.string, | ||
vol.optional("searchType"): cv.string, # Playlist or song, default playlist | ||
vol.Optional("limit"): cv.positive_int, | ||
} | ||
) | ||
|
||
@websocket_wrapper | ||
async def search_handler( | ||
hass: HomeAssistant, connection: ActiveConnection, msg: dict | ||
): | ||
"""Searches for a playlist or song. | ||
|
||
Args: | ||
- hass (HomeAssistant): The Home Assistant instance. | ||
- connection (ActiveConnection): The active WebSocket connection. | ||
- msg (dict): The message received through the WebSocket API. | ||
""" | ||
account_id = msg.get("account") | ||
query = msg.get("url") | ||
searchType = msg.get("searchType", "playlist") | ||
limit = msg.get("limit", 10) | ||
|
||
account: SpotifyAccount | ||
|
||
if account_id is None: | ||
entry = get_account_entry(hass) | ||
account_id = entry.entry_id | ||
account = await SpotifyAccount.async_from_config_entry(hass, entry) | ||
else: | ||
account = search_account(hass, account_id) | ||
|
||
# prepend view/ to the url | ||
url = f"view/{url}" | ||
|
||
result = await account.async_search( | ||
query: query, | ||
searchType: searchType, | ||
limit: limit, | ||
) | ||
|
||
formatted_results = [ | ||
{ | ||
"id": item["id"], | ||
"name": item["name"], | ||
"icon": item["images"][0]["url"] | ||
if "images" in item and len(item["images"]) > 0 | ||
else None, | ||
} | ||
for item in result[searchType] | ||
if "id" in item # Only include playlists with an 'id' | ||
] | ||
|
||
connection.send_result( | ||
msg["id"], | ||
{ | ||
"total": len(formatted_results), | ||
"account": account_id, | ||
"playlists": formatted_results, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THere is already an async_search method. This method is generalised for any type of search. But you would have to build a SearchQuery object to utilize it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.