Skip to content

Commit

Permalink
Removed the 'linux' version of search
Browse files Browse the repository at this point in the history
  • Loading branch information
j-jacobson committed Aug 22, 2023
1 parent 5561842 commit c5cc082
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
38 changes: 16 additions & 22 deletions applemusicpy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def storefronts_all(self, l=None, limit=None, offset=None):
return self._get(url, l=l, limit=limit, offset=offset)

# Search
def search(self, term, storefront='us', l=None, limit=None, offset=None, types=None, hints=False, os='linux'):
def search(self, term, storefront='us', l=None, limit=None, offset=None, types=None, hints=False, os=None):
"""
Query the Apple Music API based on a search term
Expand All @@ -824,7 +824,6 @@ def search(self, term, storefront='us', l=None, limit=None, offset=None, types=N
:param offset: The index of the first item returned
:param types: A list of resource types to return (e.g. songs, artists, etc.)
:param hints: Include search hints
:param os: Operating System being used. If search isn't working on Windows, try os='windows'.
:return: The search results in JSON format
"""
Expand All @@ -837,28 +836,23 @@ def search(self, term, storefront='us', l=None, limit=None, offset=None, types=N
else:
type_str = None

if os == 'linux':
return self._get(url, term=term, l=l, limit=limit, offset=offset, types=type_str)
elif os == 'windows':
params = {
'term': term,
'limit': limit,
'offset': offset,
'types': type_str
}
params = {
'term': term,
'limit': limit,
'offset': offset,
'types': type_str
}

# The params parameter in requests converts '+' to '%2b'
# On some Windows computers, this breaks the API request, so generate full URL instead
param_string = '?'
for param, value in params.items():
if value is None:
continue
param_string = param_string + str(param) + '=' + str(value) + '&'
param_string = param_string[:len(param_string) - 1] # This removes the last trailing '&'
# The params parameter in requests converts '+' to '%2b'
# On some Windows computers, this breaks the API request, so generate full URL instead
param_string = '?'
for param, value in params.items():
if value is None:
continue
param_string = param_string + str(param) + '=' + str(value) + '&'
param_string = param_string[:len(param_string) - 1] # This removes the last trailing '&'

return self._get(url + param_string)
else:
return None
return self._get(url + param_string)

# Charts
def charts(self, storefront='us', chart=None, types=None, l=None, genre=None, limit=None, offset=None):
Expand Down
6 changes: 0 additions & 6 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,6 @@ def test_search(self):
actual_name = results['results']['songs']['data'][0]['attributes']['name']
self.assertTrue(expected_name == actual_name, f"Expected: {expected_name}, Actual: {actual_name}")

def test_search_windows(self):
results = am.search(self.search_term, types=['songs'], os='windows')
expected_name = 'Nice For What'
actual_name = results['results']['songs']['data'][0]['attributes']['name']
self.assertTrue(expected_name == actual_name, f"Expected: {expected_name}, Actual: {actual_name}")

def test_charts(self):
results = am.charts(types=['songs'], genre=self.pop)
expected_name = 'Top Songs'
Expand Down

0 comments on commit c5cc082

Please sign in to comment.