code: def _build_filename_from_browserstack_json(j):
      
      filename = ''
      device = j['device'] if j['device'] else 'Desktop'
      if j['state'] == 'done' and j['image_url']:
          detail = [device, j['os'], j['os_version'],
                    j['browser'], j['browser_version'], '.jpg']
          filename = '_'.join(item.replace(" ", "_") for item in detail if item)
      else:
          print 'screenshot timed out, ignoring this result'
      return filename
docs: Build a useful filename for an image from the screenshot json metadata