original_docstring: 
          Generates a Spotify playlist based on a passed message.
  
          returns a list containing PlaylistItem(s)
          
docstring: Generates a Spotify playlist based on a passed message.
  returns a list containing PlaylistItem(s)
docstring_tokens: Generates a Spotify playlist based on a passed message . returns a list containing PlaylistItem ( s )
code: def generate_playlist(self, message, use_max_chunk_length=False):
          """
          Generates a Spotify playlist based on a passed message.
  
          returns a list containing PlaylistItem(s)
          """
  
          # Filter non-alphanumeric, non-space characters
          message = re.sub(r'[^a-zA-Z0-9\s\']', '', message)
          # We want our playlist to contain at least two songs, so max_chunk_length must be less than total sentence length
          # can be overridden with the use_max_chunk_length
          if use_max_chunk_length:
              max_chunk_length = len(message.split())
          else:
              max_chunk_length = len(message.split()) - 1
          chunker = MessageChunker(message, max_chunk_length)
          playlist = []
          discarded_playlists = []
          index = 0
          words_covered = 0
          for chunk in chunker:
              if not chunk:
                  # The current list of (remaining) groups is depleted, so we're backtracking
                  discarded_playlists.append([item for item in playlist])
                  words_covered -= len(playlist.pop().name.split())
                  index -= 1
                  continue
  
              title = " ".join(chunk[index]).strip().lower()
  
              if self.cache:
                  try:
                      item = self._fetch_item_from_cache(title)
                  except ApiException:
                      raise
                  if item:
                      playlist.append(item)
                      words_covered += len(chunk[index])
                      index += 1
                      chunker.progress()
                      continue
  
              try:
                  item = self._fetch_item_from_api(title)
              except ApiException:
                  raise
              if item:
                  if self.cache:
                      self.cache.put(title, item)
                  playlist.append(item)
                  # Keep track of how many words are covered by our current playlist
                  words_covered += len(chunk[index])
                  index += 1
                  chunker.progress()
          if not playlist or words_covered < len(message.split()):
              # Apperently no complete playlist could be constructed, so we're taking the best effort
              incomplete = True
              sorted_playlists = sorted(discarded_playlists, key=len, reverse=True)
              playlist = sorted_playlists[0] if sorted_playlists else playlist
          else:
              incomplete = False
          return playlist, incomplete
code_tokens: def generate_playlist ( self , message , use_max_chunk_length = False ) : message = re . sub ( r'[^a-zA-Z0-9\s\']' , '' , message ) if use_max_chunk_length : max_chunk_length = len ( message . split ( ) ) else : max_chunk_length = len ( message . split ( ) ) - 1 chunker = MessageChunker ( message , max_chunk_length ) playlist = [ ] discarded_playlists = [ ] index = 0 words_covered = 0 for chunk in chunker : if not chunk : discarded_playlists . append ( [ item for item in playlist ] ) words_covered -= len ( playlist . pop ( ) . name . split ( ) ) index -= 1 continue title = " " . join ( chunk [ index ] ) . strip ( ) . lower ( ) if self . cache : try : item = self . _fetch_item_from_cache ( title ) except ApiException : raise if item : playlist . append ( item ) words_covered += len ( chunk [ index ] ) index += 1 chunker . progress ( ) continue try : item = self . _fetch_item_from_api ( title ) except ApiException : raise if item : if self . cache : self . cache . put ( title , item ) playlist . append ( item ) words_covered += len ( chunk [ index ] ) index += 1 chunker . progress ( ) if not playlist or words_covered < len ( message . split ( ) ) : incomplete = True sorted_playlists = sorted ( discarded_playlists , key = len , reverse = True ) playlist = sorted_playlists [ 0 ] if sorted_playlists else playlist else : incomplete = False return playlist , incomplete
short_docstring: Generates a Spotify playlist based on a passed message.
short_docstring_tokens: Generates a Spotify playlist based on a passed message .
comment: """
          Generates a Spotify playlist based on a passed message.
  
          returns a list containing PlaylistItem(s)
          """$SEP$# Filter non-alphanumeric, non-space characters$SEP$# We want our playlist to contain at least two songs, so max_chunk_length must be less than total sentence length$SEP$# can be overridden with the use_max_chunk_length$SEP$# The current list of (remaining) groups is depleted, so we're backtracking$SEP$# Keep track of how many words are covered by our current playlist$SEP$# Apperently no complete playlist could be constructed, so we're taking the best effort