Formatting

This commit is contained in:
nathom 2021-04-16 12:48:09 -07:00
parent 4ff90bc796
commit 55294bc971
4 changed files with 44 additions and 24 deletions

1
.gitignore vendored
View file

@ -12,3 +12,4 @@ test.py
StreamripDownloads StreamripDownloads
*.wav *.wav
*.log *.log
*.mp4

View file

@ -2,6 +2,7 @@ import base64
import hashlib import hashlib
import json import json
import logging import logging
import re
import time import time
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Generator, Sequence, Tuple, Union from typing import Generator, Sequence, Tuple, Union
@ -16,6 +17,11 @@ from .constants import (
SOUNDCLOUD_CLIENT_ID, SOUNDCLOUD_CLIENT_ID,
TIDAL_CLIENT_INFO, TIDAL_CLIENT_INFO,
TIDAL_MAX_Q, TIDAL_MAX_Q,
QOBUZ_BASE,
TIDAL_BASE,
TIDAL_AUTH_URL,
DEEZER_BASE,
SOUNDCLOUD_BASE,
) )
from .exceptions import ( from .exceptions import (
AuthenticationError, AuthenticationError,
@ -27,16 +33,6 @@ from .exceptions import (
from .spoofbuz import Spoofer from .spoofbuz import Spoofer
from .utils import gen_threadsafe_session, get_quality from .utils import gen_threadsafe_session, get_quality
QOBUZ_BASE = "https://www.qobuz.com/api.json/0.2"
TIDAL_BASE = "https://api.tidalhifi.com/v1"
TIDAL_AUTH_URL = "https://auth.tidal.com/v1/oauth2"
DEEZER_BASE = "https://api.deezer.com"
DEEZER_DL = "http://dz.loaderapp.info/deezer"
SOUNDCLOUD_BASE = "https://api-v2.soundcloud.com"
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -672,8 +668,16 @@ class TidalClient(Client):
resp = self._api_request( resp = self._api_request(
f"videos/{video_id}/playbackinfopostpaywall", params=params f"videos/{video_id}/playbackinfopostpaywall", params=params
) )
manifest = json.loads(base64.b64decode(resp['manifest']).decode("utf-8")) stream_url_regex = (
return manifest['urls'][0] r'#EXT-X-STREAM-INF:BANDWIDTH=\d+,AVERAGE-BANDWIDTH=\d+,CODECS="[^"]+"'
r",RESOLUTION=\d+x\d+\n(.+)"
)
manifest = json.loads(base64.b64decode(resp["manifest"]).decode("utf-8"))
available_urls = self.session.get(manifest["urls"][0])
url_info = re.findall(stream_url_regex, available_urls.text)
# highest resolution is last
return url_info[-1]
def _api_post(self, url, data, auth=None): def _api_post(self, url, data, auth=None):
r = self.session.post(url, data=data, auth=auth, verify=False).json() r = self.session.post(url, data=data, auth=auth, verify=False).json()

View file

@ -168,3 +168,14 @@ TIDAL_CLIENT_INFO = {
"id": "aR7gUaTK1ihpXOEP", "id": "aR7gUaTK1ihpXOEP",
"secret": "eVWBEkuL2FCjxgjOkR3yK0RYZEbcrMXRc2l8fU3ZCdE=", "secret": "eVWBEkuL2FCjxgjOkR3yK0RYZEbcrMXRc2l8fU3ZCdE=",
} }
QOBUZ_BASE = "https://www.qobuz.com/api.json/0.2"
TIDAL_BASE = "https://api.tidalhifi.com/v1"
TIDAL_AUTH_URL = "https://auth.tidal.com/v1/oauth2"
DEEZER_BASE = "https://api.deezer.com"
DEEZER_DL = "http://dz.loaderapp.info/deezer"
SOUNDCLOUD_BASE = "https://api-v2.soundcloud.com"

View file

@ -2,8 +2,8 @@
import logging import logging
import re import re
from typing import Generator, Hashable, Optional, Tuple, Union
from collections import OrderedDict from collections import OrderedDict
from typing import Generator, Hashable, Optional, Tuple, Union
from .constants import ( from .constants import (
COPYRIGHT, COPYRIGHT,
@ -163,10 +163,12 @@ class TrackMetadata:
self.explicit = resp.get("explicit", False) self.explicit = resp.get("explicit", False)
# 80, 160, 320, 640, 1280 # 80, 160, 320, 640, 1280
uuid = resp.get("cover") uuid = resp.get("cover")
self.cover_urls = OrderedDict({ self.cover_urls = OrderedDict(
sk: tidal_cover_url(uuid, size) {
for sk, size in zip(COVER_SIZES, (160, 320, 640, 1280)) sk: tidal_cover_url(uuid, size)
}) for sk, size in zip(COVER_SIZES, (160, 320, 640, 1280))
}
)
self.streamable = resp.get("allowStreaming", False) self.streamable = resp.get("allowStreaming", False)
self.quality = TIDAL_Q_MAP[resp["audioQuality"]] self.quality = TIDAL_Q_MAP[resp["audioQuality"]]
@ -186,13 +188,15 @@ class TrackMetadata:
self.explicit = bool(resp.get("parental_warning")) self.explicit = bool(resp.get("parental_warning"))
self.quality = 2 self.quality = 2
self.bit_depth = 16 self.bit_depth = 16
self.cover_urls = OrderedDict({ self.cover_urls = OrderedDict(
sk: resp.get(rk) # size key, resp key {
for sk, rk in zip( sk: resp.get(rk) # size key, resp key
COVER_SIZES, for sk, rk in zip(
("cover", "cover_medium", "cover_large", "cover_xl"), COVER_SIZES,
) ("cover", "cover_medium", "cover_large", "cover_xl"),
}) )
}
)
self.sampling_rate = 44100 self.sampling_rate = 44100
self.streamable = True self.streamable = True