def handler(event, context): # config values USERNAME = os.getenv('USERNAME') PASSWORD = os.getenv('PASSWORD') QUEUENAME = os.getenv('QUEUENAME') S3BUCKET = os.getenv('S3BUCKET') prefix = os.getenv('prefix') cacheprefix = prefix + 'cache/' cache = Cache(S3BUCKET, cacheprefix) sqs = boto3.client('sqs') print(event) print(context) print(USERNAME) print(PASSWORD) print(QUEUENAME) print(S3BUCKET) print(prefix) print(cache) # get list of recent arlo media objects from past 7 days arlo = Arlo(USERNAME, PASSWORD) today = (date.today() - timedelta(days=0)).strftime("%Y%m%d") seven_days_ago = (date.today() - timedelta(days=7)).strftime("%Y%m%d") library = arlo.GetLibrary(seven_days_ago, today) # only process library items that have arrived since our last processing time latest_saved_media_timestamp = cache.get('latest_saved_media_timestamp') library = [ l for l in library if l['lastModified'] > latest_saved_media_timestamp ] if len(library) > 0: latest_saved_media_timestamp = max( [l['lastModified'] for l in library]) cameras = arlo.GetDevices('camera') camera_id2name = {} for c in cameras: camera_id2name[c['deviceId']] = c['deviceName'] for media in library: camera_name = camera_id2name.get(media['deviceId'], 'unknown_device') filename = camera_name + '_' + datetime.datetime.fromtimestamp( int(media['name']) // 1000).strftime('%Y-%m-%d %H-%M-%S') message = { "media": media, "metadata": { "s3bucket": S3BUCKET, "content_key": prefix + 'media/' + filename + '.mp4', "thumbnail_key": prefix + 'media/' + filename + '_thumbnail.jpg' } } print(message) response = sqs.send_message(QueueUrl=QUEUENAME, MessageBody=json.dumps(message)) cache.set('latest_saved_media_timestamp', latest_saved_media_timestamp, 3600 * 24 * 30)
import os.path USERNAME = '******' PASSWORD = '******' try: # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. # Subsequent successful calls to login will update the oAuth token. arlo = Arlo(USERNAME, PASSWORD) # At this point you're logged into Arlo. today = (date.today()-timedelta(days=0)).strftime("%Y%m%d") seven_days_ago = (date.today()-timedelta(days=7)).strftime("%Y%m%d") # Get all of the recordings for a date range. library = arlo.GetLibrary(seven_days_ago, today) # Iterate through the recordings in the library. for recording in library: videofilename = datetime.datetime.fromtimestamp(int(recording['name'])//1000).strftime('%Y-%m-%d %H-%M-%S') + ' ' + recording['uniq$ ## # The videos produced by Arlo are pretty small, even in their longest, best quality settings, # but you should probably prefer the chunked stream (see below). # # Download the whole video into memory as a single chunk. # video = arlo.GetRecording(recording['presignedContentUrl']) # with open('videos/'+videofilename, 'wb') as f: # f.write(video) # f.close() # Or: #
f.close() return if __name__ == "__main__": USERNAME = '******' PASSWORD = '******' try: # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. # Subsequent successful calls to login will update the oAuth token. arlo = Arlo(USERNAME, PASSWORD) today = (date.today() - timedelta(days=0)).strftime("%Y%m%d") yesterday = (date.today() - timedelta(days=1)).strftime("%Y%m%d") # Get all of the recordings for a date range. library = arlo.GetLibrary(yesterday, today) # Get most recent 4 videos in the library. for num in range(4): recording = library[num] vfname = "media/video" + str(num + 1) + ".mp4" writeVideoFile(arlo, recording, vfname) print("Successfully downloaded and updated 4 videos") except Exception as e: print(e)
execution_path = os.getcwd() firstVideo = False try: # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached. # Subsequent successful calls to login will update the oAuth token. arlo = Arlo(USERNAME, PASSWORD) # At this point you're logged into Arlo. today = (date.today() - timedelta(days=0)).strftime("%Y%m%d") seven_days_ago = (date.today() - timedelta(days=7)).strftime("%Y%m%d") # Get all of the recordings for a date range. library = arlo.GetLibrary(today, today) # Iterate through the recordings in the library. for recording in library: videoinfo = recording datevideo = datetime.datetime.fromtimestamp( int(recording['name']) // 1000, pytz.timezone("UTC")).strftime('%Y-%m-%d %H:%M:%S') videofilename = datetime.datetime.fromtimestamp( int(recording['name']) // 1000).strftime( '%Y-%m-%d %H-%M-%S') + ' ' + recording['uniqueId'] + '.mp4' ## # The videos produced by Arlo are pretty small, even in their longest, best quality settings, # but you should probably prefer the chunked stream (see below). ### # # Download the whole video into memory as a single chunk.