apple_app_store.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """Apple App Store
  3. """
  4. from json import loads
  5. from urllib.parse import urlencode
  6. from dateutil.parser import parse
  7. about = {
  8. "website": 'https://www.apple.com/app-store/',
  9. "wikidata_id": 'Q368215',
  10. "official_api_documentation": (
  11. 'https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/'
  12. 'iTuneSearchAPI/UnderstandingSearchResults.html#//apple_ref/doc/uid/TP40017632-CH8-SW1'
  13. ),
  14. "use_official_api": True,
  15. "require_api_key": False,
  16. "results": 'JSON',
  17. }
  18. categories = ['files', 'apps']
  19. safesearch = True
  20. search_url = 'https://itunes.apple.com/search?{query}'
  21. def request(query, params):
  22. explicit = "Yes"
  23. if params['safesearch'] > 0:
  24. explicit = "No"
  25. params['url'] = search_url.format(query=urlencode({'term': query, 'media': 'software', 'explicit': explicit}))
  26. return params
  27. def response(resp):
  28. results = []
  29. json_result = loads(resp.text)
  30. for result in json_result['results']:
  31. results.append(
  32. {
  33. 'url': result['trackViewUrl'],
  34. 'title': result['trackName'],
  35. 'content': result['description'],
  36. 'thumbnail': result['artworkUrl100'],
  37. 'publishedDate': parse(result['currentVersionReleaseDate']),
  38. 'author': result['sellerName'],
  39. }
  40. )
  41. return results