original_docstring: 
          Does a Spotify Metadata search and returns the first valid result
          
docstring: Does a Spotify Metadata search and returns the first valid result
docstring_tokens: Does a Spotify Metadata search and returns the first valid result
code: def _fetch_item_from_api(title):
          """
          Does a Spotify Metadata search and returns the first valid result
          """
          params = {'q': title, 'type': 'track'}
          r = requests.get(SPOTIFY_API_SEARCH_TRACK_URL, params=params)
  
          # Something bad happened with the API that we can't recover from
          if r.status_code not in VALID_API_STATUSCODES:
              raise ApiException(r.status_code)
          elif r.status_code == 404:
              return None
  
          last_modified = datetime_from_http_datestring(r.headers['Date'])
          max_age_match = re.match(r'.*max-age=(?P<age>\d+)', r.headers['Cache-Control'])
          if max_age_match:
              max_age = int(max_age_match.group('age'))
          else:
              max_age = None
          expires = datetime.utcnow() + timedelta(seconds=max_age)
          decoded_result = r.json()
          track_listing = decoded_result['tracks']['items']
  
          # Valid track is any track whose name resembles the title we're looking for
          # Spotify Metadata API also returns tracks whose ALBUM name resembles the query...
          valid_tracks = [track for track in track_listing if title == track['name'].lower().strip()]
          if valid_tracks:
              return PlaylistItem(valid_tracks[0]['name'], valid_tracks[0]['uri'], last_modified, expires)
          else:
              return None
code_tokens: def _fetch_item_from_api ( title ) : params = { 'q' : title , 'type' : 'track' } r = requests . get ( SPOTIFY_API_SEARCH_TRACK_URL , params = params ) if r . status_code not in VALID_API_STATUSCODES : raise ApiException ( r . status_code ) elif r . status_code == 404 : return None last_modified = datetime_from_http_datestring ( r . headers [ 'Date' ] ) max_age_match = re . match ( r'.*max-age=(?P<age>\d+)' , r . headers [ 'Cache-Control' ] ) if max_age_match : max_age = int ( max_age_match . group ( 'age' ) ) else : max_age = None expires = datetime . utcnow ( ) + timedelta ( seconds = max_age ) decoded_result = r . json ( ) track_listing = decoded_result [ 'tracks' ] [ 'items' ] valid_tracks = [ track for track in track_listing if title == track [ 'name' ] . lower ( ) . strip ( ) ] if valid_tracks : return PlaylistItem ( valid_tracks [ 0 ] [ 'name' ] , valid_tracks [ 0 ] [ 'uri' ] , last_modified , expires ) else : return None
short_docstring: Does a Spotify Metadata search and returns the first valid result
short_docstring_tokens: Does a Spotify Metadata search and returns the first valid result
comment: """
          Does a Spotify Metadata search and returns the first valid result
          """$SEP$# Something bad happened with the API that we can't recover from$SEP$# Valid track is any track whose name resembles the title we're looking for$SEP$# Spotify Metadata API also returns tracks whose ALBUM name resembles the query...