parameters: (youtube, item)
docstring: Given a raw item from an API response, return the appropriate Resource instance.
docstring_summary: Given a raw item from an API response, return the appropriate Resource instance.
docstring_tokens: Given a raw item from an API response return the appropriate Resource instance .
function: def create_resource_from_api_response(youtube, item):
      """Given a raw item from an API response, return the appropriate Resource instance."""
  
      # extract kind and id for the item.  if it's a search result then we have to do a bit of
      # wrangling. but we only extract the data - don't alter anything in the api response item!
      kind = item['kind'].replace('youtube#', '')
      if kind == 'searchResult':
          kind = item['id']['kind'].replace('youtube#', '')
          id_label = kind + 'Id'
          id = item['id'][id_label]
      else:
          id = item['id']
  
      if kind == 'video':
          return Video(youtube, id, item)
      elif kind == 'channel':
          return Channel(youtube, id, item)
      elif kind == 'playlist':
          return Playlist(youtube, id, item)
      elif kind == 'subscription':
          channel_id = item['snippet']['resourceId']['channelId']
          return Channel(youtube, id=channel_id)
      elif kind == 'playlistItem':
          return PlaylistItem(youtube, id, item)
      else:
          raise NotImplementedError(f"can't deal with resource kind '{kind}'")
function_tokens: def create_resource_from_api_response ( youtube , item ) : # extract kind and id for the item.  if it's a search result then we have to do a bit of # wrangling. but we only extract the data - don't alter anything in the api response item! kind = item [ 'kind' ] . replace ( 'youtube#' , '' ) if kind == 'searchResult' : kind = item [ 'id' ] [ 'kind' ] . replace ( 'youtube#' , '' ) id_label = kind + 'Id' id = item [ 'id' ] [ id_label ] else : id = item [ 'id' ] if kind == 'video' : return Video ( youtube , id , item ) elif kind == 'channel' : return Channel ( youtube , id , item ) elif kind == 'playlist' : return Playlist ( youtube , id , item ) elif kind == 'subscription' : channel_id = item [ 'snippet' ] [ 'resourceId' ] [ 'channelId' ] return Channel ( youtube , id = channel_id ) elif kind == 'playlistItem' : return PlaylistItem ( youtube , id , item ) else : raise NotImplementedError ( f"can't deal with resource kind '{kind}'" )