diff --git a/src/onthespot/api/apple_music.py b/src/onthespot/api/apple_music.py index 0a2b206..69b2592 100644 --- a/src/onthespot/api/apple_music.py +++ b/src/onthespot/api/apple_music.py @@ -398,16 +398,14 @@ def apple_music_get_artist_album_ids(session, artist_id): return item_ids -def apple_music_get_playlist_track_ids(session, playlist_id): - logger.info(f"Getting items in playlist: '{playlist_id}'") - playlist_data = make_call(f"{BASE_URL}/catalog/{session.cookies.get("itua")}/playlists/{playlist_id}", session=session) - item_ids = [] - for track in playlist_data.get('data', [])[0].get('relationships', {}).get('tracks', {}).get('data', []): - item_ids.append(track['id']) - return item_ids +def apple_music_get_playlist_data(session, playlist_id): + logger.info(f"Get playlist data for playlist: {playlist_id}") + playlist_data = make_call(f"{BASE_URL}/catalog/{session.cookies.get("itua")}/playlists/{playlist_id}", session=session, skip_cache=True) + playlist_name = playlist_data.get('data', [])[0].get('attributes', {}).get('name', '') + playlist_by = playlist_data.get('data', [])[0].get('attributes', {}).get('curatorName', '') -def apple_music_get_playlist_data(session, playlist_id): - logger.info(f"Get playlist data for playlist: '{playlist_id}'") - playlist_data = make_call(f"{BASE_URL}/catalog/{session.cookies.get("itua")}/playlists/{playlist_id}", session=session) - return playlist_data.get('data', [])[0].get('attributes', {}).get('name', ''), playlist_data.get('data', [])[0].get('attributes', {}).get('curatorName', '') + track_ids = [] + for track in playlist_data.get('data', [])[0].get('relationships', {}).get('tracks', {}).get('data', []): + track_ids.append(track['id']) + return playlist_name, playlist_by, track_ids diff --git a/src/onthespot/api/deezer.py b/src/onthespot/api/deezer.py index bbb1ca3..b9e3dcc 100644 --- a/src/onthespot/api/deezer.py +++ b/src/onthespot/api/deezer.py @@ -68,19 +68,17 @@ def deezer_get_artist_album_ids(token, artist_id): return item_ids -def deezer_get_playlist_track_ids(token, playlist_id): - logger.info(f"Getting items in playlist: '{playlist_id}'") - album_data = make_call(f"{BASE_URL}/playlist/{playlist_id}") - item_ids = [] - for track in album_data.get("tracks", {}).get("data", ''): - item_ids.append(track['id']) - return item_ids - - def deezer_get_playlist_data(token, playlist_id): logger.info(f"Get playlist data for playlist: '{playlist_id}'") playlist_data = make_call(f"{BASE_URL}/playlist/{playlist_id}") - return playlist_data.get("title", ''), playlist_data.get("creator", {}).get("name", '') + + playlist_name = playlist_data.get("title", '') + playlist_by = playlist_data.get("creator", {}).get("name", '') + + track_ids = [] + for track in playlist_data.get("tracks", {}).get("data", ''): + track_ids.append(track.get('id', '')) + return playlist_name, playlist_by, track_ids def deezer_get_track_metadata(token, item_id): diff --git a/src/onthespot/api/tidal.py b/src/onthespot/api/tidal.py index 8a975af..ce5f86e 100644 --- a/src/onthespot/api/tidal.py +++ b/src/onthespot/api/tidal.py @@ -379,8 +379,8 @@ def tidal_get_album_track_ids(token, album_id): return item_ids -def tidal_get_playlist_track_ids(token, playlist_id): - logger.info(f"Getting items in playlist: {playlist_id}") +def tidal_get_playlist_data(token, playlist_id): + logger.info(f"Get playlist data for playlist: {playlist_id}") headers = {} headers["Authorization"] = f"Bearer {token['access_token']}" @@ -388,23 +388,35 @@ def tidal_get_playlist_track_ids(token, playlist_id): params["countryCode"] = token['country_code'] params["limit"] = '10000' - playlist_track_data = make_call(f"{BASE_URL}/playlists/{playlist_id}/tracks", params=params, headers=headers) + playlist_data = make_call(f"{BASE_URL}/playlists/{playlist_id}", params=params, headers=headers, skip_cache=True) + playlist_track_data = make_call(f"{BASE_URL}/playlists/{playlist_id}/tracks", params=params, headers=headers, skip_cache=True) - item_ids = [] + playlist_name = playlist_data.get('title', '') + playlist_by = playlist_data.get('creator', {}).get('name', 'Tidal') + + track_ids = [] for track in playlist_track_data['items']: - item_ids.append(track['id']) - return item_ids + track_ids.append(track.get('id', '')) + return playlist_name, playlist_by, track_ids -def tidal_get_playlist_data(token, playlist_id): - logger.info(f"Get playlist data for playlist: {playlist_id}") + +def tidal_get_mix_data(token, mix_id): + logger.info(f"Get mix data for mix: {mix_id}") headers = {} headers["Authorization"] = f"Bearer {token['access_token']}" - + print(mix_id) params = {} + params["mixId"] = mix_id params["countryCode"] = token['country_code'] - params["limit"] = '10000' - - playlist_data = make_call(f"{BASE_URL}/playlists/{playlist_id}", params=params, headers=headers) - playlist_name = playlist_data.get('title', '') - playlist_by = playlist_data.get('creator', {}).get('name', 'Tidal') - return playlist_name, playlist_by + params["locale"] = 'en_US' + params["deviceType"] = 'BROWSER' + + mix_data = make_call(f"https://api.tidal.com/v1/pages/mix", params=params, headers=headers)#, skip_cache=True) + print(mix_data) + playlist_name = mix_data['title'] + playlist_by = 'Tidal' + + track_ids = [] + for track in mix_data['rows'][1]['modules'][0]['pagedList']['items']: + track_ids.append(track['id']) + return playlist_name, playlist_by, track_ids diff --git a/src/onthespot/parse_item.py b/src/onthespot/parse_item.py index 70ec6c3..1e4a9e2 100755 --- a/src/onthespot/parse_item.py +++ b/src/onthespot/parse_item.py @@ -1,12 +1,12 @@ import re import time from .accounts import get_account_token -from .api.apple_music import apple_music_get_album_track_ids, apple_music_get_artist_album_ids, apple_music_get_playlist_track_ids, apple_music_get_playlist_data +from .api.apple_music import apple_music_get_album_track_ids, apple_music_get_artist_album_ids, apple_music_get_playlist_data from .api.bandcamp import bandcamp_get_album_track_ids, bandcamp_get_artist_album_ids -from .api.deezer import deezer_get_album_track_ids, deezer_get_artist_album_ids, deezer_get_playlist_track_ids, deezer_get_playlist_data +from .api.deezer import deezer_get_album_track_ids, deezer_get_artist_album_ids, deezer_get_playlist_data from .api.soundcloud import soundcloud_parse_url, soundcloud_get_set_items from .api.spotify import spotify_get_album_track_ids, spotify_get_artist_album_ids, spotify_get_playlist_items, spotify_get_playlist_data, spotify_get_liked_songs, spotify_get_your_episodes, spotify_get_show_episode_ids -from .api.tidal import tidal_get_album_track_ids, tidal_get_artist_album_ids, tidal_get_playlist_track_ids, tidal_get_playlist_data +from .api.tidal import tidal_get_album_track_ids, tidal_get_artist_album_ids, tidal_get_playlist_data, tidal_get_mix_data from .runtimedata import get_logger, parsing, download_queue, pending, parsing_lock, pending_lock from .utils import format_local_id @@ -16,7 +16,7 @@ DEEZER_URL_REGEX = re.compile(r'https?://www.deezer.com/(?:[a-z]{2}/)?(?Palbum|playlist|track|artist)/(?P\d+)') SOUNDCLOUD_URL_REGEX = re.compile(r"https?://soundcloud.com/[-\w:/]+") SPOTIFY_URL_REGEX = re.compile(r"https?://open.spotify.com/(intl-([a-zA-Z]+)/|)(?Ptrack|album|artist|playlist|episode|show)/(?P[0-9a-zA-Z]{22})(\?si=.+?)?$") -TIDAL_URL_REGEX = re.compile(r"https?://(www\.|listen\.)?tidal.com/(browse/)?(?Palbum|track|artist|playlist)/(?P\d+)") +TIDAL_URL_REGEX = re.compile(r"https?://(www\.|listen\.)?tidal.com/(browse/)?(?Palbum|track|artist|playlist|mix)/(?P[-a-z0-9]+)") YOUTUBE_URL_REGEX = re.compile(r"https?://(www\.|music\.)?youtube\.com/watch\?v=(?P[a-zA-Z0-9_-]+)(&list=(?P[a-zA-Z0-9_-]+))?") #QOBUZ_INTERPRETER_URL_REGEX = re.compile(r"https?://www\.qobuz\.com/\w\w-\w\w/interpreter/[-\w]+/([-\w]+)") @@ -197,22 +197,24 @@ def parsingworker(): } continue - elif current_type in ("album", "playlist"): - item_ids = globals()[f"{current_service}_get_{current_type}_track_ids"](token, current_id) + elif current_type in ["album", "playlist", "mix"]: + if current_type == "album": + playlist_name = '' + playlist_by = '' + track_ids = globals()[f"{current_service}_get_{current_type}_track_ids"](token, current_id) + else: + playlist_name, playlist_by, track_ids = globals()[f"{current_service}_get_{current_type}_data"](token, current_id) + if current_type == 'mix': + current_type = 'playlist' - playlist_name = '' - playlist_by = '' - if current_type == "playlist": - playlist_name, playlist_by = globals()[f"{current_service}_get_playlist_data"](token, current_id) - - for index, item_id in enumerate(item_ids): - local_id = format_local_id(item_id) + for index, track_id in enumerate(track_ids): + local_id = format_local_id(track_id) with pending_lock: pending[local_id] = { 'local_id': local_id, 'item_service': current_service, 'item_type': 'track', - 'item_id': item_id, + 'item_id': track_id, 'parent_category': current_type, 'playlist_name': playlist_name, 'playlist_by': playlist_by,