Merge pull request #426 from DJDoubleD/qobuz_interpreter_link

This commit is contained in:
Nathan Thomas 2023-06-08 09:12:27 -07:00 committed by GitHub
commit de857c6543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -6,6 +6,9 @@ from typing import Tuple
from streamrip.constants import AGENT
from streamrip.utils import gen_threadsafe_session
interpreter_artist_id_regex = re.compile(
r"https?://www\.qobuz\.com/\w\w-\w\w/interpreter/[-\w]+/(?P<artistId>[0-9]+)"
)
interpreter_artist_regex = re.compile(r"getSimilarArtist\(\s*'(\w+)'")
@ -13,9 +16,14 @@ def extract_interpreter_url(url: str) -> str:
"""Extract artist ID from a Qobuz interpreter url.
:param url: Urls of the form "https://www.qobuz.com/us-en/interpreter/{artist}/download-streaming-albums"
or "https://www.qobuz.com/us-en/interpreter/the-last-shadow-puppets/{artistId}}"
:type url: str
:rtype: str
"""
url_match = interpreter_artist_id_regex.search(url)
if url_match:
return url_match.group("artistId")
session = gen_threadsafe_session({"User-Agent": AGENT})
r = session.get(url)
match = interpreter_artist_regex.search(r.text)