mopidy: fix bandcamp plugin

This commit is contained in:
Kate 2025-02-02 16:23:00 +01:00
parent 4ed7283490
commit ce8a2e6453
5 changed files with 149 additions and 48 deletions

95
flake.lock generated
View file

@ -99,16 +99,17 @@
"base16-vim": {
"flake": false,
"locked": {
"lastModified": 1735953590,
"narHash": "sha256-YbQwaApLFJobn/0lbpMKcJ8N5axKlW2QIGkDS5+xoSU=",
"lastModified": 1732806396,
"narHash": "sha256-e0bpPySdJf0F68Ndanwm+KWHgQiZ0s7liLhvJSWDNsA=",
"owner": "tinted-theming",
"repo": "base16-vim",
"rev": "c2a1232aa2c0ed27dcbf005779bcfe0e0ab5e85d",
"rev": "577fe8125d74ff456cf942c733a85d769afe58b7",
"type": "github"
},
"original": {
"owner": "tinted-theming",
"repo": "base16-vim",
"rev": "577fe8125d74ff456cf942c733a85d769afe58b7",
"type": "github"
}
},
@ -162,11 +163,11 @@
]
},
"locked": {
"lastModified": 1737504076,
"narHash": "sha256-/B4XJnzYU/6K1ZZOBIgsa3K4pqDJrnC2579c44c+4rI=",
"lastModified": 1738033138,
"narHash": "sha256-qlIM8A3bdL9c6PexhpS+QyZLO9y/8a3V75HVyJgDE5Q=",
"owner": "lnl7",
"repo": "nix-darwin",
"rev": "65cc1fa8e36ceff067daf6cfb142331f02f524d3",
"rev": "349a74c66c596ef97ee97b4d80a3ca61227b6120",
"type": "github"
},
"original": {
@ -182,11 +183,11 @@
"nixpkgs": "nixpkgs_2"
},
"locked": {
"lastModified": 1733098767,
"narHash": "sha256-XLxNWOclBjSrzbbLQoOUNWyuF306/R0n4mMGxT3a698=",
"lastModified": 1738140586,
"narHash": "sha256-Vn4PD4eH18QklgDY1vnjXJqNPmP3SJNejcBroW0yTTA=",
"owner": "mirrexagon",
"repo": "nixpkgs-esp-dev",
"rev": "31ee58005f43e93a6264e3667c9bf5c31b368733",
"rev": "29517b39abe729e04118bf77af526f9947f6c476",
"type": "github"
},
"original": {
@ -482,11 +483,11 @@
]
},
"locked": {
"lastModified": 1737704314,
"narHash": "sha256-zta8jvOQ2wRCZmiwFEnS5iCulWAh8e+fLUlQxrgOBjM=",
"lastModified": 1738228963,
"narHash": "sha256-Ee5hVHM7AWxaq7XJN6xiZztTZX8csdXernjqaTW5r9I=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "a0428685572b134f6594e7d7f5db5e1febbab2d7",
"rev": "d963ed335b890a70ed53eecf14cdb21528eda9b8",
"type": "github"
},
"original": {
@ -526,11 +527,11 @@
"pre-commit-hooks": "pre-commit-hooks"
},
"locked": {
"lastModified": 1737739244,
"narHash": "sha256-D0hxQ9BkIV6J9c6uoEFt667LMhl2LvX6ptHUWK6VP8I=",
"lastModified": 1738174211,
"narHash": "sha256-eYmp1mKM4kULV1W+EBtCPk6LmKWl2REivaYfGRl+AWo=",
"ref": "refs/heads/main",
"rev": "523bd9dce89c29cda3b50f78911d534556775f5f",
"revCount": 16683,
"rev": "64e33a7e09a0d1faacf2fd3f6ebd647fe4d8346a",
"revCount": 17329,
"type": "git",
"url": "https://git@git.lix.systems/lix-project/lix"
},
@ -569,11 +570,11 @@
"xwayland-satellite-unstable": "xwayland-satellite-unstable"
},
"locked": {
"lastModified": 1737746480,
"narHash": "sha256-Lccg6b+Sz6TSDj4BpLZhugauwDa/CyCjF7E6W3VvYa0=",
"lastModified": 1738237661,
"narHash": "sha256-9QNTd6lazGEqDEkI13itPwq6uvh9z7LGmn4OY1+xAL0=",
"owner": "sodiboo",
"repo": "niri-flake",
"rev": "afeb7877090d50d02c1ecab3159b328b85a44868",
"rev": "5921aa096d1bc92fb1960f8f1db78f58a96b4c51",
"type": "github"
},
"original": {
@ -602,11 +603,11 @@
"niri-unstable": {
"flake": false,
"locked": {
"lastModified": 1737697331,
"narHash": "sha256-9k77pFW2ANx8bZc+RcF6YP9McFZsUCWWY+XwBX0P3/Q=",
"lastModified": 1738234654,
"narHash": "sha256-HJR2r/e4ZxbAfLYHNrQD8vaxZDZvKpma9jchJr8zYH8=",
"owner": "YaLTeR",
"repo": "niri",
"rev": "748d90b443b9f20134020c21760b5b6c2c42a7de",
"rev": "fb5fedbf24aa66909bb9d112856f27ceb04766a8",
"type": "github"
},
"original": {
@ -698,11 +699,11 @@
},
"nix-hardware": {
"locked": {
"lastModified": 1737590910,
"narHash": "sha256-qM/y6Dtpu9Wmf5HqeZajQdn+cS0aljdYQQQnrvx+LJE=",
"lastModified": 1737751639,
"narHash": "sha256-ZEbOJ9iT72iwqXsiEMbEa8wWjyFvRA9Ugx8utmYbpz4=",
"owner": "nixos",
"repo": "nixos-hardware",
"rev": "9368027715d8dde4b84c79c374948b5306fdd2db",
"rev": "dfad538f751a5aa5d4436d9781ab27a6128ec9d4",
"type": "github"
},
"original": {
@ -757,11 +758,11 @@
},
"nixos-hardware": {
"locked": {
"lastModified": 1737590910,
"narHash": "sha256-qM/y6Dtpu9Wmf5HqeZajQdn+cS0aljdYQQQnrvx+LJE=",
"lastModified": 1737751639,
"narHash": "sha256-ZEbOJ9iT72iwqXsiEMbEa8wWjyFvRA9Ugx8utmYbpz4=",
"owner": "NixOS",
"repo": "nixos-hardware",
"rev": "9368027715d8dde4b84c79c374948b5306fdd2db",
"rev": "dfad538f751a5aa5d4436d9781ab27a6128ec9d4",
"type": "github"
},
"original": {
@ -851,11 +852,11 @@
},
"nixpkgs-stable_2": {
"locked": {
"lastModified": 1737672001,
"narHash": "sha256-YnHJJ19wqmibLQdUeq9xzE6CjrMA568KN/lFPuSVs4I=",
"lastModified": 1738163270,
"narHash": "sha256-B/7Y1v4y+msFFBW1JAdFjNvVthvNdJKiN6EGRPnqfno=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "035f8c0853c2977b24ffc4d0a42c74f00b182cd8",
"rev": "59e618d90c065f55ae48446f307e8c09565d5ab0",
"type": "github"
},
"original": {
@ -914,11 +915,11 @@
},
"nixpkgs_5": {
"locked": {
"lastModified": 1737632463,
"narHash": "sha256-38J9QfeGSej341ouwzqf77WIHAScihAKCt8PQJ+NH28=",
"lastModified": 1738142207,
"narHash": "sha256-NGqpVVxNAHwIicXpgaVqJEJWeyqzoQJ9oc8lnK9+WC4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0aa475546ed21629c4f5bbf90e38c846a99ec9e9",
"rev": "9d3ae807ebd2981d593cddd0080856873139aa40",
"type": "github"
},
"original": {
@ -930,11 +931,11 @@
},
"nixpkgs_6": {
"locked": {
"lastModified": 1737632463,
"narHash": "sha256-38J9QfeGSej341ouwzqf77WIHAScihAKCt8PQJ+NH28=",
"lastModified": 1738142207,
"narHash": "sha256-NGqpVVxNAHwIicXpgaVqJEJWeyqzoQJ9oc8lnK9+WC4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0aa475546ed21629c4f5bbf90e38c846a99ec9e9",
"rev": "9d3ae807ebd2981d593cddd0080856873139aa40",
"type": "github"
},
"original": {
@ -961,10 +962,10 @@
},
"nixpkgs_8": {
"locked": {
"lastModified": 1736883708,
"narHash": "sha256-uQ+NQ0/xYU0N1CnXsa2zghgNaOPxWpMJXSUJJ9W7140=",
"path": "/nix/store/xb4yfxa32hsjpincdgjv7xdq9kyys8l9-source",
"rev": "eb62e6aa39ea67e0b8018ba8ea077efe65807dc8",
"lastModified": 1737632463,
"narHash": "sha256-38J9QfeGSej341ouwzqf77WIHAScihAKCt8PQJ+NH28=",
"path": "/nix/store/8dh0832snzamw6wk2rdfjz29xdzgma49-source",
"rev": "0aa475546ed21629c4f5bbf90e38c846a99ec9e9",
"type": "path"
},
"original": {
@ -1142,11 +1143,11 @@
"tinted-zed": "tinted-zed"
},
"locked": {
"lastModified": 1737657729,
"narHash": "sha256-TIDR1zKoP2uaqRot/LnarugfAC9U7geycjbJqA1naVM=",
"lastModified": 1738025638,
"narHash": "sha256-nU3JpvIeEmcDHzQK4OTD1KXSoL/GOff6j9kuSO4X8eM=",
"owner": "danth",
"repo": "stylix",
"rev": "e594886eb0951a0a0c28ffa333a9df6fb13857a1",
"rev": "55418e8fc8d4696af619176a22cefcfac56ad2ef",
"type": "github"
},
"original": {
@ -1371,11 +1372,11 @@
"xwayland-satellite-unstable": {
"flake": false,
"locked": {
"lastModified": 1736487362,
"narHash": "sha256-4kGoOA7FgK9N2mzS+TFEn41kUUNY6KwdiA/0rqlr868=",
"lastModified": 1737837494,
"narHash": "sha256-wIMowP8Juas4ZwMRcpc+58sZ0kKTDu8fm13THPmv/F8=",
"owner": "Supreeeme",
"repo": "xwayland-satellite",
"rev": "8f55e27f63a749881c4bbfbb6b1da028342a91d1",
"rev": "3944c9a0e40e5629f16ad023bbc90dac80d35a0f",
"type": "github"
},
"original": {

View file

@ -0,0 +1,97 @@
diff --git a/mopidy_bandcamp/bandcamp.py b/mopidy_bandcamp/bandcamp.py
index ff8c737..7d0b866 100644
--- a/mopidy_bandcamp/bandcamp.py
+++ b/mopidy_bandcamp/bandcamp.py
@@ -2,11 +2,38 @@ import json
import mopidy_bandcamp
import re
import requests
+import ssl
from html import unescape
from mopidy import httpclient
from time import time
+from requests.adapters import HTTPAdapter
+class BandcampHTTPAdapter(HTTPAdapter):
+ def init_poolmanager(self, *args, **kwargs):
+ context = ssl.create_default_context()
+ DEFAULT_CIPHERS = ":".join(
+ [
+ "ECDHE+AESGCM",
+ "ECDHE+CHACHA20",
+ "DHE+AESGCM",
+ "DHE+CHACHA20",
+ "ECDH+AESGCM",
+ "DH+AESGCM",
+ "ECDH+AES",
+ "DH+AES",
+ "RSA+AESGCM",
+ "RSA+AES",
+ "!aNULL",
+ "!eNULL",
+ "!MD5",
+ "!DSS",
+ "!AESCCM",
+ ]
+ )
+ context.set_ciphers(DEFAULT_CIPHERS)
+ kwargs["ssl_context"] = context
+ return super().init_poolmanager(*args, **kwargs)
class BandcampClient:
BASE_URL = "https://bandcamp.com/api"
@@ -43,6 +70,8 @@ class BandcampClient:
}
def __init__(self, config):
+ self.bandcamp_session = requests.Session()
+ self.bandcamp_session.mount("https://", BandcampHTTPAdapter())
self.proxy = httpclient.format_proxy(config["proxy"])
self.ua_str = httpclient.format_user_agent(
f"{mopidy_bandcamp.Extension.dist_name}/{mopidy_bandcamp.__version__}"
@@ -53,7 +82,7 @@ class BandcampClient:
def _get(self, *args, **kwargs):
headers = {"User-Agent": self.ua_str}
- resp = requests.get(*args, **kwargs, headers=headers, proxies=self.proxy)
+ resp = self.bandcamp_session.get(*args, **kwargs, headers=headers, proxies=self.proxy)
resp.raise_for_status()
js = resp.json()
if "error" in js:
@@ -62,7 +91,7 @@ class BandcampClient:
def _post(self, *args, **kwargs):
headers = {"User-Agent": self.ua_str}
- resp = requests.post(*args, **kwargs, headers=headers, proxies=self.proxy)
+ resp = self.bandcamp_session.post(*args, **kwargs, headers=headers, proxies=self.proxy)
resp.raise_for_status()
js = resp.json()
if "error" in js:
@@ -73,7 +102,7 @@ class BandcampClient:
headers = {"User-Agent": self.ua_str}
if self.identity:
headers["Cookie"] = f"identity={self.identity}"
- resp = requests.get(uri, headers=headers, proxies=self.proxy)
+ resp = self.bandcamp_session.get(uri, headers=headers, proxies=self.proxy)
resp.raise_for_status()
# Build the tralbum data by joining multiple json chunks.
data = re.search(r'\s+data-tralbum="(.*?)"', resp.text)
@@ -127,7 +156,7 @@ class BandcampClient:
return []
headers = {"User-Agent": self.ua_str, "Cookie": f"identity={self.identity}"}
if self.fan_id is None:
- resp = requests.get(
+ resp = self.bandcamp_session.get(
self.BASE_URL + "/fan/2/collection_summary",
headers=headers,
proxies=self.proxy,
@@ -141,7 +170,7 @@ class BandcampClient:
endpoint = "wishlist_items"
elif ctype == "following":
endpoint = "following_bands"
- resp = requests.post(
+ resp = self.bandcamp_session.post(
self.BASE_URL + "/fancollection/1/" + endpoint,
headers=headers,
proxies=self.proxy,

View file

@ -19,7 +19,9 @@
mopidy-iris
mopidy-mpd
mopidy-tidal
mopidy-bandcamp
(mopidy-bandcamp.overrideAttrs (prev: {
patches = [ ./001-fix-mopidy-bandcamp.patch ];
}))
];
settings = {

View file

@ -117,6 +117,7 @@ with pkgs;
rclone
ripgrep
rr
translate-shell
unzip
unar
unrar