From e5c1b64b1d0ea2b19c76a654a22e12c3042fe87f Mon Sep 17 00:00:00 2001 From: ta Date: Wed, 24 Aug 2022 17:27:36 +0700 Subject: [PATCH 1/4] add the apple app store engine The Apple App Store is the digital app distribution platform for iOS & iPadOS. --- searx/engines/apple_app_store.py | 51 ++++++++++++++++++++++++++++++++ searx/settings.yml | 5 ++++ 2 files changed, 56 insertions(+) create mode 100644 searx/engines/apple_app_store.py diff --git a/searx/engines/apple_app_store.py b/searx/engines/apple_app_store.py new file mode 100644 index 000000000..8cb1e55b1 --- /dev/null +++ b/searx/engines/apple_app_store.py @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# lint: pylint +""" + Apple App Store +""" + +from json import loads +from urllib.parse import urlencode +from dateutil.parser import parse + +about = { + "website": 'https://www.apple.com/app-store/', + "wikidata_id": 'Q368215', + "official_api_documentation": ( + 'https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/' + 'iTuneSearchAPI/UnderstandingSearchResults.html#//apple_ref/doc/uid/TP40017632-CH8-SW1' + ), + "use_official_api": True, + "require_api_key": False, + "results": 'JSON', +} + +categories = ['files', 'apps'] + +search_url = 'https://itunes.apple.com/search?{query}' + + +def request(query, params): + params['url'] = search_url.format(query=urlencode({'term': query, 'media': 'software'})) + + return params + + +def response(resp): + results = [] + + json_result = loads(resp.text) + + for result in json_result['results']: + results.append( + { + 'url': result['trackViewUrl'], + 'title': result['trackName'], + 'content': result['sellerName'] + ': ' + result['description'], + 'img_src': result['artworkUrl100'], + 'thumbnail': result['screenshotUrls'][0], + 'publishedDate': parse(result['currentVersionReleaseDate']), + } + ) + + return results diff --git a/searx/settings.yml b/searx/settings.yml index a61be1071..82fa9c165 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -268,6 +268,11 @@ engines: shortcut: apkm disabled: true + - name: apple app store + engine: apple_app_store + shortcut: aps + disabled: true + # Requires Tor - name: ahmia engine: ahmia From bcae7ae4e3861959102a5a2c903b829dc5a22d6a Mon Sep 17 00:00:00 2001 From: ta Date: Wed, 24 Aug 2022 17:50:38 +0700 Subject: [PATCH 2/4] add developer info as author --- searx/engines/apple_app_store.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/searx/engines/apple_app_store.py b/searx/engines/apple_app_store.py index 8cb1e55b1..fe8f6ec83 100644 --- a/searx/engines/apple_app_store.py +++ b/searx/engines/apple_app_store.py @@ -41,10 +41,11 @@ def response(resp): { 'url': result['trackViewUrl'], 'title': result['trackName'], - 'content': result['sellerName'] + ': ' + result['description'], + 'content': result['description'], 'img_src': result['artworkUrl100'], 'thumbnail': result['screenshotUrls'][0], 'publishedDate': parse(result['currentVersionReleaseDate']), + 'author': result['sellerName'], } ) From 78bff4618cd4db242d4b7e27ef42b465a0df5484 Mon Sep 17 00:00:00 2001 From: ta Date: Wed, 24 Aug 2022 18:31:04 +0700 Subject: [PATCH 3/4] add safesearch support --- searx/engines/apple_app_store.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/searx/engines/apple_app_store.py b/searx/engines/apple_app_store.py index fe8f6ec83..112c58224 100644 --- a/searx/engines/apple_app_store.py +++ b/searx/engines/apple_app_store.py @@ -21,12 +21,18 @@ about = { } categories = ['files', 'apps'] +safesearch = True search_url = 'https://itunes.apple.com/search?{query}' def request(query, params): - params['url'] = search_url.format(query=urlencode({'term': query, 'media': 'software'})) + explicit = "Yes" + + if params['safesearch'] > 0: + explicit = "No" + + params['url'] = search_url.format(query=urlencode({'term': query, 'media': 'software', 'explicit': explicit})) return params From 5057007270070c58123b3e2740d17316ffee273b Mon Sep 17 00:00:00 2001 From: ta Date: Sat, 27 Aug 2022 06:23:30 +0700 Subject: [PATCH 4/4] remove thumbnail from results --- searx/engines/apple_app_store.py | 1 - 1 file changed, 1 deletion(-) diff --git a/searx/engines/apple_app_store.py b/searx/engines/apple_app_store.py index 112c58224..f75a1a657 100644 --- a/searx/engines/apple_app_store.py +++ b/searx/engines/apple_app_store.py @@ -49,7 +49,6 @@ def response(resp): 'title': result['trackName'], 'content': result['description'], 'img_src': result['artworkUrl100'], - 'thumbnail': result['screenshotUrls'][0], 'publishedDate': parse(result['currentVersionReleaseDate']), 'author': result['sellerName'], }