Option to send Google Drive link to video via email #1719

Open
opened 2026-02-28 00:52:23 -05:00 by deekerman · 0 comments
Owner

Originally created by @morrowsend on GitHub (Jul 18, 2020).

I posted a reply to a similar request in motioneyeOS but I think it ultimately should live in motineye instead.

Essentially, it would be helpful to be able to return google drive links to videos or images for external services. In my own case, I'd like to have an option in the email when motion is detected to include a link to the video on google drive. I think this would be very helpful for users. That said, I don't know enough with python to fully implement this myself. My issue is mainly that I don't know how to structure it, but I have researched enough to have some code that I feel could live in uploadServices.py that could return the link to the google drive video preview but I'm not really sure how to get that in the email. Here's the info from my post I mentioned previously with code snippets:

Take a look at motioneye's uploadServices.py
After the _upload_data function is called. It gives the file a title based on filename. Which then uploads it to google.

Google assigns it a random fileID, but doesn't return this value to you in any way. You'll need to request it.

Get the folderID this file is stored in somehow (how does clear_cloud do it?) This is given a title based on the current date and will be needed for the next step.

Get the list of [children sorted by modifiedDate in descending order. Your first child is the most recent file]
(https://developers.google.com/drive/api/v2/reference/children/list)
orderBy=folder,modifiedDate desc,title
If you don't use your google drive for any other purpose, you can just get the most recent file uploaded. Here's an example python script for that.

Squashing code from those two references together give something like this for getting the fileID:

from apiclient import errors
# ...

def print_files_in_folder(service, folder_id):
  """Print files belonging to a folder.

  Args:
    service: Drive API service instance.
    folder_id: ID of the folder to print files from.
  """
  page_token = None
    try:
      param = {}
      if page_token:
        param['pageToken'] = page_token
      children = service.children().list(
          folderId=folder_id, orderBy="createdTime", **param).execute() 
          #returns a presorted list

      childItems = children.get('items', []):
      child = childItems[0]; #returns most recent file in the folder
        print 'File Id: %s' % child['id']

    except errors.HttpError, error:
      print 'An error occurred: %s' % error
      break

Then you should have the fileID.

You know that the share link will always take the form of https://drive.google.com/file/d/<fileID> so build the string manually.

As I said, I looked at this for a few hours last night but couldn't figure out how to incorporate this in any meaningful way. Should this be an option on the webUI like a checkbox when someone sets up sending emails? Since the upload service and sendmail.py service don't talk to one another, how could I pass the data of the current folderID and fileID from the upload service back to the sendmail? Then it'd need to add an optional field to the email.

Hopefully this is on the right direction and helps someone implement this!

Originally created by @morrowsend on GitHub (Jul 18, 2020). [I posted a reply to a similar request in motioneyeOS](https://github.com/ccrisan/motioneyeos/issues/2401) but I think it ultimately should live in motineye instead. Essentially, it would be helpful to be able to return google drive links to videos or images for external services. In my own case, I'd like to have an option in the email when motion is detected to include a link to the video on google drive. I think this would be very helpful for users. That said, I don't know enough with python to fully implement this myself. My issue is mainly that I don't know how to structure it, but I have researched enough to have some code that I feel could live in uploadServices.py that could return the link to the google drive video preview but I'm not really sure how to get that in the email. Here's the info from my post I mentioned previously with code snippets: > Take a look at [motioneye's uploadServices.py](https://github.com/ccrisan/motioneye/blob/b7007ae83cb424bdf2257db85f8f278267cd7ead/motioneye/uploadservices.py) > After the `_upload_data` function is called. It gives the file a title based on filename. Which then uploads it to google. > > Google assigns it a random `fileID`, but doesn't return this value to you in any way. You'll need to request it. > > Get the `folderID `this file is stored in somehow (how does clear_cloud do it?) This is given a title based on the current date and will be needed for the next step. > > Get the list of [children sorted by `modifiedDate `in descending order. Your first child is the most recent file] > (https://developers.google.com/drive/api/v2/reference/children/list) > `orderBy=folder,modifiedDate desc,title ` > If you don't use your google drive for any other purpose, you can just get the most recent file uploaded. [Here's an example python script for that.](http://eyana.me/list-gdrive-folders-python/#one) > > Squashing code from those two references together give something like this for getting the `fileID`: > > ``` > from apiclient import errors > # ... > > def print_files_in_folder(service, folder_id): > """Print files belonging to a folder. > > Args: > service: Drive API service instance. > folder_id: ID of the folder to print files from. > """ > page_token = None > try: > param = {} > if page_token: > param['pageToken'] = page_token > children = service.children().list( > folderId=folder_id, orderBy="createdTime", **param).execute() > #returns a presorted list > > childItems = children.get('items', []): > child = childItems[0]; #returns most recent file in the folder > print 'File Id: %s' % child['id'] > > except errors.HttpError, error: > print 'An error occurred: %s' % error > break > ``` > > Then you should have the `fileID`. > > You know that the share link will always take the form of `https://drive.google.com/file/d/<fileID>` so build the string manually. > > As I said, I looked at this for a few hours last night but couldn't figure out how to incorporate this in any meaningful way. Should this be an option on the webUI like a checkbox when someone sets up sending emails? Since [the upload service](https://github.com/ccrisan/motioneye/blob/b7007ae83cb424bdf2257db85f8f278267cd7ead/motioneye/uploadservices.py) and [sendmail.py](https://github.com/ccrisan/motioneye/blob/b7007ae83cb424bdf2257db85f8f278267cd7ead/motioneye/sendmail.py) service don't talk to one another, how could I pass the data of the current `folderID `and `fileID `from the upload service back to the sendmail? Then it'd need to add an optional field to the email. > > Hopefully this is on the right direction and helps someone implement this!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/motioneye#1719
No description provided.