summaryrefslogtreecommitdiff
path: root/cli/app/commands/cortex/upload_video.py
blob: 4590a6c0930b811e6f55ae3835802b61772e8ef7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import click
import json

import os
from app.settings import app_cfg
from app.search.video import export_video_final
from app.utils.cortex_utils import results_folder, upload_file_to_cortex

@click.command('')
@click.option('-i', '--input', 'opt_fp_in',
  help='Path to input folder (default: most recent folder in results)')
@click.option('-f', '--folder_id', 'opt_folder_id',
  help='ID of folder on Cortex (default: results folder)')
@click.pass_context
def cli(ctx, opt_fp_in, opt_folder_id):
  """
  Test uploading a file to Cortex
  """
  if opt_folder_id is None:
    folder = results_folder()
    opt_folder_id = folder['id']

  if opt_fp_in is None:
    for fn in sorted(os.listdir(app_cfg.DIR_RESULTS), reverse=True):
      fp_frames = os.path.join(app_cfg.DIR_RESULTS, fn)
      if os.path.isdir(fp_frames):
        opt_fp_in = fp_frames
        break

  frames = os.listdir(opt_fp_in)
  if len(frames) < 10:
    print("Didn't run long enough, skipping")
    return

  fp_out = os.path.join(app_cfg.DIR_RENDERS, fn + '.mp4')
  export_video_final(opt_fp_in, fp_out)
  if fp_out is None:
    return
  
  if not os.path.exists(fp_out):
    print("No video found")
    return
  
  print("Uploading {}".format(fp_out))
  data = upload_file_to_cortex(opt_folder_id, fp_out, datatype='video', activity='live')
  print(json.dumps(data, indent=2))