Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for alternate Model 3 camera file name #11

Closed
Closed
Show file tree
Hide file tree
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
16 changes: 5 additions & 11 deletions TeslaCamViewer/TeslaCamViewer/TeslaCamDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace TeslaCamViewer
{
public class TeslaCamDate
{
private const string FileFormat = "yyyy-MM-dd_HH-mm";
private const string FileFormatNoSeconds = "yyyy-MM-dd_HH-mm";
private const string FileFormatWithSeconds = "yyyy-MM-dd_HH-mm-ss";
private const string DisplayFormat = "M/d/yyyy h:mm tt";

public string UTCDateString { get; private set; }
Expand All @@ -25,23 +26,16 @@ public DateTime UTCTimeStamp
{
get
{

DateTime dt;
if (DateTime.TryParseExact(UTCDateString, FileFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
{
return dt;
}
else
{
throw new Exception("Invalid date format: " + UTCDateString);
}
if (DateTime.TryParseExact(UTCDateString, FileFormatNoSeconds, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt;
if (DateTime.TryParseExact(UTCDateString, FileFormatWithSeconds, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) return dt;
throw new Exception("Invalid date format: " + UTCDateString);
}
}
public DateTime LocalTimeStamp
{
get
{

return UTCTimeStamp;
}
}
Expand Down
5 changes: 3 additions & 2 deletions TeslaCamViewer/TeslaCamViewer/TeslaCamFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum CameraType
FRONT,
RIGHT_REPEATER
}
private readonly string FileNameRegex = "([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2})-([a-z_]*).mp4";
private readonly string FileNameRegex = "([0-9]{4}-[0-9]{2}-[0-9]{2}_[0-9]{2}-[0-9]{2}(-[0-9]{2})?)-([a-z_]*).mp4";
public string FilePath { get; private set; }
public string FileName { get { return System.IO.Path.GetFileName(FilePath); } }
public TeslaCamDate Date { get; private set; }
Expand All @@ -33,7 +33,8 @@ public TeslaCamFile(string FilePath)
if (m.Count != 1)
throw new Exception("Invalid TeslaCamFile '" + FileName + "'");
this.Date = new TeslaCamDate(m[0].Groups[1].Value);
string cameraType = m[0].Groups[2].Value;
int cameraTypeIndex = m[0].Groups.Count - 1;
string cameraType = m[0].Groups[cameraTypeIndex].Value;
if (cameraType == "front")
CameraLocation = CameraType.FRONT;
else if (cameraType == "left_repeater")
Expand Down