rrwen / google_streetview

A command line tool and module for Google Street View Image API
https://rrwen.github.io/google_streetview
MIT License
98 stars 25 forks source link

Rename saved images #13

Open KAEYL98 opened 3 years ago

KAEYL98 commented 3 years ago

Hi,

Is it possible to specify the filename of the downloaded images when using results.download_links()?

Thank you

kevalshah90 commented 2 years ago

Same issue here. Did you figure out a way to do this?

@KAEYL98

I'am using this module to download several images and need them stored with unique file names. file_name is accessible by using .get method of python dictionary.

results.metadata[0].get('_file')

You can try something like this:

results.metadata[0]['_file'] = 'file_name.jpg'

results.metadata
lorenzoromani1983 commented 2 years ago

I slightly changed the api.py file, editing the results class as follows:

  def __init__(
    self,
    params,
    coordinates,
    heading,
    site_api='https://maps.googleapis.com/maps/api/streetview',
    site_metadata='https://maps.googleapis.com/maps/api/streetview/metadata'):

...

    self.params = params
    self.coordinates = coordinates
    self.heading = heading

...

  for i, url in enumerate(self.links):
    if metadata[i][metadata_status] == status_ok:
      file_path = path.join(dir_path, coordinates + "_" + str(heading) + '.jpg')
      metadata[i]['_file'] = path.basename(file_path) # add file reference
      helpers.download(url, file_path)

in such a way, you can instantiate the results class passing as arguments the parameters, the lat,lon coordinates and the heading value. All become mandatory with such a solution:

results = google_streetview.api.results(params, "45.1234,15.759", "270")

the file name will be created accordingly by joining the lat-lon-heading values and no overwriting will occur.