from typing import Dict, List, Optional, Set from apollo_utils.core.constants.dsp import DSP_SPOTIFY_APPLE from apollo_playlists_messages.config import CORE_IMAGE_SERVICE from apollo_playlists_messages.constants import APPLE_SYNONYM_CC, PLAYLIST_IMAGE_RESOLUTION def get_dsp(dsp_playlist_id: str) -> str: return dsp_playlist_id.split("_")[0] def get_id(dsp_playlist_id: str) -> str: return dsp_playlist_id.split("_")[1] def get_country_code(full_playlist_id: str) -> Optional[str]: cc = full_playlist_id.split("_")[2] if cc != "None": return cc def get_dsp_id(full_playlist_id: str) -> str: parts = full_playlist_id.split("_") return f"{parts[0]}_{parts[1]}" def get_playlist_image_url( playlist_id: str, dsp: str, country_code: str = None, resolution: str = PLAYLIST_IMAGE_RESOLUTION ) -> str: if dsp == DSP_SPOTIFY_APPLE.APPLE.value: dsp_part = "apple_music" else: dsp_part = dsp country_code = None url = f"{CORE_IMAGE_SERVICE}/playlists/by_{dsp_part}_id/{playlist_id}?resolution={resolution}" if country_code: url += f"&storefront={country_code}" return url def parse_self_to_top_country_codes( dsp: str, self_codes: List[str], top_codes: List[str] ) -> Dict[Optional[str], Set[str]]: if dsp == DSP_SPOTIFY_APPLE.SPOTIFY.value: return {None: set(top_codes)} tops = set(self_codes) & set(top_codes) - {APPLE_SYNONYM_CC[1]} synonyms = {APPLE_SYNONYM_CC[0]: set(APPLE_SYNONYM_CC)} return {cc: synonyms.get(cc, {cc}) for cc in tops} # add {us, global} tops for self us market (apple only)