-
Notifications
You must be signed in to change notification settings - Fork 2
/
arlo-downloader.py
executable file
·148 lines (132 loc) · 5.9 KB
/
arlo-downloader.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python
import logging
import os
import sys
import pyaarlo
import asyncio
import argparse
from config import Config
def parse_arguments():
parser = argparse.ArgumentParser(description='Download records from Arlo Cameras.')
parser.add_argument('-d',
'--debug',
action='store_true',
help='Enable Debug messages. Can also be set with environment variable DEBUG=1')
parser.add_argument('-m',
'--save-media-to',
help="Save Media naming scheme without extension (default = \'{}\')".format(Config.config("save_media_to")),
action='store')
parser.add_argument('-t',
'--tfa-type',
choices=['PUSH', 'EMAIL'],
help="Set TFA type (default = \'{}\')".format(Config.config("tfa_type")),
action='store')
parser.add_argument('-s',
'--tfa-source',
choices=['push', 'imap'],
help="Set TFA source (default = \'{}\')".format(Config.config("tfa_source")),
action='store')
parser.add_argument('-r',
'--tfa-retries',
help="Set TFA max retries (default = {}).".format(Config.config("tfa_retries")),
type=int,
action='store')
parser.add_argument('-D',
'--tfa-delay',
help="Set TFA delay between each check (default = {}).".format(Config.config("tfa_delay")),
type=int,
action='store')
parser.add_argument('-H',
'--tfa-host',
help="(EMAIL/imap only) Set TFA host (default = {}).".format(Config.config("tfa_host")),
action='store')
parser.add_argument('-U',
'--tfa-username',
help="(EMAIL/imap only) Set TFA username (default = {}).".format(Config.config("tfa_username")),
action='store')
parser.add_argument('-P',
'--tfa-password',
help="(EMAIL/imap only) Set TFA password (default = {}).".format(Config.config("tfa_password")),
action='store')
args = parser.parse_args()
return args
def set_logger(dbg):
level = logging.INFO
if (dbg):
level = logging.DEBUG
logging.basicConfig(level=level,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt="%Y-%m-%dT%H:%M:%S%z"
)
_LOGGER = logging.getLogger(__name__)
def Init():
# code to trap when attributes change
def attribute_changed(device, attr, value):
logging.info('attribute_changed:' + device.name + ':' + attr + ':' + str(value)[:80])
# set these from the environment to log in
USERNAME = os.environ.get('ARLO_USERNAME', '_INVALID')
PASSWORD = os.environ.get('ARLO_PASSWORD', '_INVALID')
# Print configuration in DEBUG
for confItem in Config.dump_config().items(): logging.debug(confItem)
# log in
# add `dump=True` to enable event stream packet dumps
arlo = pyaarlo.PyArlo(username=USERNAME, password=PASSWORD,
tfa_type=Config.config('tfa_type'),
tfa_source=Config.config('tfa_source'),
tfa_retries=Config.config('tfa_retries'),
tfa_delay=Config.config('tfa_delay'),
tfa_host=Config.config('tfa_host'),
tfa_username=Config.config('tfa_username'),
tfa_password=Config.config('tfa_password'),
synchronous_mode=False,
mode_api='v2',
save_state=True,
dump=False,
storage_dir='aarlo',
save_media_to=Config.config('save_media_to'))
if not arlo.is_connected:
logging.info("failed to login({})".format(arlo._last_error))
sys.exit(-1)
# get base stations, list their statuses, register state change callbacks
for base in arlo.base_stations:
logging.info("base: name={},device_id={},state={}".format(base.name,base.device_id,base.state))
base.add_attr_callback('*', attribute_changed)
# get cameras, list their statuses, register state change callbacks
# * is any callback, you can use motionDetected just to get motion events
for camera in arlo.cameras:
logging.info("camera: name={},device_id={},state={}".format(camera.name,camera.device_id,camera.state))
camera.add_attr_callback('*', attribute_changed)
def main(arguments):
loop = asyncio.get_event_loop()
if arguments.save_media_to:
Config.set("save_media_to", arguments.save_media_to)
if arguments.tfa_type:
Config.set("tfa_type", arguments.tfa_type)
if arguments.tfa_source:
Config.set("tfa_source", arguments.tfa_source)
if arguments.tfa_retries:
Config.set("tfa_retries", arguments.tfa_retries)
if arguments.tfa_delay:
Config.set("tfa_delay", arguments.tfa_delay)
if arguments.tfa_host:
Config.set("tfa_host", arguments.tfa_host)
if arguments.tfa_username:
Config.set("tfa_username", arguments.tfa_username)
if arguments.tfa_password:
Config.set("tfa_password", arguments.tfa_password)
if arguments.debug:
set_logger(True)
elif (os.environ.get('DEBUG') and os.environ.get('DEBUG') == '1'):
set_logger(True)
else:
set_logger(False)
try:
Init()
loop.run_forever()
except KeyboardInterrupt:
sys.exit(0)
finally:
loop.close()
if __name__ == "__main__":
arguments = parse_arguments()
main(arguments)