Skip to content
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

Allow the iTunes Search API to sort the results #4

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 23 additions & 11 deletions itunes/__init__.py
Expand Up @@ -16,7 +16,7 @@
__name__ = 'pyitunes'
__doc__ = 'A python interface to search iTunes Store'
__author__ = 'Oscar Celma'
__version__ = '0.1'
__version__ = '0.2'
__license__ = 'GPL'
__maintainer__ = 'Oscar Celma'
__email__ = 'ocelma@bmat.com'
Expand Down Expand Up @@ -179,7 +179,9 @@ def get(self):
class Search(_BaseObject):
""" Search iTunes Store """

def __init__(self, query, country=COUNTRY, media='all', entity=None, attribute=None, offset=0, limit=50, lang='en_us', version=API_VERSION, explicit='Yes'):
def __init__(self, query, country=COUNTRY, media='all', entity=None,
attribute=None, offset=0, limit=50, order=None,
lang='en_us', version=API_VERSION, explicit='Yes'):
_BaseObject.__init__(self, 'search')

self._search_terms = dict()
Expand All @@ -191,8 +193,10 @@ def __init__(self, query, country=COUNTRY, media='all', entity=None, attribute=N
if attribute:
self._search_terms['attribute'] = attribute # The attribute you want to search for in the stores, relative to the specified media type
self._search_terms['limit'] = limit # Results limit
if offset > 0:
if offset > 0:
self._search_terms['offset'] = offset
if order is not None:
self._search_terms['order'] = order
self._search_terms['lang'] = lang # The language, English or Japanese, you want to use when returning search results
self._search_terms['version'] = version # The search result key version you want to receive back from your search
self._search_terms['explicit'] = explicit # A flag indicating whether or not you want to include explicit content in your search results
Expand Down Expand Up @@ -577,17 +581,25 @@ def get_md5(text):
return hash.hexdigest()

#SEARCHES
def search_track(query, limit=100, offset=0, store=COUNTRY):
return Search(query=query, media='music', entity='song', offset=offset, limit=limit, country=store).get()
def search_track(query, limit=100, offset=0, order=None, store=COUNTRY):
return Search(query=query, media='music', entity='song',
offset=offset, limit=limit, order=order, country=store).get()

def search_album(query, limit=100, offset=0, store=COUNTRY):
return Search(query=query, media='music', entity='album', limit=limit, offset=offset, country=store).get()
def search_album(query, limit=100, offset=0, order=None, store=COUNTRY):
return Search(query=query, media='music', entity='album',
limit=limit, offset=offset, order=order, country=store).get()

def search_artist(query, limit=100, offset=0, store=COUNTRY):
return Search(query=query, media='music', entity='musicArtist', limit=limit, offset=offset, country=store).get()
def search_artist(query, limit=100, offset=0, order=None, store=COUNTRY):
return Search(query=query, media='music', entity='musicArtist',
limit=limit, offset=offset, order=order, country=store).get()

def search(query, media='all', limit=100, offset=0, store=COUNTRY):
return Search(query=query, media=media, limit=limit, offset=offset, country=store).get()
def search_app(query, limit=100, offset=0, order=None, store=COUNTRY):
return Search(query=query, media='software', limit=limit,
offset=offset, order=order, country=store).get()

def search(query, media='all', limit=100, offset=0, order=None, store=COUNTRY):
return Search(query=query, media=media, limit=limit,
offset=offset, order=order, country=store).get()

#LOOKUP
def lookup(id):
Expand Down