| 
									
										
										
										
											2022-08-24 12:27:36 +02:00
										 |  |  | # SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							| 
									
										
										
										
											2024-03-11 07:45:08 +01:00
										 |  |  | """Apple App Store
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-24 12:27:36 +02:00
										 |  |  | """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 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'] | 
					
						
							| 
									
										
										
										
											2022-08-24 13:31:04 +02:00
										 |  |  | safesearch = True | 
					
						
							| 
									
										
										
										
											2022-08-24 12:27:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | search_url = 'https://itunes.apple.com/search?{query}' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def request(query, params): | 
					
						
							| 
									
										
										
										
											2022-08-24 13:31:04 +02:00
										 |  |  |     explicit = "Yes" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if params['safesearch'] > 0: | 
					
						
							|  |  |  |         explicit = "No" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     params['url'] = search_url.format(query=urlencode({'term': query, 'media': 'software', 'explicit': explicit})) | 
					
						
							| 
									
										
										
										
											2022-08-24 12:27:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     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'], | 
					
						
							| 
									
										
										
										
											2022-08-24 12:50:38 +02:00
										 |  |  |                 'content': result['description'], | 
					
						
							| 
									
										
										
										
											2024-05-12 17:52:52 +02:00
										 |  |  |                 'thumbnail': result['artworkUrl100'], | 
					
						
							| 
									
										
										
										
											2022-08-24 12:27:36 +02:00
										 |  |  |                 'publishedDate': parse(result['currentVersionReleaseDate']), | 
					
						
							| 
									
										
										
										
											2022-08-24 12:50:38 +02:00
										 |  |  |                 'author': result['sellerName'], | 
					
						
							| 
									
										
										
										
											2022-08-24 12:27:36 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return results |