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

Functions

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

Variables

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

Detailed Description

SoundCloud is a German audio streaming service.

Function Documentation

◆ get_client_id()

str searx.engines.soundcloud.get_client_id ( )

Definition at line 112 of file soundcloud.py.

112def get_client_id() -> str:
113
114 client_id = ""
115 url = "https://soundcloud.com"
116 resp = http_get(url, timeout=10)
117
118 if not resp.ok:
119 logger.error("init: GET %s failed", url)
120 return client_id
121
122 tree = html.fromstring(resp.content)
123 script_tags = tree.xpath("//script[contains(@src, '/assets/')]")
124 app_js_urls = [tag.get("src") for tag in script_tags if tag is not None]
125
126 # extracts valid app_js urls from soundcloud.com content
127
128 for url in app_js_urls[::-1]:
129
130 # gets app_js and search for the client_id
131 resp = http_get(url)
132
133 if not resp.ok:
134 logger.error("init: app_js GET %s failed", url)
135 continue
136
137 cids = cid_re.search(resp.content.decode())
138 if cids and len(cids.groups()):
139 client_id = cids.groups()[0]
140 break
141
142 if client_id:
143 logger.info("using client_id '%s' for soundclud queries", client_id)
144 else:
145 logger.warning("missing valid client_id for soundclud queries")
146 return client_id

Referenced by init().

+ Here is the caller graph for this function:

◆ init()

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

Definition at line 107 of file soundcloud.py.

107def init(engine_settings=None): # pylint: disable=unused-argument
108 global guest_client_id # pylint: disable=global-statement
109 guest_client_id = get_client_id()
110
111

References get_client_id().

+ Here is the call graph for this function:

◆ request()

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

Definition at line 52 of file soundcloud.py.

52def request(query, params):
53
54 # missing attributes: user_id, app_version
55 # - user_id=451561-497874-703312-310156
56 # - app_version=1740727428
57
58 args = {
59 "q": query,
60 "offset": (params['pageno'] - 1) * results_per_page,
61 "limit": results_per_page,
62 "facet": soundcloud_facet,
63 "client_id": guest_client_id,
64 "app_locale": app_locale_map.get(params["language"].split("-")[0], "en"),
65 }
66
67 params['url'] = f"{search_url}?{urlencode(args)}"
68 return params
69
70

◆ response()

searx.engines.soundcloud.response ( resp)

Definition at line 71 of file soundcloud.py.

71def response(resp):
72 results = []
73 data = resp.json()
74
75 for result in data.get("collection", []):
76
77 if result["kind"] in ("track", "playlist"):
78 url = result.get("permalink_url")
79 if not url:
80 continue
81 uri = quote_plus(result.get("uri"))
82 content = [
83 result.get("description"),
84 result.get("label_name"),
85 ]
86 res = {
87 "url": url,
88 "title": result["title"],
89 "content": " / ".join([c for c in content if c]),
90 "publishedDate": parser.parse(result["last_modified"]),
91 "iframe_src": "https://w.soundcloud.com/player/?url=" + uri,
92 "views": result.get("likes_count"),
93 }
94 thumbnail = result["artwork_url"] or result["user"]["avatar_url"]
95 res["thumbnail"] = thumbnail or None
96 length = int(result.get("duration", 0) / 1000)
97 if length:
98 length = datetime.timedelta(seconds=length)
99 res["length"] = length
100 res["views"] = result.get("playback_count", 0) or None
101 res["author"] = result.get("user", {}).get("full_name") or None
102 results.append(res)
103
104 return results
105
106

Variable Documentation

◆ about

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

Definition at line 13 of file soundcloud.py.

◆ app_locale_map

dict searx.engines.soundcloud.app_locale_map
Initial value:
1= {
2 "de": "de",
3 "en": "en",
4 "es": "es",
5 "fr": "fr",
6 "oc": "fr",
7 "it": "it",
8 "nl": "nl",
9 "pl": "pl",
10 "szl": "pl",
11 "pt": "pt_BR",
12 "pap": "pt_BR",
13 "sv": "sv",
14}

Definition at line 36 of file soundcloud.py.

◆ categories

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

Definition at line 22 of file soundcloud.py.

◆ cid_re

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

Definition at line 30 of file soundcloud.py.

◆ guest_client_id

str searx.engines.soundcloud.guest_client_id = ""

Definition at line 31 of file soundcloud.py.

◆ paging

bool searx.engines.soundcloud.paging = True

Definition at line 23 of file soundcloud.py.

◆ results_per_page

int searx.engines.soundcloud.results_per_page = 10

Definition at line 32 of file soundcloud.py.

◆ search_url

str searx.engines.soundcloud.search_url = "https://api-v2.soundcloud.com/search"

Definition at line 25 of file soundcloud.py.

◆ soundcloud_facet

str searx.engines.soundcloud.soundcloud_facet = "model"

Definition at line 34 of file soundcloud.py.