From 9825d2afb32adee9ba244d50bd8e5fe85e4de949 Mon Sep 17 00:00:00 2001 From: konradit Date: Sat, 29 Dec 2018 17:07:33 +0100 Subject: [PATCH] Fix listMedia && add dowload today example --- README.md | 2 +- docs/docs.md | 306 +++++++++++++++---------------------- examples/download_today.py | 36 +++++ examples/hero3_tests.py | 40 +++-- goprocam/GoProCamera.py | 6 +- 5 files changed, 184 insertions(+), 206 deletions(-) create mode 100644 examples/download_today.py diff --git a/README.md b/README.md index 5a9d5a2..3c02fe3 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ python setup.py install Connect your camera to your computer via WiFi (WiFi on the camera must be on!) -``` +```python from goprocam import GoProCamera, constants goproCamera = GoProCamera.GoPro() goproCamera.shoot_video(10) diff --git a/docs/docs.md b/docs/docs.md index 5f80840..9b403e2 100644 --- a/docs/docs.md +++ b/docs/docs.md @@ -1,248 +1,194 @@ ## Docs: -`GoPro(camera='detect', ip_address='10.5.5.9', -mac_address='AA:BB:CC:DD:EE:FF') ` - - - ` - | Methods defined here: - -**IsRecording**(self) - - ` Returns either 0 or 1 if the camera is recording or not.` +* GoPro(camera='detect', ip_address='10.5.5.9', +mac_address='AA:BB:CC:DD:EE:FF') + +### Methods defined here: -**KeepAlive**(self) +* **IsRecording**(self) + * Returns either 0 or 1 if the camera is recording or not. - ` Sends keep alive packet` +* **KeepAlive**(self) + * Sends keep alive packet -**__init__**(self, camera='detect', ip_address='10.5.5.9', +* **__init__**(self, camera='detect', ip_address='10.5.5.9', mac_address='AA:BB:CC:DD:EE:FF') + * Initialize self. See help(type(self)) for accurate signature. - ` Initialize self. See help(type(self)) for accurate signature.` - -**__str__**(self) - - ` Return str(self).` - -**cancelClip**(self, video_id) - - ` cancels clip conversion` - -**changeWiFiSettings**(self, ssid, password) - - ` Changes ssid and passwod of Hero4 camera` - -**clipStatus**(self, status) - - ` returns clip status` - -**delete**(self, option) - - ` Deletes media. "last", "all" or an integer are accepted values for option` - -**deleteFile**(self, folder, file) - - ` Deletes a file. Pass folder and file as parameters.` - -**downloadAll**(self, option='') - - ` Download all media on camera` - -**downloadLastMedia**(self, path='', custom_filename='') - - ` Downloads last media taken, set custom_filename to download to that filename` - -**downloadLowRes**(self, path='', custom_filename='') - - ` Downloads the low-resolution video` - -**downloadMedia**(self, folder, file, custom_filename='') - - ` Downloads specific folder and filename` - -**downloadMultiShot**(self, path='') - - ` Downloads a multi-shot sequence.` - -**getClip**(self, file, resolution, frame_rate, start_ms, stop_ms) +* **__str__**(self) + * Return str(self). - ` Starts a clip conversion: -file: folder + filename -resolution: see constants.Clip -frame_rate: see constants.Clip -start_ms: start of the video in ms -stop_ms: stop of the video in ms` +* **cancelClip**(self, video_id) + * cancels clip conversion -**getClipURL**(self, status) +* **changeWiFiSettings**(self, ssid, password) + * Changes ssid and passwod of Hero4 camera - ` gets clip URL from status` +* **clipStatus**(self, status) + * returns clip status -**getInfoFromURL**(self, url) +* **delete**(self, option) + * Deletes media. "last", "all" or an integer are accepted values for option - ` Gets information from Media URL.` +* **deleteFile**(self, folder, file) + * Deletes a file. Pass folder and file as parameters. -**getMedia**(self) +* **downloadAll**(self, option='') + * Download all media on camera - ` Returns last media URL` +* **downloadLastMedia**(self, path='', custom_filename='') + * Downloads last media taken, set custom_filename to download to that filename -**getMediaFusion**(self) +* **downloadLowRes**(self, path='', custom_filename='') + * Downloads the low-resolution video -**getMediaInfo**(self, option) +* **downloadMedia**(self, folder, file, custom_filename='') + * Downloads specific folder and filename - ` Returns an array of the last media, both front and back URLs` +* **downloadMultiShot**(self, path='') + * Downloads a multi-shot sequence. -**getPassword**(self) +* **getClip**(self, file, resolution, frame_rate, start_ms, stop_ms) + * Starts a clip conversion: + * file: folder + filename + * resolution: see constants.Clip + * frame_rate: see constants.Clip + * start_ms: start of the video in ms + * stop_ms: stop of the video in ms - ` Gets password from Hero3, Hero3+ cameras` +* **getClipURL**(self, status) + * gets clip URL from status -**getPhotoEXIF**(self, option='', folder='', file='') +* **getInfoFromURL**(self, url) + * Gets information from Media URL. - ` Gets Photo EXIF data, set folder and file parameters.` +* **getMedia**(self) + * Returns last media URL -**getPhotoInfo**(self, option='', folder='', file='') +* **getMediaFusion**(self) - ` Gets photo nformation, set folder and file parameters. -option parameters: w/h/wdr/raw...` +* **getMediaInfo**(self, option) + * Returns an array of the last media, both front and back URLs -**getStatus**(self, param, value='') +* **getPassword**(self) + * Gets password from Hero3, Hero3+ cameras - ` This returns a status message based on param (status/setting) and value (numeric)` +* **getPhotoEXIF**(self, option='', folder='', file='') + * Gets Photo EXIF data, set folder and file parameters. -**getStatusRaw**(self) +* **getPhotoInfo**(self, option='', folder='', file='') + * Gets photo nformation, set folder and file parameters. + * option parameters: w/h/wdr/raw... - ` Delivers raw status message` +* **getStatus**(self, param, value='') + * This returns a status message based on param (status/setting) and value (numeric) -**getVideoInfo**(self, option='', folder='', file='') +* **getStatusRaw**(self) + * Delivers raw status message - ` Gets video information, set folder and file parameters. -option parameters: dur/tag_count/tags/profile/w/h` +* **getVideoInfo**(self, option='', folder='', file='') + * Gets video information, set folder and file parameters. +option parameters: dur/tag_count/tags/profile/w/h -**gpControlCommand**(self, param) +* **gpControlCommand**(self, param) + * sends Parameter gpControl/command - ` sends Parameter gpControl/command` +* **gpControlExecute**(self, param) + * sends Parameter to gpControl/execute -**gpControlExecute**(self, param) +* **gpControlSet**(self, param, value) + * sends Parameter and value to gpControl/setting - ` sends Parameter to gpControl/execute` +* **hilight**(self) + * Tags a hilight in the video -**gpControlSet**(self, param, value) +* **infoCamera**(self, option='') + * Gets camera info, such as mac address and firmware version. See constants.Camera for possible options. - ` sends Parameter and value to gpControl/setting` - -**hilight**(self) - - ` Tags a hilight in the video` - -**infoCamera**(self, option='') - - ` Gets camera info, such as mac address and firmware version. See constants.Camera for possible options.` - -**listMedia**(self, format=False, media_array=False) - - ` Lists media on SD card +* **listMedia**(self, format=False, media_array=False) + * Lists media on SD card format = (True/False) - Sets formatting -media_array = (True/False) - returns an array` - -**livestream**(self, option) +media_array = (True/False) - returns an array - ` start livestreaming -option = "start"/"stop"` +* **livestream**(self, option) + * start livestreaming +option = "start"/"stop" -**locate**(self, param) +* **locate**(self, param) + * Starts or stops locating (beeps camera) - ` Starts or stops locating (beeps camera)` +* **mode**(self, mode, submode='0') + * Changes mode of the camera. See constants.Mode and constants.Mode.SubMode for sub-modes. -**mode**(self, mode, submode='0') +* **overview**(self) - ` Changes mode of the camera. See constants.Mode and constants.Mode.SubMode for sub-modes.` - -**overview**(self) - -**pair**(self, usepin=True) - - ` This is a pairing procedure needed for HERO4 and HERO5 cameras. When those type GoPro camera are purchased the GoPro Mobile app needs an authentication code when pairing the camera to a mobile device for the first time. +* **pair**(self, usepin=True) + * This is a pairing procedure needed for HERO4 and HERO5 cameras. When those type GoPro camera are purchased the GoPro Mobile app needs an authentication code when pairing the camera to a mobile device for the first time. The code is useless afterwards. This function will pair your GoPro to the -machine without the need of using the mobile app -- at all.` - -**parse_value**(self, param, value) - -**power_off**(self) - - ` Sends power off command` - -**power_on**(self, _mac_address='') +machine without the need of using the mobile app -- at all. - ` Sends power on command. Mac address might need to be defined` +* **parse_value**(self, param, value) -**power_on_auth**(self) +* **power_off**(self) + * Sends power off command - ` Sends power on command to Hero 3/3+ cameras` +* **power_on**(self, _mac_address='') + * Sends power on command. Mac address might need to be defined -**prepare_gpcontrol**(self) +* **power_on_auth**(self) + * Sends power on command to Hero 3/3+ cameras -**reset**(self, r) +* **prepare_gpcontrol**(self) - ` Resets video/photo/multishot protune values` +* **reset**(self, r) + * Resets video/photo/multishot protune values -**sendBacpac**(self, param, value) +* **sendBacpac**(self, param, value) + * sends Parameter and value to 10.5.5.9/camera/ - ` sends Parameter and value to 10.5.5.9/camera/` +* **sendCamera**(self, param, value='') + * sends Parameter and value to 10.5.5.9/camera/ -**sendCamera**(self, param, value='') +* **setZoom**(self, zoomLevel) + * Sets camera zoom (Hero6/Hero7), zoomLevel is an integer - ` sends Parameter and value to 10.5.5.9/camera/` +* **shoot_video**(self, duration=0) + * Shoots a video, if duration is 0 it will not stop the video, set duration to an integer to set the video duration. -**setZoom**(self, zoomLevel) +* **shutter**(self, param) + * Starts/stop video or timelapse recording, pass constants.start or constants.stop as value in param - ` Sets camera zoom (Hero6/Hero7), zoomLevel is an integer` - -**shoot_video**(self, duration=0) - - ` Shoots a video, if duration is 0 it will not stop the video, set duration to an integer to set the video duration.` - -**shutter**(self, param) - - ` Starts/stop video or timelapse recording, pass constants.start or constants.stop as value in param` - -**stream**(self, addr, quality='') - - ` Starts a FFmpeg instance for streaming to an address +* **stream**(self, addr, quality='') + * Starts a FFmpeg instance for streaming to an address addr: Address to stream to -quality: high/medium/low` - -**streamSettings**(self, bitrate, resolution) +quality: high/medium/low - ` Sets stream settings` +* **streamSettings**(self, bitrate, resolution) + * Sets stream settings -**syncTime**(self) +* **syncTime**(self) + * Sets time and date to computer's time and date - ` Sets time and date to computer's time and date` +* **take_photo**(self, timer=1) + * Takes a photo. Set timer to an integer to set a wait time -**take_photo**(self, timer=1) +* **video_settings**(self, res, fps='none') + * Change video resolution and FPS +See constants.Video.Resolution - ` Takes a photo. Set timer to an integer to set a wait time` - -**video_settings**(self, res, fps='none') - - ` Change video resolution and FPS -See constants.Video.Resolution` - -**whichCam**(self) - - ` This returns what type of camera is currently connected. -- gpcontrol: HERO4 Black and Silver, HERO5 Black and Session, HERO Session (formally known as HERO4 Session), HERO+ LCD, HERO+. -- auth: HERO2 with WiFi BacPac, HERO3 Black/Silver/White, HERO3+ Black and Silver.` +* **whichCam**(self) + * This returns what type of camera is currently connected. + - gpcontrol: HERO4 Black and Silver, HERO5 Black and Session, HERO Session (formally known as HERO4 Session), HERO+ LCD, HERO+. + - auth: HERO2 with WiFi BacPac, HERO3 Black/Silver/White, HERO3+ Black and Silver. * * * Data descriptors defined here: -**__dict__** - - ` dictionary for instance variables (if defined)` - -**__weakref__** +* **__dict__** + * dictionary for instance variables (if defined) - ` list of weak references to the object (if defined)` +* **__weakref__** + * list of weak references to the object (if defined) diff --git a/examples/download_today.py b/examples/download_today.py new file mode 100644 index 0000000..abe044e --- /dev/null +++ b/examples/download_today.py @@ -0,0 +1,36 @@ +from goprocam import GoProCamera, constants +import argparse +import datetime + +parser = argparse.ArgumentParser() +parser.add_argument('--video', "-v", help='Download videos only', required=False, type=bool) +parser.add_argument('--photo', "-p", help='Download photos only', required=False, type=bool) +parser.add_argument('--all', "-a", help='Download all', required=False, type=bool) +parser.add_argument('--out', "-o", help='Output path', default="") + +args = parser.parse_args() +gopro = GoProCamera.GoPro() + +medialist = gopro.listMedia(format=True, media_array=True) +currentdate = datetime.datetime.today().date() + +if args.video: + for media in medialist: + dat = datetime.datetime.fromtimestamp(int(media[3])).date() + if "MP4" in media[1] and dat == currentdate: + newpath = args.out + "/" + media[1] + gopro.downloadMedia(media[0], media[1], newpath) +if args.photo: + for media in medialist: + dat = datetime.datetime.fromtimestamp(int(media[3])).date() + if "JPG" in media[1] and dat == currentdate: + newpath = args.out + "/" + media[1] + gopro.downloadMedia(media[0], media[1], newpath) +if args.all: + for media in medialist: + dat = datetime.datetime.fromtimestamp(int(media[3])).date() + if dat == currentdate: + newpath = args.out + "/" + media[1] + gopro.downloadMedia(media[0], media[1], newpath) + + diff --git a/examples/hero3_tests.py b/examples/hero3_tests.py index ffc7912..8ba1526 100644 --- a/examples/hero3_tests.py +++ b/examples/hero3_tests.py @@ -4,25 +4,21 @@ gpCam = GoProCamera.GoPro(constants.auth) gpCam.infoCamera("model_name") - -if gpCam.getStatus(constants.Hero3Status.Mode) == 00: - print("videomode") -gpCam.getStatus(constants.Hero3Status.SpotMeter) -gpCam.getStatus(constants.Hero3Status.TimeLapseInterval) -gpCam.getStatus(constants.Hero3Status.FOV) -gpCam.getStatus(constants.Hero3Status.Beep) -gpCam.getStatus(constants.Hero3Status.LED) -gpCam.getStatus(constants.Hero3Status.AutoOff) -gpCam.getStatus(constants.Hero3Status.VideoRes) -gpCam.getStatus(constants.Hero3Status.FPS) -gpCam.getStatus(constants.Hero3Status.Loop) -gpCam.getStatus(constants.Hero3Status.WhiteBalance) -gpCam.getStatus(constants.Hero3Status.IsRecording) -gpCam.getStatus(constants.Hero3Status.PicRes) -gpCam.getStatus(constants.Hero3Status.TimeRecordedMins) -gpCam.getStatus(constants.Hero3Status.TimeRecordedSecs) -gpCam.getStatus(constants.Hero3Status.Charging) -gpCam.getStatus(constants.Hero3Status.PicturesTaken) - -gpCam.getStatus(constants.Hero3Status.VideoRemaining) -gpCam.getStatus(constants.Hero3Status.VideosTaken) +print(gpCam.getStatus(constants.Hero3Status.SpotMeter)) +print(gpCam.getStatus(constants.Hero3Status.TimeLapseInterval)) +print(gpCam.getStatus(constants.Hero3Status.FOV)) +print(gpCam.getStatus(constants.Hero3Status.Beep)) +print(gpCam.getStatus(constants.Hero3Status.LED)) +print(gpCam.getStatus(constants.Hero3Status.AutoOff)) +print(gpCam.getStatus(constants.Hero3Status.VideoRes)) +print(gpCam.getStatus(constants.Hero3Status.FPS)) +print(gpCam.getStatus(constants.Hero3Status.Loop)) +print(gpCam.getStatus(constants.Hero3Status.WhiteBalance)) +print(gpCam.getStatus(constants.Hero3Status.IsRecording)) +print(gpCam.getStatus(constants.Hero3Status.PicRes)) +print(gpCam.getStatus(constants.Hero3Status.TimeRecordedMins)) +print(gpCam.getStatus(constants.Hero3Status.TimeRecordedSecs)) +print(gpCam.getStatus(constants.Hero3Status.Charging)) +print(gpCam.getStatus(constants.Hero3Status.PicturesTaken)) +print(gpCam.getStatus(constants.Hero3Status.VideoRemaining)) +print(gpCam.getStatus(constants.Hero3Status.VideosTaken)) diff --git a/goprocam/GoProCamera.py b/goprocam/GoProCamera.py index 876f4e8..41ff9df 100644 --- a/goprocam/GoProCamera.py +++ b/goprocam/GoProCamera.py @@ -649,13 +649,13 @@ def listMedia(self, format=False, media_array=False): for i in range(medialength): for folder in json_parse[i]['media']: for item in folder['fs']: - media.append([folder['d'],item['n'], item['s']]) + media.append([folder['d'],item['n'], item['s'], item['mod']]) else: raw_data = urllib.request.urlopen('http://' + self.ip_addr + ':8080/gp/gpMediaList').read().decode('utf-8') json_parse = json.loads(raw_data) for i in json_parse['media']: for i2 in i['fs']: - media.append([i['d'], i2['n'], i2['s']]) + media.append([i['d'], i2['n'], i2['s'], i2['mod']]) return media else: if "FS" in self.infoCamera(constants.Camera.Firmware): @@ -671,7 +671,7 @@ def listMedia(self, format=False, media_array=False): json_parse = json.loads(raw_data) medialength=len(json_parse) for i in range(medialength): - for folder in json_parse[i]['media']: + for folder in json_parse['media']: for item in folder['fs']: print(item['n']) except (HTTPError, URLError) as error: