Skip to content

Commit c9f82fa

Browse files
authored
[plugin.audio.kxmxpxtx.bandcamp] v0.5.2+matrix.1 (#4653)
1 parent 137c212 commit c9f82fa

2 files changed

Lines changed: 27 additions & 16 deletions

File tree

plugin.audio.kxmxpxtx.bandcamp/addon.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<addon id="plugin.audio.kxmxpxtx.bandcamp" name="Bandcamp" version="0.5.1+matrix.1" provider-name="Simon Mollema">
2+
<addon id="plugin.audio.kxmxpxtx.bandcamp" name="Bandcamp" version="0.5.2+matrix.1" provider-name="Simon Mollema">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0"/>
55
<import addon="script.module.future" version="0.18.2+matrix.1"/>
@@ -15,7 +15,12 @@
1515
<platform>all</platform>
1616
<email>xbmc@molzy.com</email>
1717
<source>https://github.com/molzy/plugin.audio.kxmxpxtx.bandcamp</source>
18-
<news>v0.5.1+matrix.1 (2024-08)
18+
<news>v0.5.2+matrix.1 (2025-04)
19+
- Fixed search function which was broken due to upstream change
20+
- Thank you to everyone who reported and contributed a fix!
21+
- Extended API timeout, to help those with a large collection or wishlist
22+
23+
v0.5.1+matrix.1 (2024-08)
1924
- Resolved 403 forbidden error when accessing bandcamp API
2025

2126
v0.5.0+matrix.1 (2023-01)

plugin.audio.kxmxpxtx.bandcamp/resources/lib/bandcamp_api/bandcamp.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,21 @@
1414
from builtins import *
1515
from html.parser import HTMLParser
1616

17-
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36'
18-
19-
def urlopen_ua(url, data=None):
20-
return urlopen(Request(url, data=data, headers={'User-Agent': USER_AGENT}), timeout=5)
21-
22-
def req(url, data=None):
17+
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.3'
18+
19+
def urlopen_ua(url, data=None, content_type=None):
20+
headers = {'User-Agent': USER_AGENT}
21+
if content_type is not None:
22+
headers['Content-Type'] = content_type
23+
return urlopen(Request(url, data=data, headers=headers), timeout=15)
24+
25+
def req(url, data=None, content_type=None):
26+
if isinstance(data, dict):
27+
data = json.dumps(data)
28+
if content_type is None:
29+
content_type = 'application/json'
2330
body = data.encode() if data else None
24-
return urlopen_ua(url, data=body).read().decode()
31+
return urlopen_ua(url, data=body, content_type=content_type).read().decode()
2532

2633
class Band:
2734
def __init__(self, band_id=None, band_name="", band_img=None):
@@ -127,8 +134,7 @@ def get_subgenres(self):
127134
def get_collection(self, fan_id, count=1000, return_albums=False):
128135
url = "https://bandcamp.com/api/fancollection/1/collection_items"
129136
token = self._get_token()
130-
body = '{{"fan_id": "{fan_id}", "older_than_token": "{token}", "count":"{count}"}}' \
131-
.format(fan_id=fan_id, token=token, count=count)
137+
body = {"fan_id": fan_id, "older_than_token": token, "count": count}
132138
x = req(url, data=body)
133139
items = json.loads(x)['items']
134140
bands = {}
@@ -150,8 +156,7 @@ def get_collection(self, fan_id, count=1000, return_albums=False):
150156
def get_wishlist(self, fan_id, count=1000, return_albums=False):
151157
url = "https://bandcamp.com/api/fancollection/1/wishlist_items"
152158
token = self._get_token()
153-
body = '{{"fan_id": "{fan_id}", "older_than_token": "{token}", "count":"{count}"}}' \
154-
.format(fan_id=fan_id, token=token, count=count)
159+
body = {"fan_id": fan_id, "older_than_token": token, "count": count}
155160
x = req(url, data=body)
156161
items = json.loads(x)['items']
157162
bands = {}
@@ -224,7 +229,7 @@ def get_album_by_url(self, url):
224229

225230
def get_band(self, band_id):
226231
url = "https://bandcamp.com/api/mobile/24/band_details"
227-
body = '{{"band_id": "{band_id}"}}'.format(band_id=band_id)
232+
body = {"band_id": band_id}
228233
request = req(url, data=body)
229234
band_details = json.loads(request)
230235
band = Band(band_id=band_details['id'], band_name=band_details['name'],
@@ -239,8 +244,9 @@ def get_band(self, band_id):
239244
def search(self, query):
240245
if PY2:
241246
query = query.decode('utf-8')
242-
url = "https://bandcamp.com/api/fuzzysearch/1/autocomplete?q={query}".format(query=quote_plus(query))
243-
request = req(url)
247+
url = "https://bandcamp.com/api/bcsearch_public_api/1/autocomplete_elastic"
248+
body = {"full_page": False, "search_filter": "", "search_text": query}
249+
request = req(url, data=body)
244250
results = json.loads(request)['auto']['results']
245251
items = []
246252
for result in results:

0 commit comments

Comments
 (0)