Package: google-nest-camera-proxy
google_nest_camera_proxyProxy your Nest Camera throughmediamtxso you can view it on any RTSP reader.How Google Nest Cameras WorkUnfortunately, Google does not let you just connect to an RTSP stream, or even an RTSPS string, and read your cameras. It is much more complicated than that. There are a few hoops that you have to jump through:Go through the Google Device Access Registration ProcessGet your Google Authentication TokensCreate your configuration filesInstall mediamtxRun the google-nest-camera-proxy applicationOnce this process is running what it does is reaches out to Google and gets an authentication token for the RTSPS stream, however that token only lasts for 5 minutes. It also includes an extension token, and this code will extend the token every 4 minutes so that you can record a continuous stream.Google Device Access Registration ProcessThis is a fairly onerous process, so make sure to read the details before you begin. (There is some more nice documentation of going through the process with screenshots athttps://geoffhudik.com/tech/2023/03/04/trying-google-nest-api-with-postman-and-python/)The biggest roadblock is that access to this API requires registering with Google for Device Accesshttps://developers.google.com/nest/device-access/registration. This has a one time $5 fee.The documentationhttps://developers.google.com/nest/device-access/get-startedwalks you through the rest of the process.I'm not going to cover all the details on how to get this done, because it is documented better elsewhere. Some addition documentation from Google about using their APIs is here:https://developers.google.com/nest/device-access/authorizehttps://developers.google.com/nest/device-access/use-the-apihttps://developers.google.com/nest/device-access/api/thermostatInstallationYou need to installmediamtx, which you can download athttps://github.com/bluenviron/mediamtx. This is the rtsp proxy that I use to translate from Google RTSPS to RTSP. Make a note of where you install it for the configuration fileInstall this module$pipinstallgoogle_nest_camera_proxyEdit the configuration file, whose default location is~/.config/nest/config. See the Configuration section below for the details.Basic InstructionsThese instructions were taken from the python-google-nest package (https://pypi.org/project/python-google-nest/) which provides the underlying libraries that I use to connect to the cameras. At a high level it involves:Making sure your Nest devices are linked to your Google accountSet up GCP (Google Cloud Platform) accounthttps://console.cloud.google.com/Set up a new GCP projectCreate an Oauth landing page and add your email as a test userEnable the Smart device management APICreate an Oauth credential with the settings called from web server andhttps://www.google.comas the authorized redirect URI. Note the client ID and secret from this step.Inhttps://console.nest.google.com/device-accesscreate a new project and add oauth client ID from step 3.3Follow the series of queries inhttps://developers.google.com/nest/device-access/authorizeto authorize devices. Note This step handled by this library.Be careful as you follow along the guide inhttps://developers.google.com/nest/device-access/get-started, since you're dealing with so many similar accounts and keys it can be easy to mix something up, and you won't get particularly useful errors.You should end up with the following pieces of information:project_id
: ID of the project you created inhttps://console.nest.google.com/device-accessclient_id
: value from setting up OAuth inhttps://console.cloud.google.com/projectclient_secret
: value from setting up OAuth inhttps://console.cloud.google.com/projectYou will need those values in the next section.ConfigurationYou need to create a confiuration file with the authentication details, and information about setting up themediamtxserver. Below is a sample file:[AUTH]
    client_id = MYCLIENTID
    client_secret = MYSECRET
    project_id = MYPROJECTID
    access_token_cache_file = /Users/ME/.config/nest/token_cache

[RTSP_SERVER]
    executable = /usr/local/bin/mediamtx
    config_filename = /Users/ME/.config/nest/rtsp.ymlclient_id
: This is the client_id from your project (from the credentials page on the Google console)client_secret
: The client secret (from the credentials page on the Google console)project_id
: The project ID (from the project page on the Google console)access_token_cache_file
: Where the token cache is storedexecutable
: The location you installed themediamtxexecutable.config_filename
: The location of themediamtxconfiguration file. This program adds all the cameras to the configuration fileAuthenticationAs part of the pyhon-google-nest package installation that is a dependency of this project, it creates anestapplication. The first time you runnest showit will tell you to go to a URL (https://nestservices.google.com/partnerconnectionswith some parameters), and then you will step through selecting and authorizing the cameras that you want to stream. When you finish this process your browser will have a URL that looks likehttps://www.google.com/?state=SOME_STATE_VALUE&code=SOME_AUTHENTICATION_CODE&scope=https://www.googleapis.com/auth/sdm.servicethat you need to copy and paste into the callback, which is then stored  in the ~/.config/nest/token_cache file.UsageUsage: google-nest-camera-proxy [OPTIONS]

  Configures the proxy rtsp server, and keeps it updated

  CONFIGURATION
  -------------
  The configuration file looks like this:

  [AUTH]
      client_id = client_id from Google
      client_secret = client secret from Google
      project_id = project id from Google
      access_token_cache_file = /Users/ME/.config/nest/token_cache

  [RTSP_SERVER]
      executable = /usr/local/bin/rtsp-simple-server
      config_filename = /Users/ME/.config/nest/rtsp

      See the README.md file to see how to get those values.

Options:
  -c, --configuration-file PATH  Where the configuration for this program is
                                 located
  -v, --verbose                  Turn on more informational output
  -d, --debug                    Turn on debugging output
  -n, --no-server                Update the file, but don't run the mediamtx
                                 server as a subprocess
  --help                         Show this message and exit.mediamtxConfigurationmediamtxcomes with a default configuration file that you can leave alone except for changing a few parameters. The only ones youhaveto change arereadUserandreadPass. You should put in a username and password, and those will need to be provided to the program that reads the camera.In addition,mediamtxprovides a lot of options that you won't need, so you can turn them off. This is optional, but here are my settings for these fields:protocols:[tcp]rtmp:nohls:nowebrtc:noWhen you rungoogle-nest-camera-proxyit regularly modifies themediamtxconfiguration file, adding the camera configuration to the bottom of it. Do not edit below this line"# NEST EDITS BELOW -- DO NOT EDIT THIS LINE OR BELOWConfiguring SecuritySpyI have found SecuritySpy (https://bensoftware.com/securityspy/) the best product to view and record cameras. To configure SecuritySpy to view the cameras:Open Settings in SecuritySpyGo to the Cameras tabOn the bottom left, hit the+and selectAdd Network DeviceIn theAddressbox, put the IP address of the box that is running themtxmediaserver. In my case, I use 127.0.0.1, since both the server and SecuritySpy are running on the same hostUnless you've changed thertspAddressparameter in themediamtx.ymlfile, put8554in theRTSP portbox.SelectManual Profilefrom theProfiledropdown.If you look in themediamtx.ymlfile at the bottom, there are lines that look like this. The tag is the name of the camera, and the source is the rtsps stream that changes regularly. Use the name in the file as the name of the camera, and put it in theRequestbox.Backyard:source:rtsps://stream-ue1-bravo.dropcam.com:443/sdm_live_stream/CiUA2vuxr2D61w4Y5ZU2awZvBxZoVD5zE-WgFM5ofLJiMML9NnXLEnEAEGF6Sh1PFqMRG4ynOX1qGu4MgBGjmBwDHgWpkCsHKWybOA?auth=g.0.eyJraWQiOiIyMzhiNTUxZmMyM2EyM2Y4M2E2ZTE3MmJjZTg0YmU3ZjgxMzAzMmM4IiwiYWxnIjoiUlMyNTYifQ.eyJpc3MBhaOhZ0Y5utipHFESKsG4499KfxIs_xuQ8HF1f6vzicaQ9zBGu3yFAWq6bx5hkd5rcrJRmRDjTgfKO96fy9UIYZZAmJptW9r8KGwreadUser:adminreadPass:mysecurepasswordFrontDoor:source:rtsps://stream-us1-foxtrot.dropcam.com:443/sdm_live_stream/CiUA2vuxr32E11B1alS1QRyq7w4mwEX8NRJEhMnJ_m2mTO9EiXXCEnEAEGF6SmAHpELf7bUIco7Dx3enLdzFi5I?auth=g.0.eyJraWQiOiIyMzhiNTUxZmMyM2EyM2Y4M2E2ZTE3MmJjZTg0YmU3ZjgxMzAzMmM4IiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJuZXN0LXNlY3VyaXR5LWF1dGhwcm94eSIsInN1YiI6Im5lc3RfaWQ6bmVzdC1waG9lbml4LXByb2Q6MTQxNDQwMSIsInBvbCI6IjNwLW9hdXRoLXNjb3BlLUFQSV9TRE1fU0VSVklDNzfcmq51D5VEk8P8ksPEeUNld-xl7BgO0844T-FjXMk7MKqMDYoum6qwYYwtwVGSP5V0KkMgg50E8PP_rUfm6bKp4KG2i50PGxcNOWFi2Uz0EVH1Q8rmCfX6TWHJb-n3I9I2XH6zv3Z-zjLba7fxvSdgmMjPgRfEF61xNOwnOkja3lqva7I6cWkwreadUser:adminreadPass:mysecurepasswordClickApply Preferencesand in just a few minutes it should start receiving the video.ContributingInterested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.Licensegoogle_nest_camera_proxywas created by Xev Gittler. It is licensed under the terms of the MIT license.Creditsgoogle_nest_camera_proxywas created withcookiecutterand thepy-pkgs-cookiecuttertemplate.