.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.soundcloud Namespace Reference

Functions

 get_client_id ()
 
 init (engine_settings=None)
 
 request (query, params)
 
 response (resp)
 

Variables

dict about
 
list categories = ['music']
 
bool paging = True
 
str url = 'https://api-v2.soundcloud.com/'
 
tuple search_url
 
 cid_re = re.compile(r'client_id:"([^"]*)"', re.I | re.U)
 
str guest_client_id = ''
 

Detailed Description

 Soundcloud (Music)

Function Documentation

◆ get_client_id()

searx.engines.soundcloud.get_client_id ( )

Definition at line 44 of file soundcloud.py.

44def get_client_id():
45 resp = http_get("https://soundcloud.com")
46
47 if resp.ok:
48 tree = html.fromstring(resp.content)
49 # script_tags has been moved from /assets/app/ to /assets/ path. I
50 # found client_id in https://a-v2.sndcdn.com/assets/49-a0c01933-3.js
51 script_tags = tree.xpath("//script[contains(@src, '/assets/')]")
52 app_js_urls = [script_tag.get('src') for script_tag in script_tags if script_tag is not None]
53
54 # extracts valid app_js urls from soundcloud.com content
55 for app_js_url in app_js_urls[::-1]:
56 # gets app_js and searches for the clientid
57 resp = http_get(app_js_url)
58 if resp.ok:
59 cids = cid_re.search(resp.content.decode())
60 if cids is not None and len(cids.groups()):
61 return cids.groups()[0]
62 logger.warning("Unable to fetch guest client_id from SoundCloud, check parser!")
63 return ""
64
65

Referenced by searx.engines.soundcloud.init().

+ Here is the caller graph for this function:

◆ init()

searx.engines.soundcloud.init ( engine_settings = None)

Definition at line 66 of file soundcloud.py.

66def init(engine_settings=None): # pylint: disable=unused-argument
67 global guest_client_id # pylint: disable=global-statement
68 # api-key
69 guest_client_id = get_client_id()
70
71
72# do search-request

References searx.engines.soundcloud.get_client_id().

+ Here is the call graph for this function:

◆ request()

searx.engines.soundcloud.request ( query,
params )

Definition at line 73 of file soundcloud.py.

73def request(query, params):
74 offset = (params['pageno'] - 1) * 20
75
76 params['url'] = search_url.format(query=urlencode({'q': query}), offset=offset, client_id=guest_client_id)
77
78 return params
79
80

◆ response()

searx.engines.soundcloud.response ( resp)

Definition at line 81 of file soundcloud.py.

81def response(resp):
82 results = []
83 search_res = loads(resp.text)
84
85 # parse results
86 for result in search_res.get('collection', []):
87
88 if result['kind'] in ('track', 'playlist'):
89 uri = quote_plus(result['uri'])
90 res = {
91 'url': result['permalink_url'],
92 'title': result['title'],
93 'content': result['description'] or '',
94 'publishedDate': parser.parse(result['last_modified']),
95 'iframe_src': "https://w.soundcloud.com/player/?url=" + uri,
96 }
97 thumbnail = result['artwork_url'] or result['user']['avatar_url']
98 if thumbnail:
99 res['thumbnail'] = thumbnail
100 results.append(res)
101
102 return results

Variable Documentation

◆ about

dict searx.engines.soundcloud.about
Initial value:
1= {
2 "website": 'https://soundcloud.com',
3 "wikidata_id": 'Q568769',
4 "official_api_documentation": 'https://developers.soundcloud.com/',
5 "use_official_api": True,
6 "require_api_key": False,
7 "results": 'JSON',
8}

Definition at line 14 of file soundcloud.py.

◆ categories

list searx.engines.soundcloud.categories = ['music']

Definition at line 24 of file soundcloud.py.

◆ cid_re

searx.engines.soundcloud.cid_re = re.compile(r'client_id:"([^"]*)"', re.I | re.U)

Definition at line 40 of file soundcloud.py.

◆ guest_client_id

str searx.engines.soundcloud.guest_client_id = ''

Definition at line 41 of file soundcloud.py.

◆ paging

bool searx.engines.soundcloud.paging = True

Definition at line 25 of file soundcloud.py.

◆ search_url

tuple searx.engines.soundcloud.search_url
Initial value:
1= (
2 url + 'search?{query}'
3 '&variant_ids='
4 '&facet=model'
5 '&limit=20'
6 '&offset={offset}'
7 '&linked_partitioning=1'
8 '&client_id={client_id}'
9)

Definition at line 30 of file soundcloud.py.

◆ url

str searx.engines.soundcloud.url = 'https://api-v2.soundcloud.com/'

Definition at line 29 of file soundcloud.py.