Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions solarcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path
import subprocess
import json
import re
from datetime import datetime


Expand Down Expand Up @@ -73,6 +74,8 @@ def generateTargetFilePath(self, filename, downloadDir, extention=""):
fileExtention = Path(filename).suffix
filenameSplit = filename.split("/")
filenameDisk = f"{filenameSplit[3]}_{filenameSplit[5][:8]}".replace(".", "-")
# the segments come from the camera; keep anything else out of the path
filenameDisk = re.sub(r"[^A-Za-z0-9_-]", "_", filenameDisk)
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Resolved
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Resolved
targetPathClean = f"{downloadDir}/{filenameDisk}"

if extention != "":
Expand All @@ -81,16 +84,27 @@ def generateTargetFilePath(self, filename, downloadDir, extention=""):
return f"{targetPathClean}{fileExtention}"

def convertFile(self, sourceFile, targetFile):
# an argv list, not a shell string: the paths carry camera-supplied names
if (
subprocess.run(
f"ffmpeg -framerate 15 -i {sourceFile} -b:v 1M -c:v libvpx-vp9 -c:a libopus {targetFile}",
[
"ffmpeg",
"-framerate", "15",
"-i", sourceFile,
"-b:v", "1M",
"-c:v", "libvpx-vp9",
"-c:a", "libopus",
targetFile,
],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=True,
).returncode
!= 0
):
self.logger.debug(f"Error converting video. Check {sourceFile}")
# a partial output would be taken as converted and stop the retry
Path(targetFile).unlink(missing_ok=True)
return
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Resolved

self.logger.debug(f"File successfully converted: {targetFile}")
Path(sourceFile).unlink()
Expand All @@ -110,10 +124,6 @@ def save_files(self, download_dir, files, blacklist=None, target_filetype=None):
file["FileName"], download_dir, extention=f"{target_filetype}"
)

if Path(f"{target_file_path}").is_file():
self.logger.debug(f"File already exists: {target_file_path}")
continue

if (
target_file_path_convert
and Path(f"{target_file_path_convert}").is_file()
Expand All @@ -123,6 +133,12 @@ def save_files(self, download_dir, files, blacklist=None, target_filetype=None):
)
continue

# with conversion on, a source left by a failed conversion is retried
downloaded = Path(f"{target_file_path}").is_file()
if downloaded and not target_file_path_convert:
self.logger.debug(f"File already exists: {target_file_path}")
continue

if blacklist:
if target_file_path in blacklist:
self.logger.debug(f"File is on the blacklist: {target_file_path}")
Expand All @@ -133,11 +149,12 @@ def save_files(self, download_dir, files, blacklist=None, target_filetype=None):
)
continue

self.logger.debug(f"Downloading {target_file_path}...")
self.cam.download_file(
file["BeginTime"], file["EndTime"], file["FileName"], target_file_path
)
self.logger.debug(f"Finished downloading {target_file_path}...")
if not downloaded:
self.logger.debug(f"Downloading {target_file_path}...")
self.cam.download_file(
file["BeginTime"], file["EndTime"], file["FileName"], target_file_path
)
self.logger.debug(f"Finished downloading {target_file_path}...")

if target_file_path_convert:
self.logger.debug(f"Converting {target_file_path_convert}...")
Expand Down
Loading