(
        query: Optional[str] = None,
        key: Optional[int] = None,
        external_url: Optional[str] = None,
    )
return provider
Factory method to create a song provider.
        Either (query and key) or external url need to be specified.
        Detects the type of provider needed and returns one of corresponding type.
Factory method to create a song provider.
        Either (query and key) or external url need to be specified.
        Detects the type of provider needed and returns one of corresponding type.
Factory method to create a song provider . Either ( query and key ) or external url need to be specified . Detects the type of provider needed and returns one of corresponding type .
def create(
        query: Optional[str] = None,
        key: Optional[int] = None,
        external_url: Optional[str] = None,
    ) -> "SongProvider":
        """Factory method to create a song provider.
        Either (query and key) or external url need to be specified.
        Detects the type of provider needed and returns one of corresponding type."""
        if key is not None:
            if query is None:
                logging.error(
                    "archived song requested but no query given (key %s)", key
                )
                raise ValueError()
            try:
                archived_song = ArchivedSong.objects.get(id=key)
            except ArchivedSong.DoesNotExist:
                logging.error("archived song requested for nonexistent key %s", key)
                raise ValueError()
            external_url = archived_song.url
        if external_url is None:
            raise ValueError(
                "external_url was provided and could not be inferred from remaining attributes."
            )
        provider_class: Optional[Type[SongProvider]] = None
        url_type = song_utils.determine_url_type(external_url)
        if url_type == "local":
            from core.musiq.localdrive import LocalSongProvider

            provider_class = LocalSongProvider
        elif storage.get("youtube_enabled") and url_type == "youtube":
            from core.musiq.youtube import YoutubeSongProvider

            provider_class = YoutubeSongProvider
        elif storage.get("spotify_enabled") and url_type == "spotify":
            from core.musiq.spotify import SpotifySongProvider

            provider_class = SpotifySongProvider
        elif storage.get("soundcloud_enabled") and url_type == "soundcloud":
            from core.musiq.soundcloud import SoundcloudSongProvider

            provider_class = SoundcloudSongProvider
        elif storage.get("jamendo_enabled") and url_type == "jamendo":
            from core.musiq.jamendo import JamendoSongProvider

            provider_class = JamendoSongProvider
        if not provider_class:
            raise NotImplementedError(f"No provider for given song: {external_url}")
        if not query and external_url:
            query = external_url
        provider = provider_class(query, key)
        return provider
def create ( query : Optional [ str ] = None , key : Optional [ int ] = None , external_url : Optional [ str ] = None , ) -> "SongProvider" : if key is not None : if query is None : logging . error ( "archived song requested but no query given (key %s)" , key ) raise ValueError ( ) try : archived_song = ArchivedSong . objects . get ( id = key ) except ArchivedSong . DoesNotExist : logging . error ( "archived song requested for nonexistent key %s" , key ) raise ValueError ( ) external_url = archived_song . url if external_url is None : raise ValueError ( "external_url was provided and could not be inferred from remaining attributes." ) provider_class : Optional [ Type [ SongProvider ] ] = None url_type = song_utils . determine_url_type ( external_url ) if url_type == "local" : from core . musiq . localdrive import LocalSongProvider provider_class = LocalSongProvider elif storage . get ( "youtube_enabled" ) and url_type == "youtube" : from core . musiq . youtube import YoutubeSongProvider provider_class = YoutubeSongProvider elif storage . get ( "spotify_enabled" ) and url_type == "spotify" : from core . musiq . spotify import SpotifySongProvider provider_class = SpotifySongProvider elif storage . get ( "soundcloud_enabled" ) and url_type == "soundcloud" : from core . musiq . soundcloud import SoundcloudSongProvider provider_class = SoundcloudSongProvider elif storage . get ( "jamendo_enabled" ) and url_type == "jamendo" : from core . musiq . jamendo import JamendoSongProvider provider_class = JamendoSongProvider if not provider_class : raise NotImplementedError ( f"No provider for given song: {external_url}" ) if not query and external_url : query = external_url provider = provider_class ( query , key ) return provider