def parse_query(query, ilogger):
    """
    Gets either a list of videos from a query, parsing links and search queries
    and playlists

    Args:
        query (str): The YouTube search query
        ilogger (logging.logger): The logger to log API calls to

    Returns:
        queue (list): The items obtained from the YouTube search
    """

    # Try parsing this as a link
    p = urlparse(query)
    if p and p.scheme and p.netloc:
        if "youtube" in p.netloc and p.query and ytdiscoveryapi is not None:
            query_parts = p.query.split('&')
            yturl_parts = {}
            for q in query_parts:
                s = q.split('=')
                if len(s) < 2:
                    continue

                q_name = s[0]
                q_val = '='.join(s[1:])
                # Add to the query
                if q_name not in yturl_parts:
                    yturl_parts[q_name] = q_val

            if "list" in yturl_parts:
                ilogger.info("Queued YouTube playlist from link")
                return get_queue_from_playlist(yturl_parts["list"])
            elif "v" in yturl_parts:
                ilogger.info("Queued YouTube video from link")
                return [["https://www.youtube.com/watch?v={}".format(yturl_parts["v"]), query]]
        elif "soundcloud" in p.netloc:
            if scclient is None:
                ilogger.error("Could not queue from SoundCloud API, using link")
                return [[query, query]]
            try:
                result = scclient.get('/resolve', url=query)

                track_list = []
                if isinstance(result, ResourceList):
                    for r in result.data:
                        tracks = get_sc_tracks(r)
                        if tracks is not None:
                            for t in tracks:
                                track_list.append(t)
                elif isinstance(result, Resource):
                    tracks = get_sc_tracks(result)
                    if tracks is not None:
                        for t in tracks:
                            track_list.append(t)

                if track_list is not None and len(track_list) > 0:
                    ilogger.info("Queued SoundCloud songs from link")
                    return track_list
                else:
                    ilogger.error("Could not queue from SoundCloud API")
                    return [[query, query]]
            except Exception as e:
                logger.exception(e)
                ilogger.error("Could not queue from SoundCloud API, using link")
                return [[query, query]]
        else:
            ilogger.debug("Using url: {}".format(query))
            return [[query, query]]

    args = query.split(' ')
    if len(args) == 0:
        ilogger.error("No query given")
        return []

    if args[0].lower() in ["sp", "spotify"] and spclient is not None:
        if spclient is None:
            ilogger.error("Host does not support Spotify")
            return []

        try:
            if len(args) > 2 and args[1] in ['album', 'artist', 'song', 'track', 'playlist']:
                query_type = args[1].lower()
                query_search = ' '.join(args[2:])
            else:
                query_type = 'track'
                query_search = ' '.join(args[1:])
            query_type = query_type.replace('song', 'track')
            ilogger.info("Queueing Spotify {}: {}".format(query_type, query_search))
            spotify_tracks = search_sp_tracks(query_type, query_search)
            if spotify_tracks is None or len(spotify_tracks) == 0:
                ilogger.error("Could not queue Spotify {}: {}".format(query_type, query_search))
                return []
            ilogger.info("Queued Spotify {}: {}".format(query_type, query_search))
            return spotify_tracks
        except Exception as e:
            logger.exception(e)
            ilogger.error("Error queueing from Spotify")
            return []
    elif args[0].lower() in ["sc", "soundcloud"]:
        if scclient is None:
            ilogger.error("Host does not support SoundCloud")
            return []

        try:
            requests = ['song', 'songs', 'track', 'tracks', 'user', 'playlist', 'tagged', 'genre']
            if len(args) > 2 and args[1] in requests:
                query_type = args[1].lower()
                query_search = ' '.join(args[2:])
            else:
                query_type = 'track'
                query_search = ' '.join(args[1:])
            query_type = query_type.replace('song', 'track')
            ilogger.info("Queueing SoundCloud {}: {}".format(query_type, query_search))
            soundcloud_tracks = search_sc_tracks(query_type, query_search)
            ilogger.info("Queued SoundCloud {}: {}".format(query_type, query_search))
            return soundcloud_tracks
        except Exception as e:
            logger.exception(e)
            ilogger.error("Could not queue from SoundCloud")
            return []
    elif args[0].lower() in ["yt", "youtube"] and ytdiscoveryapi is not None:
        if ytdiscoveryapi is None:
            ilogger.error("Host does not support YouTube")
            return []

        try:
            query_search = ' '.join(args[1:])
            ilogger.info("Queued Youtube search: {}".format(query_search))
            return get_ytvideos(query_search, ilogger)
        except Exception as e:
            logger.exception(e)
            ilogger.error("Could not queue YouTube search")
            return []

    if ytdiscoveryapi is not None:
        ilogger.info("Queued YouTube search: {}".format(query))
        return get_ytvideos(query, ilogger)
    else:
        ilogger.error("Host does not support YouTube".format(query))
        return []