Skip to content

Commit

Permalink
Merge pull request #23 from natumbri/original_repo
Browse files Browse the repository at this point in the history
add bndcmpr support
  • Loading branch information
impliedchaos authored Dec 18, 2023
2 parents be71385 + 1d8e218 commit fa1f927
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ Note: Adding an artist by clicking on the artist in a search result or by manual
bandcamp page can take a long time depending on the artist. This is because Mopidy-Bandcamp tries to load
the entirety of the artist's discography.

Mopidy-Bandcamp also supports bndcmpr.co playlists. Just get the playlist id from the bndcmpr url, prepend with
"bandcamp:bndcmpr" and add it to Mopidy. For example, to add this bndcmpr playlist "https://bndcmpr.co/4dfdd589"
using mpc on the command line:

.. code:: shell
$ mpc add "bandcamp:bndcmpr:4dfdd589"
Would add all the tracks in the bndcmpr playlist to the queue.

Web Client
----------
Expand All @@ -107,7 +116,8 @@ as a URL for a bookmark in your web browser:
Note: Replace *hostname* and *6680* with your mopidy server's hostname and configured HTTP port.

Now when you're browsing bandcamp you can simply click that bookmark to add the current page to Mopidy.
Now when you're browsing bandcamp (or a bndcmpr playlist) you can simply click that bookmark to add the
current page to Mopidy.
(This works in Chrome and Firefox. I haven't bothered checking anything else.)

Configuration
Expand Down
11 changes: 11 additions & 0 deletions mopidy_bandcamp/library.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import datetime
import hashlib
import json
import re

from concurrent.futures.thread import ThreadPoolExecutor

from mopidy import backend
from mopidy.models import Album, Artist, Image, Ref, SearchResult, Track
from urllib.parse import quote
Expand Down Expand Up @@ -295,6 +298,14 @@ def lookup(self, uri):
f"bandcamp:track:{disc['band_id']}-0-{disc['item_id']}"
)
)
elif func == "bndcmpr":
bndcmpr_raw = self.backend.bandcamp._get(f"https://bndcmpr.co/api/list/{bcId}")
bndcmpr_tracks = json.loads(bndcmpr_raw["tracks"].encode().decode())
bndcmpr_uris = [f'bandcamp:{track["url"]}' for track in bndcmpr_tracks]
with ThreadPoolExecutor(4) as executor:
futures = executor.map(self.lookup, bndcmpr_uris)
[ret.extend(value) for value in futures if value is not None]
return ret
elif re.match(r"^https?", func, re.I):
url = uri[9:]
try:
Expand Down
5 changes: 5 additions & 0 deletions mopidy_bandcamp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ def get(self):
self.write(
"<!DOCTYPE html><html><head><title>URL Added</title><script>alert('URL has been added.');window.history.back()</script></head></html>"
)
elif re.match(r"^https?://bndcmpr\.co/", url):
self.core.tracklist.add(uris=[f"bandcamp:bndcmpr:{url[-8:]}"])
self.write(
"<!DOCTYPE html><html><head><title>BNDCMPR Playlist Added</title><script>alert('BNDCMPR Playlist has been added.');window.history.back()</script></head></html>"
)
else:
self.write(
"<!DOCTYPE html><html><head><title>Error</title></head><body><h1>Error</h1><p>Invalid URL: &quot;%s&quot;</p></body></html>"
Expand Down

0 comments on commit fa1f927

Please sign in to comment.