def get_track_id_from_json(item):
 fields = ['contentDetails/videoId', 'snippet/resourceId/videoId', 'id/videoId', 'id']
 for field in fields:
  node = item
  for p in field.split('/'):
   if (node and isinstance(node, dict)):
    node = node.get(p)
  if node:
   return node
 return ''

def get_track_id_from_json ( item ) : fields = [ 'contentDetails/videoId' , 'snippet/resourceId/videoId' , 'id/videoId' , 'id' ] for field in fields : node = item for p in field . split ( '/' ) : if ( node and isinstance ( node , dict ) ) : node = node . get ( p ) if node : return node return ''
try to extract video id from various response types .