Advertisement
Nomadadon

Get_Arlo_Videos.py

Sep 26th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. # Install base code from: https://github.com/jeffreydwalter/arlo
  4. # pip install arlo
  5.  
  6. from Arlo import Arlo
  7.  
  8. from datetime import timedelta, date
  9. import datetime
  10. import sys
  11.  
  12. USERNAME = 'robert.l.harris@gmail.com'
  13. PASSWORD = 'R4nd0mP4sswd'
  14.  
  15. try:
  16. # Instantiating the Arlo object automatically calls Login(), which returns an oAuth token that gets cached.
  17. # Subsequent successful calls to login will update the oAuth token.
  18. print('Logging in '+USERNAME)
  19. arlo = Arlo(USERNAME, PASSWORD)
  20. # At this point you're logged into Arlo.
  21.  
  22. today = (date.today()-timedelta(days=0)).strftime("%Y%m%d")
  23. #today = ''.join((date.today()-timedelta(days=0)).strftime("%Y%m%d"))
  24. seven_days_ago = (date.today()-timedelta(days=7)).strftime("%Y%m%d")
  25. #seven_days_ago = ''.join((date.today()-timedelta(days=7)).strftime("%Y%m%d"))
  26. print('Getting from '+seven_days_ago+' until '+today)
  27.  
  28.  
  29. # Get all of the recordings for a date range.
  30. print('Pre-Library Pull')
  31. print(' '+seven_days_ago, "is of type", type(seven_days_ago))
  32. print(' '+today, "is of type", type(today))
  33. # range = seven_days_ago+', '+today
  34. # library = arlo.GetLibrary( range )
  35. library = arlo.GetLibrary( seven_days_ago, today )
  36. print('Library: '+library)
  37.  
  38. # Iterate through the recordings in the library.
  39. for recording in library:
  40.  
  41. print('Getting recording '+recording+' from '+recording['createdDate']+' and saving as '+videofilename+'.')
  42. videofilename = datetime.datetime.fromtimestamp(int(recording['name'])//1000).strftime('%Y-%m-%d %H-%M-%S') + ' ' + recording['uniqueId'] + '.mp4'
  43. ##
  44. # The videos produced by Arlo are pretty small, even in their longest, best quality settings,
  45. # but you should probably prefer the chunked stream (see below).
  46. ###
  47. # # Download the whole video into memory as a single chunk.
  48. # video = arlo.GetRecording(recording['presignedContentUrl'])
  49. # with open('videos/'+videofilename, 'wb') as f:
  50. # f.write(video)
  51. # f.close()
  52. # Or:
  53. #
  54. # Get video as a chunked stream; this function returns a generator.
  55. stream = arlo.StreamRecording(recording['presignedContentUrl'])
  56. with open('~/Arlo/videos/'+videofilename, 'wb') as f:
  57. for chunk in stream:
  58. f.write(chunk)
  59. #f.write(join(chunk))
  60. f.close()
  61.  
  62. print('Downloaded video '+videofilename+' from '+recording['createdDate']+'.')
  63.  
  64. # Delete all of the videos you just downloaded from the Arlo library.
  65. # Notice that you can pass the "library" object we got back from the GetLibrary() call.
  66. # result = arlo.BatchDeleteRecordings(library)
  67.  
  68. # If we made it here without an exception, then the videos were successfully deleted.
  69. print('Batch deletion of videos completed successfully.')
  70.  
  71. except Exception as e:
  72. print(e)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement