import json import time from datetime import datetime, timedelta from urllib.parse import urlencode import allure from assertpy import assert_that from ui_automation_framework.api.api_client import ApiClient as ApiClientBase from ui_automation_framework.utils import AppConfig, CoreConfig access_token = {} class ApiClient(ApiClientBase): def authorize(self, user=CoreConfig.USER_EMAIL, password=CoreConfig.USER_PASSWORD): global access_token, expires_in if not access_token: expires_in = {} if access_token.get(user) and expires_in.get(user) > int(time.time()): self.logger.info(f'expire date: {datetime.fromtimestamp(expires_in[user]).strftime("%A, %B %d, %Y %I:%M:%S")}') return access_token.get(user) else: data = { "client_id": CoreConfig.AUTH0_CLIENT_ID, "client_secret": CoreConfig.AUTH0_CLIENT_SECRET, "audience": CoreConfig.AUTH0_AUDIENCE, "grant_type": CoreConfig.AUTH0_GRANT_TYPE, "realm": CoreConfig.AUTH0_REALM, "username": user, "password": password, } headers = {"content-type": "application/x-www-form-urlencoded"} session_token = self.session.post(CoreConfig.AUTH0_HOST, urlencode(data), headers=headers) access_token[user] = session_token.json().get("access_token") expires_in[user] = int(time.time()) + int(session_token.json().get("expires_in")) self.logger.info(f"session token full: {session_token.json()}") self.logger.info(f"expire: {expires_in[user]}") self.logger.info(access_token[user]) if access_token[user] is None: raise ValueError("Can not get the access token!") return access_token[user] @allure.step("GET /dsp-api/delphi/total-streams-count-bulk") def get_streams_count(self, market, track_isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} resp = self.session.get( self.host_endpoint + "/dsp-api/delphi/total-streams-count-bulk?isrc=" + track_isrc + "&market=" + market, headers=headers, timeout=self.timeout, ) values = { "global_value": resp.json().get("global"), "market_value": resp.json().get("market"), } return values def remove_all_track_from_comparison_page(self, market, user=CoreConfig.USER_EMAIL): token = self.authorize(user) spotify_id = "spotify_id" self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} resp = self.session.get(self.host_endpoint + "/apollo-api/compared-tracks/?market={}".format(market), headers=headers) ids = [] for id in resp.json(): ids.append(id[spotify_id]) self.logger.info("found ids: {}".format(ids)) for id in ids: payload = {spotify_id: "{}".format(id)} resp = self.session.delete(self.host_endpoint + "/apollo-api/compared-tracks/", data=json.dumps(payload), headers=headers) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info(response) self.logger.info("deleted id: {}".format(id)) def get_playlist_ids_with_period_tracks(self, apple_spotify, track, period, param_name, user=CoreConfig.USER_EMAIL, token="default"): if token == "default": token = self.authorize(user) else: token = token self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} # spotify or apple-music url_main = f"/gate-api/playlists/{apple_spotify}/previous/top/?period={period}" tracks_part = "" for t in track: tracks_part = tracks_part + "&tracks={t}".format(t=t) self.logger.info("tracks part url is: {}".format(tracks_part)) resp = self.session.get(self.host_endpoint + url_main + tracks_part, headers=headers) self.logger.info("full url is: {}".format(self.host_endpoint + url_main + tracks_part)) playlist_ids = [] for id in resp.json()["playlists"]: playlist_ids.append(str(id[param_name]).strip().replace(" ", " ").replace(" ", " ")) self.logger.info("found ids: {}".format(playlist_ids)) return playlist_ids def get_playlist_ids_with_period_tracks_for_market(self, apple_spotify, track, period, param_name, user=CoreConfig.USER_EMAIL, market="us"): token = self.authorize(user) return self.get_playlist_ids_with_period_tracks_for_market_with_token(apple_spotify=apple_spotify, track=track, period=period, param_name=param_name, token_s=token, market=market) def get_playlist_ids_with_period_tracks_for_market_with_token(self, apple_spotify, track, period, param_name, token_s, market="us"): token = token_s self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} # spotify or apple-music url_main = "/gate-api/playlists/{apple_spotify}/previous/top/?market={market}&period={period}".format(apple_spotify=apple_spotify, market=market, period=period) tracks_part = "" for t in track: tracks_part = tracks_part + "&tracks={t}".format(t=t) self.logger.info(url_main + tracks_part) self.logger.info("tracks part url is: {}".format(tracks_part)) resp = self.session.get(self.host_endpoint + url_main + tracks_part, headers=headers) self.logger.info("full url is: {}".format(self.host_endpoint + url_main + tracks_part)) playlist_ids = [] for id in resp.json()["playlists"]: playlist_ids.append(str(id[param_name]).strip().replace(" ", " ").replace(" ", " ")) self.logger.info("found ids: {}".format(playlist_ids)) return playlist_ids def get_playlist_ids_with_period_for_track_for_market(self, apple_spotify, track, period, param_name, user=CoreConfig.USER_EMAIL, market="us"): token = self.authorize(user) self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} # spotify or apple-music url_main = "/gate-api/playlists/{apple_spotify}/previous/top/?market={market}&period={period}".format(apple_spotify=apple_spotify, market=market, period=period) tracks_part = "&tracks={}".format(track) self.logger.info("tracks part url is: {}".format(tracks_part)) resp = self.session.get(self.host_endpoint + url_main + tracks_part, headers=headers) self.logger.info("full url is: {}".format(self.host_endpoint + url_main + tracks_part)) playlist_ids = [] for id in resp.json()["playlists"]: playlist_ids.append(str(id[param_name]).strip().replace(" ", " ").replace(" ", " ")) self.logger.info("found ids: {}".format(playlist_ids)) return playlist_ids def get_playlist_track_history_with_period_for_track_for_market(self, apple_spotify, track, period, token, market="us"): token = token self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} # spotify or apple-music url_main = "/gate-api/playlists/{apple_spotify}/previous/top/?market={market}&period={period}".format(apple_spotify=apple_spotify, market=market, period=period) tracks_part = "" for t in track: tracks_part = tracks_part + "&tracks={t}".format(t=t) self.logger.info("tracks part url is: {}".format(tracks_part)) resp = self.session.get(self.host_endpoint + url_main + tracks_part, headers=headers) self.logger.info("full url is: {}".format(self.host_endpoint + url_main + tracks_part)) self.logger.info("response : {}".format(resp.json()["playlists"])) return resp.json()["playlists"] def get_playlist_ids_with_period_track(self, apple_spotify, track, period, user, param_name, market=""): token = self.authorize(user) self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} # spotify or apple-music mark = "" if market != "": mark = "market={}&".format(market) url_main = "/gate-api/playlists/{apple_spotify}/previous/top/?{mark}period={period}".format(apple_spotify=apple_spotify, period=period, mark=mark) tracks_part = "&tracks={track}".format(track=track) self.logger.info("tracks part url is: {}".format(tracks_part)) resp = self.session.get(self.host_endpoint + url_main + tracks_part, headers=headers) self.logger.info("full url for period: {} is: {}".format(period, self.host_endpoint + url_main + tracks_part)) playlist_ids = [] for id in resp.json()["playlists"]: playlist_ids.append(str(id[param_name]).strip().replace(" ", " ").replace(" ", " ")) self.logger.info("found ids: {}".format(playlist_ids)) return playlist_ids def get_first_last_date_for_isrc(self, isrc, user=CoreConfig.USER_EMAIL): token = self.authorize(user) self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} # spotify or apple-music url_main = "/dsp-api/analytics/v1/streams-dates?isrc={isrc}&include_last_dates=true".format(isrc=isrc) resp = self.session.get(self.host_endpoint + url_main, headers=headers) self.logger.info("full url is: {}".format(self.host_endpoint + url_main)) return resp.json() def get_apple_tracklist(self, country, id): token = self.authorize() self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json"} url_main = "/applemusic/playlists/{id}?country={country}".format(id=id, country=country) resp = self.session.get(self.host_endpoint + url_main, headers=headers) self.logger.info("full url is: {}".format(self.host_endpoint + url_main)) self.logger.info("resp: {}".format(resp.json())) return resp.json() def add_track_to_comparison(self, market, isrc, id, token): token = token self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json; charset=utf-8"} payload = {"spotify_id": "{id}".format(id=id), "isrc": "{isrc}".format(isrc=isrc)} resp = self.session.post(self.host_endpoint + "/apollo-api/compared-tracks/?market={market}".format(market=market), data=json.dumps(payload), headers=headers) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info(response) return resp def get_demographics_delphi(self, market, isrc, start_date, period, token, dsp): end_date = (datetime.strptime(start_date, "%Y-%m-%d") + timedelta(days=period)).date() last_stream_date = self.get_first_last_date_for_isrc(isrc=isrc)["last_stream_date"]["spotify"] self.logger.info("end date: {}, last date: {}".format(end_date, last_stream_date)) if end_date > datetime.strptime(last_stream_date, "%Y-%m-%d").date(): end_date = last_stream_date self.logger.info("end date: {}".format(end_date)) token = token self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json; charset=utf-8"} payload = {"items": [{"start": "{}".format(start_date), "end": "{}".format(end_date), "isrc": "{}".format(isrc)}], "combine_isrc": "false", "market": "{}".format(market)} resp = self.session.post(self.host_endpoint + "/dsp-api/delphi/{}-demographics".format(dsp), data=json.dumps(payload), headers=headers) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info(response) return resp.json() def get_consumer_analytics_streams(self, track, vendor, period, token): end_date = (datetime.strptime(track.dates.first_date, "%Y-%m-%d") + timedelta(days=period)).date() token = token self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json; charset=utf-8"} resp = self.session.get(self.host_endpoint + "/dsp-api/consumer_analytics/track-per-country?isrc={isrc}&start_date={f_date}" "&end_date={end_date}&vendor={vendor}&streams_only=false".format(isrc=track.isrc, f_date=track.dates.f_date, end_date=end_date, vendor=vendor), headers=headers) return resp.json() def get_consumer_analytics_streams_v1(self, track, vendor, market, end_date, start_date, token=""): if token == "": token = self.authorize() self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json; charset=utf-8"} uri = f"/dsp-api/consumer_analytics/v1/playlists-summary?isrc={track.isrc}&vendor={vendor}&start_date={start_date}&end_date={end_date}&market={market}" self.logger.info(f"URI: {uri}") resp = self.session.get(self.host_endpoint + uri, headers=headers) self.logger.info(f"uri: {uri}") response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info(f"response for : {uri}\n response: {response}") return resp.json() def get_apple_demographics_delphi(self, isrc, start_date, end_date, market, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/dsp-api/delphi/apple-demographics" payload = {"items": [{"start": start_date, "end": end_date, "isrc": isrc}], "market": market, "combine_isrc": False, "timestamp": 1596622249220} resp = self.session.post(self.host_endpoint + api_string, json=payload, headers=headers) self.logger.info(str(token)) response = {"status_code": resp.status_code, "body": resp.json()} return response def get_apple_demographics_delphi_isrcs(self, isrcs, start_date, end_date, market, token_mobile): headers = {"authorization": "Bearer {}".format(token_mobile)} api_string = "/dsp-api/delphi/apple-demographics" part_isrcs = [] for i in isrcs: part_isrcs.append({"start": start_date, "end": end_date, "isrc": i}) payload = {"items": part_isrcs, "market": market, "combine_isrc": True, "include": "all", "timestamp": 1596622249220} resp = self.session.post(self.host_endpoint + api_string, json=payload, headers=headers) self.logger.info(self.host_endpoint + api_string) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info("demgraphics delphi apple: {}".format(response)) return response def get_spotify_demographics_delphi(self, isrc, start_date, end_date, market, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/dsp-api/delphi/spotify-demographics" payload = {"items": [{"start": start_date, "end": end_date, "isrc": isrc}], "market": market, "combine_isrc": False} # , "timestamp": 1596622249220 resp = self.session.post(self.host_endpoint + api_string, json=payload, headers=headers) self.logger.info(self.host_endpoint + api_string) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info("response spotify delphi: {}".format(response)) return response def get_spotify_demographics_delphi_isrcs(self, isrcs, start_date, end_date, market, token, combine=True): headers = {"authorization": "Bearer {}".format(token)} api_string = "/dsp-api/delphi/spotify-demographics" part_isrcs = [] for i in isrcs: part_isrcs.append({"start": start_date, "end": end_date, "isrc": i}) payload = {"items": part_isrcs, "market": market, "combine_isrc": combine, "include": "all"} resp = self.session.post(self.host_endpoint + api_string, json=payload, headers=headers) self.logger.info(self.host_endpoint + api_string) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info("demgraphics delphi spotify: {}".format(response)) return response def get_spotify_saves_and_skips(self, isrcs, start_date, end_date, market, token): headers = {"authorization": "Bearer {}".format(token)} part_isrcs = "" for i in isrcs: part_isrcs = part_isrcs + "&isrc={i}".format(i=i) api_string = f"/dsp-api/filtr/spotify-saves-skips/?start_date={start_date}&end_date={end_date}&combine_isrc=true" + part_isrcs resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(self.host_endpoint + api_string) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info("saves and skips: {}".format(resp.json())) return response def get_spotify_demographics_consumer_analytics(self, isrc, start_date, end_date, market, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/apollo-api/spotify/track-demographics/" payload = {"items": [{"start": start_date, "end": end_date, "isrc": isrc}], "use_compression": 0, "market": market} resp = self.session.post(self.host_endpoint + api_string, json=payload, headers=headers) self.logger.info(self.host_endpoint + api_string) response = {"status_code": resp.status_code, "body": resp.json()} return response def get_apple_demographics_consumer_analytics(self, isrc, start_date, end_date, market, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/apple-consumer-analytics/track-demographics?startDate={}&endDate={}&isrc={}".format(start_date, end_date, isrc) resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(self.host_endpoint + api_string) response = {"status_code": resp.status_code, "body": resp.json()} return response def get_charts_additions(self, vendor, market, date, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/gate-api/charts/additions/?vendor={vendor}&market={market}&date={date}".format(vendor=vendor, market=market, date=date) resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info("Response" + str(resp.json())) return resp.json() def get_charts_removals(self, vendor, market, date, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/gate-api/charts/removals/?vendor={vendor}&market={market}&date={date}&fields=is_sony&fields=is_re_enter&fields=trends".format(vendor=vendor, market=market, date=date) resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info("Response: " + str(resp.json())) return resp.json() def get_vendor_api_tracks(self, vendor, market, token, end=10): headers = {"authorization": "Bearer {}".format(token)} api_string = "/gate-api/charts/top/?vendor={vendor}&market={market}&fields=is_sony&fields=is_re_enter&fields=trends&end={end}".format(vendor=vendor, market=market, end=end) resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info("Response: " + str(resp.json())) return resp.json() def get_top_charts_dates(self, vendor, market, type, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/gate-api/charts/date-range/?vendor={vendor}&market={market}&type={type}".format(vendor=vendor, market=market, type=type) resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"response: {resp.json()}") return resp.json() def get_dashboard_charts(self, added_url, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/gate-api/charts/{addition}".format(addition=added_url) resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"api_string: {api_string}, \n response: {resp.json()}") return resp.json() def get_is_sony_album(self, market, upc, token): headers = {"authorization": "Bearer {}".format(token)} api_string = f"/sonyalbums/issony?market={market}&upc={upc}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(resp.json()) return resp.json() def get_response(self, endpoint, user, env=CoreConfig.TARGET_API_URL, token=""): if token == "": token = self.authorize(user) headers = {"authorization": "Bearer {}".format(token)} resp = self.session.get(env + endpoint, headers=headers) self.logger.info(f"uri: {env + endpoint}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") response = {"status_code": resp.status_code, "body": resp.json()} return response def get_track_in_playlist_summary_2(self, start_date, end_date, market, playlist_id): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} endpoint_isrcs = f"/sonytracks/analyze?playlisturi=spotify%3Aplaylist%3A{playlist_id}&countryCode={market}" isrcs_resp = self.session.get(self.host_endpoint + endpoint_isrcs, headers=headers).json()["tracks"] playlist_isrcs = [i["isrc"] for i in isrcs_resp] isrcs_part = "".join([f"isrc={i}&" for i in playlist_isrcs]) self.logger.info(f"isrcs part: {isrcs_part}") endpoint = "/spotify-consumer-analytics-compat/tracks-in-playlist-summary-2?{isrcs}" "playlistId={playlist_id}&startDate={start_date}&endDate={end_date}&countryCode={market}".format(start_date=start_date, end_date=end_date, market=market, playlist_id=playlist_id, isrcs=isrcs_part) self.logger.info(f"full endpoint: {endpoint}") resp = self.session.get(self.host_endpoint + endpoint, headers=headers).json() self.logger.info(f"response: {resp}") return resp def get_playlistswithtrack(self, isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/applemusic/playlists/tracklisthistory/track?isrc={isrc}&limit=1000" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_apple_playlistswithtrack(self, isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/applemusic/playlistswithtrack?isrc={isrc}&limit=1000" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_isrc_by_apple_id(self, id, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/apple/tracks/{id}?market={market}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def delete_apple_starred_track(self, isrc, id, token): headers = {"authorization": "Bearer {}".format(token)} resp = self.session.delete(self.host_endpoint + f"/apollo-api/v1/starred-tracks/?uri={id}&isrc={isrc}", headers=headers) response = {"status_code": resp.status_code, "body": resp.json()} self.logger.info(response) self.logger.info("deleted id: {}".format(id)) def get_starred_tracks(self, token): headers = {"authorization": "Bearer {}".format(token)} api_string = "/apollo-api/v1/starred-tracks/detailed/?limit=200&offset=0&related=true" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_latest_date_date(self): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = "/spotify-consumer-analytics-compat/latest-date" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json()["date"] def get_latest_date_all(self): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = "/dsp-api/consumer_analytics/streams-latest-date?vendors=all" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_gtp_tracks(self): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/tracks/gtp/?date={datetime.today().date()}&market=_gl&include=all&type_id=1" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json()["tracks"] def get_gtp_charts(self, isrcs, market, end_date, date_shift=4): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f'/gate-api/gtp/charts/?&isrc={"&isrc=".join(isrcs)}&market={market}&end={end_date}&date_shift={date_shift}' resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_gtp_cpot_charts_with_date_range(self, isrc, market, start_date, date_shift): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/gtp/charts/?isrc={isrc}&market={market}&start={start_date}&date_shift={date_shift}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_gtp_cpot_charts(self, isrc, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/gtp/charts/?isrc={isrc}&market={market}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_charts_tracks(self, vendor, market, date, type, end=200): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/top/?vendor={vendor}&market={market}&fields=is_sony&fields=is_re_enter&fields=trends&date={date}&type={type}&end={end}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_track_per_country(self, isrc, start_date, end_date, vendor): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/consumer_analytics/v1/track-per-country?isrc={isrc}&start_date={start_date}&end_date={end_date}&vendor={vendor}&streams_only=false&combine_isrc=true" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"response: {resp.json()}") return resp.json() def get_isrc_by_spotify_id(self, market, id): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} market_p = "" if market != AppConfig.get("market")["global"]["api3"]: market_p = f"?market={market}" api_string = f"/dsp-api/spotify/tracks/{id}{market_p}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") self.logger.info(f"response: {resp.json()}") return resp.json() @allure.step("GET /dsp-api/delphi/amazon/tracks/v1/streams") def get_amazon_tracks(self, isrc, start_date, end_date): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/amazon/tracks/v1/streams?isrc={isrc}&start_date={start_date}&end_date={end_date}&combine_isrc=true&combine_tiers=true&group_by=date&group_by=sub_dsp" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_stations_summary(self, isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/stations/summary/?isrc={isrc}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_video_analytics(self, video_id, market, start_date, end_date, group_by="&group_by=date%2Cvideo_id"): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/video-analytics?start_date={start_date}&end_date={end_date}{group_by}&video_id={video_id}&country_code={market}&only=traffic_sources%2Cengagement%2Cwatch_times" self.logger.info(f"Api string: {api_string}") resp = self.session.get(self.host_endpoint + api_string, headers=headers) if resp.status_code != 200: raise ValueError(f"API response status code != 200, code: {resp.status_code}") # self.logger.info(f'video analytics: {resp.json()}') return resp.json() def get_video_analytics_demographics(self, start_date, end_date, market, isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/video-analytics?group_by=video_id&isrc={isrc}&start_date={start_date}&end_date={end_date}&country_code={market}&content_type=partner_uploaded%2Cpremium_ugc&include=demographics&expand_to=related_isrcs" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_delphi_videos(self, isrc, params): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/videos?{params}isrc={isrc}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_youtube_top_markets(self, start, end, ids): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} video_ids = "&video_id=".join(ids) api_string = f"/dsp-api/analytics/v1/youtube/top-markets?limit=15&start_date={start}&end_date={end}&video_id={video_ids}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_global_search_results_albums_artists_tracks(self, query, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/vendor-api/spotify/v1/search?query={query}&item_type=track%2Cartist%2Calbum&limit=20&market={market}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_delphi_video_positions(self, isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/video-positions/charts/summary?isrc={isrc}&expand_to=related_isrcs" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_track_in_playlist_2(self, isrc, playlistId, startDate, endDate, local_m=""): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} if local_m != "": local_m = f"&countryCode={local_m}" api_string = f"/spotify-consumer-analytics-compat/track-in-playlist-2?isrc={isrc}&playlistId={playlistId}{local_m}&startDate={startDate}&endDate={endDate}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_tracks_from_artists_page(self, artist_id, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/trackplaylistadds?uri=spotify%3Aartist%3A{artist_id}&limit=50®ion={market}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_tracks_gtp(self, date=datetime.today().date(), market="_gl", type_id=1): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/tracks/gtp/?date={date}&market={market}&include=all&type_id={type_id}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_gtp_streams(self, isrcs, market, date): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f'/gate-api/tracks/streams/by-date-shift/?&isrc={"&isrc=".join(isrcs)}&market={market}&date={date}' resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_playlists_summary_nmf(self): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = "/gate-api/playlists/summary/nmf/" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_tracks_info_nmf(self, date, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} if market != "worldwide": api_string = f"/gate-api/tracks/nmf/?date={date}&market={market}" else: api_string = f"/gate-api/tracks/nmf/?date={date}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") # self.logger.info(f'response: {resp.json()}') return resp.json() def get_tiktok_top_resp(self, isrc, start, end, metrics, limit=15): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/tracks/markets/top/?isrc={isrc}&start_date={start}&end_date={end}&dsp=tiktok&combine=false&metrics={metrics}&combine=false&limit={limit}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") # self.logger.info(f'response: {resp.json()}') return resp.json() def get_tiktok_tracks_analytics(self, isrc, start, end, markets): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f'/dsp-api/delphi/tiktok/tracks/analytics?breakdowns=content_type_country%2Ctotals&metrics=creations%2Cvideo_views&isrc={isrc}&start_date={start}&end_date={end}&country_code={",".join(markets)}' resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_metrics_trends(self, date, isrcs): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/analytics/v1/metrics-trends?date={date}&dsp=spotify&dsp=tiktok&metric=creations&metric=video_views&metric=streams&isrc=" + "&isrc=".join(isrcs) resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_metrics_week_values(self, market, date, isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} market_p = "" if market != AppConfig.get("market")["global"]["api"]: market_p = f"&market={market}" api_string = f"/dsp-api/analytics/v1/metrics-week-values?date={date}&dsp=spotify&dsp=tiktok&metric=creations&metric=video_views&metric=streams&isrc={isrc}{market_p}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_youtube_full_trend(self, market, date): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/youtube/full-trend/?market={market}&date={date}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_charts_youtube_video_positions(self, video_id, market, start, end): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/youtube/video-positions/?video_id={video_id}&market={market}&start_date={start}&end_date={end}&include=chart" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_shazam_charts(self, market, date, city=""): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/analytics/v1/shazam/charts?market={market}&date={date}" if city != ("" or "all"): api_string = f"{api_string}&city={city}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_shazam_charts_positions(self, market, city="", isrc="", start="", end=""): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/analytics/v1/shazam/charts/positions?market={market}" if city != ("" or "all"): api_string += f"&city={city}" if start != "": api_string += f"&start_date={start}&end_date={end}" if isrc != "": api_string += f"&isrc={isrc}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_data_health_positions_shazam(self): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = "/dsp-api/delphi/data-health/chart-positions?chart_group=shazam_top" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_video_trending_date(self, video_id): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/youtube/dates/?video_id={video_id}&include=markets" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_charts_trending_dates_markets(self): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = "/gate-api/charts/youtube/dates/?include=markets" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_shazam_cities(self, market_url): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/analytics/v1/shazam/cities?market={market_url}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_tiktok_top_tracks(self): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = "/dsp-api/delphi/tiktok/top/tracks?top_chart_id=top50_1day_product_family_period_creations_change_worldwide_no_asian&max_position=1" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"status code: {resp.status_code}") if resp.status_code != 200: raise ValueError("API response status code != 200") self.logger.info(f"response: {resp.json()}") return resp.json() def get_tiktok_charts_tracks(self, date, market, days, type): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/tracks/tiktok/?date={date}&market={market}&days={days}&type={type}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_tiktok_charts_tracks_cpot(self, isrc, start, end, market, days, type): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/tracks/tiktok/positions/?isrc={isrc}&start_date={start}&end_date={end}&market={market}&days={days}&type={type}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_track_positions_playlist(self, isrc, dsp): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/track-positions/playlists?isrc={isrc}&dsp={dsp}&include=streams%2Cplaylists%2Cstreams_for_period" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_amazon_tracklist(self, id, country, add=""): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/playlists/amazon/tracks/?playlist_id={id}&country_code={country}{add}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_amazon_streams_playlist(self, isrc, playlist_id, start, end, country): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/streams?isrc={isrc}&playlist_id={playlist_id}&start_date={start}&end_date={end}&country_code={country}&group_by=date" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_amazon_tracklist_start_end(self, isrc, id, start, end): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/track-positions/playlists?isrc={isrc}&playlist_id={id}&start_date={start}&end_date={end}&include=playlists&sort_by=date&sort_order=asc" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_amazon_playlists_list(self, isrc, dsp, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} if market == "_gl": api_string = f"/dsp-api/delphi/track-positions/playlists?isrc={isrc}&dsp={dsp}&streams_country_code=worldwide" f"&include=streams%2Cplaylists%2Cstreams_for_period" else: api_string = f"/dsp-api/delphi/track-positions/playlists?isrc={isrc}&dsp={dsp}&streams_country_code={market}" f"&include=streams%2Cplaylists%2Cstreams_for_period" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_yt_trending_for_video(self, video_id, date): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/youtube/video-trend/?video_id={video_id}&date={date}&sort_by=country_code" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_amazon_tracklist_no_isrc(self, amazon_id, start, end): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/track-positions/playlists?dsp=amazon&playlist_id={amazon_id}&start_date={start}&end_date={end}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_amazon_tracklist_start_end_id_market(self, id, start, end, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/track-positions/playlists?dsp=amazon&playlist_id={id}&country_code={market}&start_date={start}&end_date={end}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_playlists_spotify_track_graph(self, isrc, start_date, end_date, playlist_id): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/playlisttrackgraph/position?isrc={isrc}&playlistId={playlist_id}&startDate={start_date}&endDate={end_date}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_playlists_apple_by_track(self, isrc, start_date, end_date, playlist_id, country): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/applemusic/playlists/trackpositionchange?isrc={isrc}&playlistId={playlist_id}&country={country}&startDate={start_date}&endDate={end_date}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_playlists_spotify_by_track(self, isrc, end_date, market="global"): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} limit = 50 offset = 0 if market == "global": api_string = f"/gate-api/playlists/spotify/by-track/?isrc={isrc}&limit={limit}&offset={offset}&date={end_date}" else: api_string = f"/gate-api/playlists/spotify/by-track/?isrc={isrc}&market={market}&limit={limit}&offset={offset}&date={end_date}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) playlists_count = resp.json()["pagination"]["total"] limit = 200 resp_agr = [] for offset in range(0, playlists_count, limit): if market == "global": api_string = f"/gate-api/playlists/spotify/by-track/?isrc={isrc}&limit={limit}&offset={offset}&date={end_date}" else: api_string = f"/gate-api/playlists/spotify/by-track/?isrc={isrc}&market={market}&limit={limit}&offset={offset}&date={end_date}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"{limit}, {offset}, response: {resp.json()}") assert_that(resp.status_code).described_as(f"{limit}, {offset}").is_equal_to(200) resp_agr.extend(resp.json()["items"]) return {"items": resp_agr} def get_playlists_spotify_by_track_history(self, isrc): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} limit = 2000 offset = 0 api_string = f"/gate-api/playlists/spotify/by-track/history/?isrc={isrc}&limit={limit}&offset={offset}&excludeCurrentPlaylists=true" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") resp_items = resp.json()["items"] while len(resp_items) < int(resp.json()["pagination"]["total"]): limit = 200 offset = int(resp.json()["pagination"]["offset"]) api_string = f"/gate-api/playlists/spotify/by-track/history/?isrc={isrc}&limit={limit}&offset={offset}&excludeCurrentPlaylists=true" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"{limit}, {offset}, response: {resp.json()}") assert_that(resp.status_code).described_as(f"{limit}, {offset}").is_equal_to(200) resp_items.extend(resp.json()["items"]) return {"items": resp_items} def get_major_moves_tracks(self, market, vendor): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/moves/?market={market}&vendor={vendor}&fields=is_sony&fields=is_re_enter&fields=trends&order_by=moves" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_top_10_exits(self, market, vendor): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/gate-api/charts/out/?vendor={vendor}&market={market}&fields=is_sony&fields=is_re_enter&fields=trends&end=10" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_sony_tracks_analyze_spotify(self, id, region): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/sonytracks/analyze?playlisturi=spotify%3Aplaylist%3A{id}®ion={region}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_user_data_settings(self, user): token = self.authorize(user=user) headers = {"authorization": "Bearer {}".format(token), "x-app-slug": "apollo", "x-type": "web"} api_string = "/user-data-api/v1/settings/" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") self.logger.info(f"response: {resp.json()}") assert_that(resp.status_code).described_as(user).is_equal_to(200) return resp.json() def put_user_data_settings(self, user, payload): token = self.authorize(user) self.logger.info("TOKEN: {}".format(token)) headers = {"authorization": "Bearer {}".format(token), "content-type": "application/json; charset=utf-8", "x-app-slug": "apollo", "x-type": "web"} resp = self.session.put(self.host_endpoint + "/user-data-api/v1/settings/", data=json.dumps(payload), headers=headers) self.logger.info(f"response: {resp.json()}") assert_that(resp.status_code).is_equal_to(200) return resp.json() def get_apple_top_chart_tracks(self, chart_date, market): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} api_string = f"/dsp-api/delphi/apple-music/charts/tracks?date={chart_date}&chart_id=charts_daily_{market}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json() def get_amazon_stations(self, isrc, market="global"): token = self.authorize() headers = {"authorization": "Bearer {}".format(token)} if market == "global": api_string = f"/dsp-api/delphi/amazon/stations?isrc={isrc}" else: api_string = f"/dsp-api/delphi/amazon/stations?isrc={isrc}&country_code={market}" resp = self.session.get(self.host_endpoint + api_string, headers=headers) self.logger.info(f"uri: {self.host_endpoint + api_string}") assert_that(resp.status_code).is_equal_to(200) self.logger.info(f"response: {resp.json()}") return resp.json()