denven / yihack-onedrive-uploader

Upload your Yi-Camera video files to Microsoft OneDrive storage instead of subscribing a vendor's cloud plan.
MIT License
5 stars 0 forks source link
bash file-sync footage linux oauth2 onedrive shell-script upload uploader video yi-camera yi-hack

OneDrive-uploader for Yi IP Cameras

To visitors and cloners:

This repository is inspired by roleoroleo's yi-hack-MStar.gdrive uploader. The gdrive uploader does provide some convenience, however, my Google drive has only 15GB space shared with Gmail and other account applications, and it is very easy to get storage fully packed with uploaded media files. Fortunately, I've subscribed Microsoft 365 Developer Program which provides 5TB storage space. I think uploading files to OneDrive is a better option for me.

If you have a subscription of Microsoft OneDrive Stroage or Microsoft 365 Developer Program, you will get more storage space, which can allow you to store your camera videos and pictures to it other than paying an expensive manufacturer's storage premium plan.

Features

Supported camera models

Yi cameras hacked with the same file hiearacy or builtin applications are more likely to be supported. Anyway, your own separate tests are necessary before you use it. I've tested on my own camera.

  • [x] model y201c(Yi 1080p Dome BFUS) with firmware 4.6.0.0A_201908271549 and yi-hack-MStar 0.4.7 by denven
  • [x] model y623(Yi 1080p Pro 2K YFUS) with firmware 12.0.51.08_202403081746 and Allwinner v2 firmware v0.3.2 by @mrxyzl
  • [x] Yi 1080p Home IFUS + Allwinner v2 firmware by @kosauser

How to use the uploader?

Prerequisites

  1. make sure you've hacked your camera with the matched firmware, please check yi-hack-MStar or yi-hack-Allwinner-v2
  2. you have an OneDrive account assosiated with your Microsoft Azure account, you'd better have some knowledge of using the Azure portal.

Create Azure application for your uploader

  1. use App registrations to register an application on Azure portal

    • for the Supported account types choice: choose Accounts in this organizational directory only if your are a Azure Directory Single tenant; choose Personal Microsoft accounts only if you are using your own Personal OneDrive.
    • for the Redirect URI setting, choose WEB type and put a live redirectable URL, you can clone OAuth2 callback and use the code to serve a local redirect url http://localhost:8080/callback
      Register application
  2. set up the required Graph API permissions

    • For business/organization tenant user, add Files.ReadWrite.All Set up API Permissions Set up API Permissions
    • For personal account user, add Files.ReadWrite and Files.ReadWrite.All Set up API Permissions
  3. get your application client id, and tenant id (used for tenant account only, ignore it for personal account) Get application id and tenant id

  4. create a client secret and save the secret Value for next steps Get client credential

  5. Authentication setting for personal account type only Authentication

Use the repository code and setup on your camera

  1. clone the repository code to your local computer and enter the code directory
  2. use the data fetched from Azure application to fill in your config.json file before uploading the files to camera. Please refer to the following example to edit the config.json file in your directory:
    {
    "grant_type": "authorization_code",
    "client_id": "9083c44f-605d-4d31-9d16-955e48d69965",
    "client_secret": "dFE8Q~bUtscYyoTUCxt3RLawrfsnyVGARFhGdcH7",
    "tenant_id": "e2a801f7-46fe-4dcf-91b7-6d4409c7760e",
    "scope": "https://graph.microsoft.com/.default",
    "video_root_folder": "yihack_videos",
    "convert_utc_path_name": "false",
    "auto_clean_threshold": "100",
    "enable_idle_transfer": "false"
    }
Configuration key Default value Description
grant_type authorization_code
client_id "" fill in with your data
client_secret "" fill in with your data
tenant_id "" for personal account, set it as "consumers"; for tenant account, set a specific tenant id
scope https://graph.microsoft.com/.default not required
video_root_folder yihack_videos name string without white spaces
upload_video_only true not required; set it false will upload *.jpg files in the record folders
convert_utc_path_name false not required; set it to true if you don't like the uploaded folders are in UTC time (for firmware v0.4.9 and later)
auto_clean_threshold 100 value in range [50, 100) will enable this feature
enable_idle_transfer false setting to true has chances of files upload delayed
  1. upload code and dependent files to your camera sd card via ssh with root account or a FTP tool, the target path: /tmp/sd/yi-hack:

    • create an empty directory named onedrive in path /tmp/sd/yi-hack
    • upload init.sh, stop.sh and scripts and bin directory to /tmp/sd/yi-hack/onedrive
    • upload your own config.json file to /tmp/sd/yi-hack/onedrive
  2. sign in your Microsoft Azure account first

  3. run the entry Shell script init.sh to complete the application authorization grant flow

cd /tmp/sd/yi-hack/onedrive/
./init.sh

Ahthorize uploader

  1. optional: reboot your camera
    reboot -f # reboot without -f option cannot work on my camera

Maintenance

cd /tmp/sd/yi-hack/onedrive
./stop.sh