1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
|
From: "Dr. Tobias Quathamer" <toddy@debian.org>
Date: Mon, 15 Dec 2025 10:09:20 +0100
Subject: Remove deezer
---
poetry.lock | 12 ---
pyproject.toml | 1 -
streamrip/client/__init__.py | 2 -
streamrip/client/deezer.py | 226 -------------------------------------------
streamrip/rip/main.py | 3 +-
streamrip/rip/prompter.py | 44 +--------
tests/test_error_handling.py | 1 -
7 files changed, 2 insertions(+), 287 deletions(-)
delete mode 100644 streamrip/client/deezer.py
diff --git a/poetry.lock b/poetry.lock
index 3d14f16..0703e98 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -500,18 +500,6 @@ files = [
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
-[[package]]
-name = "deezer-py"
-version = "1.3.6"
-description = "A wrapper for all Deezer's APIs"
-category = "main"
-optional = false
-python-versions = ">=3.6"
-files = [
- {file = "deezer-py-1.3.6.tar.gz", hash = "sha256:a3ef151f7971d69769e7393f71373eaf896bccd22167213872ae46e04e14a2d7"},
- {file = "deezer_py-1.3.6-py3-none-any.whl", hash = "sha256:e1dcb137246cfd009400657ec07d7269a491dace210a496fe73d0e18e4690206"},
-]
-
[package.dependencies]
requests = "*"
diff --git a/pyproject.toml b/pyproject.toml
index 3f63e8b..7987656 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -27,7 +27,6 @@ simple-term-menu = { version = "^1.2.1", platform = 'darwin|linux' }
pick = { version = "^2", platform = 'win32|cygwin' }
windows-curses = { version = "^2.2.0", platform = 'win32|cygwin' }
Pillow = ">=9,<11"
-deezer-py = "1.3.6"
pycryptodomex = "^3.10.1"
appdirs = "^1.4.4"
m3u8 = "^0.9.0"
diff --git a/streamrip/client/__init__.py b/streamrip/client/__init__.py
index 4e5dd8c..7b3ea6b 100644
--- a/streamrip/client/__init__.py
+++ b/streamrip/client/__init__.py
@@ -1,5 +1,4 @@
from .client import Client
-from .deezer import DeezerClient
from .downloadable import BasicDownloadable, Downloadable
from .qobuz import QobuzClient
from .soundcloud import SoundcloudClient
@@ -7,7 +6,6 @@ from .tidal import TidalClient
__all__ = [
"Client",
- "DeezerClient",
"TidalClient",
"QobuzClient",
"SoundcloudClient",
diff --git a/streamrip/client/deezer.py b/streamrip/client/deezer.py
deleted file mode 100644
index d2642d9..0000000
--- a/streamrip/client/deezer.py
+++ /dev/null
@@ -1,226 +0,0 @@
-import asyncio
-import binascii
-import hashlib
-import logging
-
-import deezer
-from Cryptodome.Cipher import AES
-
-from ..config import Config
-from ..exceptions import (
- AuthenticationError,
- MissingCredentialsError,
- NonStreamableError,
-)
-from .client import Client
-from .downloadable import DeezerDownloadable
-
-logger = logging.getLogger("streamrip")
-logging.captureWarnings(True)
-
-
-class DeezerClient(Client):
- """Client to handle deezer API. Does not do rate limiting.
-
- Attributes:
- global_config: Entire config object
- client: client from deezer py used for API requests
- logged_in: True if logged in
- config: deezer local config
- session: aiohttp.ClientSession, used only for track downloads not API requests
-
- """
-
- source = "deezer"
- max_quality = 2
-
- def __init__(self, config: Config):
- self.global_config = config
- self.client = deezer.Deezer()
- self.logged_in = False
- self.config = config.session.deezer
-
- async def login(self):
- # Used for track downloads
- self.session = await self.get_session(
- verify_ssl=self.global_config.session.downloads.verify_ssl
- )
- arl = self.config.arl
- if not arl:
- raise MissingCredentialsError
- success = self.client.login_via_arl(arl)
- if not success:
- raise AuthenticationError
- self.logged_in = True
-
- async def get_metadata(self, item_id: str, media_type: str) -> dict:
- # TODO: open asyncio PR to deezer py and integrate
- if media_type == "track":
- return await self.get_track(item_id)
- elif media_type == "album":
- return await self.get_album(item_id)
- elif media_type == "playlist":
- return await self.get_playlist(item_id)
- elif media_type == "artist":
- return await self.get_artist(item_id)
- else:
- raise Exception(f"Media type {media_type} not available on deezer")
-
- async def get_track(self, item_id: str) -> dict:
- try:
- item = await asyncio.to_thread(self.client.api.get_track, item_id)
- except Exception as e:
- raise NonStreamableError(e)
-
- album_id = item["album"]["id"]
- try:
- album_metadata, album_tracks = await asyncio.gather(
- asyncio.to_thread(self.client.api.get_album, album_id),
- asyncio.to_thread(self.client.api.get_album_tracks, album_id),
- )
- except Exception as e:
- logger.error(f"Error fetching album of track {item_id}: {e}")
- return item
-
- album_metadata["tracks"] = album_tracks["data"]
- album_metadata["track_total"] = len(album_tracks["data"])
- item["album"] = album_metadata
-
- return item
-
- async def get_album(self, item_id: str) -> dict:
- album_metadata, album_tracks = await asyncio.gather(
- asyncio.to_thread(self.client.api.get_album, item_id),
- asyncio.to_thread(self.client.api.get_album_tracks, item_id),
- )
- album_metadata["tracks"] = album_tracks["data"]
- album_metadata["track_total"] = len(album_tracks["data"])
- return album_metadata
-
- async def get_playlist(self, item_id: str) -> dict:
- pl_metadata, pl_tracks = await asyncio.gather(
- asyncio.to_thread(self.client.api.get_playlist, item_id),
- asyncio.to_thread(self.client.api.get_playlist_tracks, item_id),
- )
- pl_metadata["tracks"] = pl_tracks["data"]
- pl_metadata["track_total"] = len(pl_tracks["data"])
- return pl_metadata
-
- async def get_artist(self, item_id: str) -> dict:
- artist, albums = await asyncio.gather(
- asyncio.to_thread(self.client.api.get_artist, item_id),
- asyncio.to_thread(self.client.api.get_artist_albums, item_id),
- )
- artist["albums"] = albums["data"]
- return artist
-
- async def search(self, media_type: str, query: str, limit: int = 200) -> list[dict]:
- # TODO: use limit parameter
- if media_type == "featured":
- try:
- if query:
- search_function = getattr(self.client.api, f"get_editorial_{query}")
- else:
- search_function = self.client.api.get_editorial_releases
- except AttributeError:
- raise Exception(f'Invalid editorical selection "{query}"')
- else:
- try:
- search_function = getattr(self.client.api, f"search_{media_type}")
- except AttributeError:
- raise Exception(f"Invalid media type {media_type}")
-
- response = search_function(query, limit=limit) # type: ignore
- if response["total"] > 0:
- return [response]
- return []
-
- async def get_downloadable(
- self,
- item_id: str,
- quality: int = 2,
- is_retry: bool = False,
- ) -> DeezerDownloadable:
- if item_id is None:
- raise NonStreamableError(
- "No item id provided. This can happen when searching for fallback songs.",
- )
- # TODO: optimize such that all of the ids are requested at once
- dl_info: dict = {"quality": quality, "id": item_id}
-
- track_info = self.client.gw.get_track(item_id)
-
- fallback_id = track_info.get("FALLBACK", {}).get("SNG_ID")
-
- quality_map = [
- (9, "MP3_128"), # quality 0
- (3, "MP3_320"), # quality 1
- (1, "FLAC"), # quality 2
- ]
-
- _, format_str = quality_map[quality]
-
- dl_info["quality_to_size"] = [
- int(track_info.get(f"FILESIZE_{format}", 0)) for _, format in quality_map
- ]
-
- token = track_info["TRACK_TOKEN"]
- try:
- logger.debug("Fetching deezer url with token %s", token)
- url = self.client.get_track_url(token, format_str)
- except deezer.WrongLicense:
- raise NonStreamableError(
- "The requested quality is not available with your subscription. "
- "Deezer HiFi is required for quality 2. Otherwise, the maximum "
- "quality allowed is 1.",
- )
- except deezer.WrongGeolocation:
- if not is_retry and fallback_id:
- return await self.get_downloadable(fallback_id, quality, is_retry=True)
- raise NonStreamableError(
- "The requested track is not available. This may be due to your country/location.",
- )
-
- if url is None:
- url = self._get_encrypted_file_url(
- item_id,
- track_info["MD5_ORIGIN"],
- track_info["MEDIA_VERSION"],
- )
-
- dl_info["url"] = url
- logger.debug("dz track info: %s", track_info)
- return DeezerDownloadable(self.session, dl_info)
-
- def _get_encrypted_file_url(
- self,
- meta_id: str,
- track_hash: str,
- media_version: str,
- ):
- logger.debug("Unable to fetch URL. Trying encryption method.")
- format_number = 1
-
- url_bytes = b"\xa4".join(
- (
- track_hash.encode(),
- str(format_number).encode(),
- str(meta_id).encode(),
- str(media_version).encode(),
- ),
- )
- url_hash = hashlib.md5(url_bytes).hexdigest()
- info_bytes = bytearray(url_hash.encode())
- info_bytes.extend(b"\xa4")
- info_bytes.extend(url_bytes)
- info_bytes.extend(b"\xa4")
- # Pad the bytes so that len(info_bytes) % 16 == 0
- padding_len = 16 - (len(info_bytes) % 16)
- info_bytes.extend(b"." * padding_len)
-
- path = binascii.hexlify(
- AES.new(b"jo6aey6haid2Teih", AES.MODE_ECB).encrypt(info_bytes),
- ).decode("utf-8")
- url = f"https://e-cdns-proxy-{track_hash[0]}.dzcdn.net/mobile/1/{path}"
- logger.debug("Encrypted file path %s", url)
- return url
diff --git a/streamrip/rip/main.py b/streamrip/rip/main.py
index 562773f..069f66e 100644
--- a/streamrip/rip/main.py
+++ b/streamrip/rip/main.py
@@ -6,7 +6,7 @@ import platform
import aiofiles
from .. import db
-from ..client import Client, DeezerClient, QobuzClient, SoundcloudClient, TidalClient
+from ..client import Client, QobuzClient, SoundcloudClient, TidalClient
from ..config import Config
from ..console import console
from ..media import (
@@ -51,7 +51,6 @@ class Main:
self.clients: dict[str, Client] = {
"qobuz": QobuzClient(config),
"tidal": TidalClient(config),
- "deezer": DeezerClient(config),
"soundcloud": SoundcloudClient(config),
}
diff --git a/streamrip/rip/prompter.py b/streamrip/rip/prompter.py
index 0cc30b8..0250852 100644
--- a/streamrip/rip/prompter.py
+++ b/streamrip/rip/prompter.py
@@ -7,7 +7,7 @@ from abc import ABC, abstractmethod
from click import launch
from rich.prompt import Prompt
-from ..client import Client, DeezerClient, QobuzClient, SoundcloudClient, TidalClient
+from ..client import Client, QobuzClient, SoundcloudClient, TidalClient
from ..config import Config
from ..console import console
from ..exceptions import AuthenticationError, MissingCredentialsError
@@ -148,47 +148,6 @@ class TidalPrompter(CredentialPrompter):
self.config.file.set_modified()
-class DeezerPrompter(CredentialPrompter):
- client: DeezerClient
-
- def has_creds(self):
- c = self.config.session.deezer
- return c.arl != ""
-
- async def prompt_and_login(self):
- if not self.has_creds():
- self._prompt_creds_and_set_session_config()
- while True:
- try:
- await self.client.login()
- break
- except AuthenticationError:
- console.print("[yellow]Invalid arl, try again.")
- self._prompt_creds_and_set_session_config()
- self.save()
-
- def _prompt_creds_and_set_session_config(self):
- console.print(
- "If you're not sure how to find the ARL cookie, see the instructions at ",
- "[blue underline]https://github.com/nathom/streamrip/wiki/Finding-your-Deezer-ARL-Cookie",
- )
- c = self.config.session.deezer
- c.arl = Prompt.ask("Enter your [bold]ARL")
-
- def save(self):
- c = self.config.session.deezer
- cf = self.config.file.deezer
- cf.arl = c.arl
- self.config.file.set_modified()
- console.print(
- f"[green]Credentials saved to config file at [bold cyan]{self.config.path}",
- )
-
- def type_check_client(self, client) -> DeezerClient:
- assert isinstance(client, DeezerClient)
- return client
-
-
class SoundcloudPrompter(CredentialPrompter):
def has_creds(self) -> bool:
return True
@@ -206,7 +165,6 @@ class SoundcloudPrompter(CredentialPrompter):
PROMPTERS = {
"qobuz": QobuzPrompter,
- "deezer": DeezerPrompter,
"tidal": TidalPrompter,
"soundcloud": SoundcloudPrompter,
}
diff --git a/tests/test_error_handling.py b/tests/test_error_handling.py
index 67f6a6e..db0b8f8 100644
--- a/tests/test_error_handling.py
+++ b/tests/test_error_handling.py
@@ -84,7 +84,6 @@ class TestErrorHandling:
with (
patch("streamrip.rip.main.QobuzClient"),
patch("streamrip.rip.main.TidalClient"),
- patch("streamrip.rip.main.DeezerClient"),
patch("streamrip.rip.main.SoundcloudClient"),
):
main = Main(mock_config)
|