Add support for deezer dynamic links

Signed-off-by: nathom <nathanthomas707@gmail.com>
This commit is contained in:
nathom 2021-06-21 00:07:17 -07:00
parent 7fdc07b448
commit b28be8ce1c
4 changed files with 30 additions and 1 deletions

View file

@ -158,6 +158,7 @@ LASTFM_URL_REGEX = r"https://www.last.fm/user/\w+/playlists/\w+"
QOBUZ_INTERPRETER_URL_REGEX = (
r"https?://www\.qobuz\.com/\w\w-\w\w/interpreter/[-\w]+/[-\w]+"
)
DEEZER_DYNAMIC_LINK_REGEX = r"https://deezer\.page\.link/\w+"
YOUTUBE_URL_REGEX = r"https://www\.youtube\.com/watch\?v=[-\w]+"
TIDAL_MAX_Q = 7

View file

@ -32,6 +32,7 @@ from .constants import (
SOUNDCLOUD_URL_REGEX,
URL_REGEX,
YOUTUBE_URL_REGEX,
DEEZER_DYNAMIC_LINK_REGEX,
)
from .db import MusicDB
from .exceptions import (
@ -42,7 +43,7 @@ from .exceptions import (
ParsingError,
)
from .tracklists import Album, Artist, Label, Playlist, Tracklist
from .utils import extract_interpreter_url
from .utils import extract_interpreter_url, extract_deezer_dynamic_link
logger = logging.getLogger("streamrip")
@ -82,6 +83,7 @@ class MusicDL(list):
self.lastfm_url_parse = re.compile(LASTFM_URL_REGEX)
self.interpreter_url_parse = re.compile(QOBUZ_INTERPRETER_URL_REGEX)
self.youtube_url_parse = re.compile(YOUTUBE_URL_REGEX)
self.deezer_dynamic_url_parse = re.compile(DEEZER_DYNAMIC_LINK_REGEX)
self.config: Config
if config is None:
@ -329,6 +331,18 @@ class MusicDL(list):
)
url = self.interpreter_url_parse.sub("", url)
dynamic_urls = self.deezer_dynamic_url_parse.findall(url)
if dynamic_urls:
click.secho(
"Extracting IDs from Deezer dynamic link. Use urls "
"of the form https://www.deezer.com/{country}/{type}/{id} for "
"faster processing.",
fg="yellow",
)
parsed.extend(
("deezer", *extract_deezer_dynamic_link(url)) for url in dynamic_urls
)
parsed.extend(self.url_parse.findall(url)) # Qobuz, Tidal, Dezer
soundcloud_urls = self.soundcloud_url_parse.findall(url)
soundcloud_items = [self.clients["soundcloud"].get(u) for u in soundcloud_urls]

View file

@ -450,6 +450,7 @@ class Playlist(Tracklist):
id=track.get("id"),
meta=meta,
cover_url=gen_cover(track),
part_of_tracklist=True,
)
)

View file

@ -337,6 +337,19 @@ def extract_interpreter_url(url: str) -> str:
)
deezer_id_link_regex = re.compile(r"https://www\.deezer\.com/[a-z]{2}/(\w+)/(\d+)")
def extract_deezer_dynamic_link(url: str) -> Tuple[str, str]:
session = gen_threadsafe_session({"User-Agent": AGENT})
r = session.get(url)
match = deezer_id_link_regex.search(r.text)
if match:
return match.group(1), match.group(2)
raise Exception("Unable to extract Deezer dynamic link.")
def get_container(quality: int, source: str) -> str:
"""Get the file container given the quality.