Add support for Tidal video links #53

This commit is contained in:
nathom 2021-04-16 13:10:59 -07:00
parent 8bfa7bc10d
commit c115eae15f
4 changed files with 14 additions and 5 deletions

View file

@ -137,7 +137,7 @@ TRACK_FORMAT = "{tracknumber}. {artist} - {title}"
# ------------------ Regexes ------------------- #
URL_REGEX = (
r"https?://(?:www|open|play|listen)?\.?(qobuz|tidal|deezer)\.com(?:(?:/"
r"(track|playlist|album|artist|label))|(?:\/[-\w]+?))+\/([-\w]+)"
r"(album|artist|track|playlist|video|label))|(?:\/[-\w]+?))+\/([-\w]+)"
)
SOUNDCLOUD_URL_REGEX = r"https://soundcloud.com/[-\w:/]+"
SOUNDCLOUD_CLIENT_ID = "a3e059563d7fd3372b49b37f00a00bcf"

View file

@ -24,7 +24,7 @@ from .constants import (
URL_REGEX,
)
from .db import MusicDB
from .downloader import Album, Artist, Label, Playlist, Track, Tracklist
from .downloader import Album, Artist, Label, Playlist, Track, Tracklist, Video
from .exceptions import (
AuthenticationError,
NonStreamable,
@ -42,6 +42,7 @@ MEDIA_CLASS = {
"artist": Artist,
"track": Track,
"label": Label,
"video": Video,
}
Media = Union[Album, Playlist, Artist, Track]

View file

@ -1496,15 +1496,16 @@ class Video:
def __init__(self, client, id, **kwargs):
self.id = id
self.client = client
self.parent_folder = kwargs.get('parent_folder', 'StreamripDownloads')
os.makedirs(self.parent_folder, exist_ok=True)
def load_meta(self):
resp = self.client.get(self.id, "video")
self.title = resp['title']
self.explicit = resp['explicit']
print(resp)
def download(self):
def download(self, **kwargs):
click.secho(f"Downloading {self.title} (Video)", fg='blue')
self.parent_folder = kwargs.get('parent_folder', 'StreamripDownloads')
url = self.client.get_file_url(self.id, video=True)
# it's more convenient to have ffmpeg download the hls
command = ["ffmpeg", "-i", url, "-c", "copy", "-loglevel", "panic", self.path]
@ -1513,6 +1514,7 @@ class Video:
@property
def path(self) -> str:
os.makedirs(self.parent_folder, exist_ok=True)
fname = self.title
if self.explicit:
fname = f"{fname} (Explicit)"

View file

@ -100,6 +100,12 @@ class TrackMetadata:
self.add_album_meta(album)
def update(self, meta):
"""Given a TrackMetadata object (usually from an album), the fields
of the current object are updated.
:param meta:
:type meta: TrackMetadata
"""
assert isinstance(meta, TrackMetadata)
for k, v in meta.asdict().items():