Skip to content
This repository has been archived by the owner on Jun 15, 2022. It is now read-only.

Commit

Permalink
Disable broken search API
Browse files Browse the repository at this point in the history
Fixes #183
  • Loading branch information
jodal committed Jul 8, 2019
1 parent 60761ff commit a79c029
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Expand Up @@ -16,6 +16,10 @@ Maintenance release.
:class:`Sequence` from :mod:`collections.abc` instead of :mod:`collections`.
This fixes a deprecation warning on Python 3.7 and prepares for Python 3.8.

- Document that the search API is broken. If it is used, raise an exception
instead of sending the search to Spotify, as that seems to disconnect your
session. (Fixes: :issue:`183`)

- Format soruce code with Black.


Expand Down
23 changes: 9 additions & 14 deletions spotify/session.py
Expand Up @@ -554,6 +554,12 @@ def search(
Search Spotify for tracks, albums, artists, and playlists matching
``query``.
.. warning:: Search API is not working
The search API was broken at 2016-02-03 by a server-side change
made by Spotify. The functionality was never restored.
Please use the Spotify Web API to perform searches.
The ``query`` string can be free format, or use some prefixes like
``title:`` and ``artist:`` to limit what to match on. There is no
official docs on the search query format, but there's a `Spotify blog
Expand All @@ -579,20 +585,9 @@ def search(
Returns a :class:`Search` instance.
"""
return spotify.Search(
self,
query=query,
callback=callback,
track_offset=track_offset,
track_count=track_count,
album_offset=album_offset,
album_count=album_count,
artist_offset=artist_offset,
artist_count=artist_count,
playlist_offset=playlist_offset,
playlist_count=playlist_count,
search_type=search_type,
)
raise Exception(
'Spotify broke the libspotify search API 2016-02-03 '
'and never restored it.')

def get_toplist(
self, type=None, region=None, canonical_username=None, callback=None
Expand Down
20 changes: 3 additions & 17 deletions tests/test_session.py
Expand Up @@ -723,25 +723,11 @@ def test_get_image(self, image_mock, lib_mock):
@mock.patch('spotify.Search')
def test_search(self, search_mock, lib_mock):
session = tests.create_real_session(lib_mock)
search_mock.return_value = mock.sentinel.search

result = session.search('alice')
with self.assertRaises(Exception):
session.search('alice')

self.assertIs(result, mock.sentinel.search)
search_mock.assert_called_with(
session,
query='alice',
callback=None,
track_offset=0,
track_count=20,
album_offset=0,
album_count=20,
artist_offset=0,
artist_count=20,
playlist_offset=0,
playlist_count=20,
search_type=None,
)
self.assertEqual(search_mock.call_count, 0)

@mock.patch('spotify.Toplist')
def test_toplist(self, toplist_mock, lib_mock):
Expand Down

0 comments on commit a79c029

Please sign in to comment.