Meta: Add const, func, and struct comments for easier troubleshooting

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer
2025-09-30 22:00:30 +02:00
parent ece066fb47
commit bbf6580512
9 changed files with 38 additions and 9 deletions

View File

@@ -9,6 +9,7 @@ import (
"github.com/photoprism/photoprism/pkg/rnd"
)
// Extended image type constants extracted from vendor-specific metadata.
const (
ImageTypeHDR = 3 // see https://exiftool.org/TagNames/Apple.html
)

View File

@@ -1,5 +1,6 @@
package meta
// Docs lists external references for metadata standards PhotoPrism relies on.
var Docs = [][]string{
{"Exiftool", "https://exiftool.org/TagNames/EXIF.html"},
{"Exiftool XMP", "https://exiftool.org/TagNames/XMP.html"},

View File

@@ -16,6 +16,8 @@ import (
"github.com/photoprism/photoprism/pkg/fs"
)
// RawExif extracts the raw EXIF block from the given media file, optionally falling back to a
// brute-force search when native parsers fail.
func RawExif(fileName string, fileFormat fs.Type, bruteForce bool) (rawExif []byte, err error) {
defer func() {
if e := recover(); e != nil {

View File

@@ -10,14 +10,18 @@ import (
"github.com/photoprism/photoprism/pkg/clean"
)
// Latitude/Longitude bounds used when clamping map coordinates.
const (
LatMax = 90
LngMax = 180
)
var GpsCoordsRegexp = regexp.MustCompile("[0-9\\.]+")
var GpsRefRegexp = regexp.MustCompile("[NSEW]+")
var GpsFloatRegexp = regexp.MustCompile("[+\\-]?(?:(?:0|[1-9]\\d*)(?:\\.\\d*)?|\\.\\d+)")
// Regular expressions used to extract GPS coordinate components from EXIF strings.
var (
GpsCoordsRegexp = regexp.MustCompile("[0-9\\.]+")
GpsRefRegexp = regexp.MustCompile("[NSEW]+")
GpsFloatRegexp = regexp.MustCompile("[+\\-]?(?:(?:0|[1-9]\\d*)(?:\\.\\d*)?|\\.\\d+)")
)
// GpsToLatLng returns the GPS latitude and longitude as float point number.
func GpsToLatLng(s string) (lat, lng float64) {

View File

@@ -21,8 +21,11 @@ import (
"github.com/photoprism/photoprism/pkg/txt"
)
const MimeVideoMp4 = "video/mp4"
const MimeQuicktime = "video/quicktime"
// Common MIME types used to detect video contexts in ExifTool sidecars.
const (
MimeVideoMp4 = "video/mp4"
MimeQuicktime = "video/quicktime"
)
// Exiftool parses JSON sidecar data as created by Exiftool.
func (data *Data) Exiftool(jsonData []byte, originalName string) (err error) {

View File

@@ -9,6 +9,7 @@ import (
"github.com/photoprism/photoprism/pkg/time/tz"
)
// GPhoto represents the photo-level fields exported by Google Photos JSON sidecars.
type GPhoto struct {
Title string `json:"title"`
Description string `json:"description"`
@@ -19,18 +20,22 @@ type GPhoto struct {
UpdatedAt GTime `json:"modificationTime"`
}
// GetTitle returns the sanitized Google Photos title.
func (m GPhoto) GetTitle() string {
return SanitizeTitle(m.Title)
}
// GetCaption returns the sanitized Google Photos description.
func (m GPhoto) GetCaption() string {
return SanitizeCaption(m.Description)
}
// GMeta wraps album metadata embedded in Google Photos sidecars.
type GMeta struct {
Album GAlbum `json:"albumData"`
}
// GAlbum contains album-level information from Google Photos exports.
type GAlbum struct {
Title string `json:"title"`
Description string `json:"description"`
@@ -40,29 +45,35 @@ type GAlbum struct {
Geo GGeo `json:"geoData"`
}
// Exists reports whether the album entry has meaningful data.
func (m GAlbum) Exists() bool {
return m.Title != ""
}
// GGeo holds geolocation data provided by Google Photos.
type GGeo struct {
Lat float64 `json:"latitude"`
Lng float64 `json:"longitude"`
Altitude float64 `json:"altitude"`
}
// Exists reports whether the geolocation entry has usable coordinates.
func (m GGeo) Exists() bool {
return m.Lat != 0.0 && m.Lng != 0.0
}
// GTime stores Unix timestamps used in Google Photos metadata.
type GTime struct {
Unix int64 `json:"timestamp,string"`
Formatted string `json:"formatted"`
}
// Exists reports whether the timestamp is set.
func (m GTime) Exists() bool {
return m.Unix > 0
}
// Time returns the timestamp as a UTC time.Time.
func (m GTime) Time() time.Time {
return time.Unix(m.Unix, 0).UTC()
}

View File

@@ -8,6 +8,7 @@ import (
"github.com/photoprism/photoprism/pkg/txt"
)
// Built-in keyword slugs inferred from metadata.
const (
KeywordFlash = "flash"
KeywordHdr = "hdr"
@@ -24,6 +25,7 @@ func (w Keywords) String() string {
return strings.Join(w, ", ")
}
// AutoKeywords lists keywords we automatically infer from descriptions or EXIF flags.
var AutoKeywords = []string{KeywordHdr, KeywordBurst, KeywordPanorama, KeywordEquirectangular}
// AddKeywords appends keywords.

View File

@@ -10,6 +10,7 @@ import (
"github.com/photoprism/photoprism/pkg/txt"
)
// UnwantedStrings lists boilerplate captions we strip during import.
var UnwantedStrings = map[string]bool{
"Created by Imlib": true, // Apps
"iClarified": true,
@@ -60,6 +61,7 @@ var UnwantedStrings = map[string]bool{
"Digital Camera": true,
}
// LowerCaseRegexp matches lower-case tokens in generated filenames.
var LowerCaseRegexp = regexp.MustCompile("[a-z\\d_\\-]+")
// SanitizeUnicode returns the string as valid Unicode with whitespace trimmed.

View File

@@ -4,10 +4,13 @@ import (
"github.com/photoprism/photoprism/pkg/media/video"
)
const CodecUnknown = ""
const CodecJpeg = "jpeg"
const CodecHeic = "heic"
const CodecXMP = "xmp"
// Common codec labels encountered in metadata.
const (
CodecUnknown = ""
CodecJpeg = "jpeg"
CodecHeic = "heic"
CodecXMP = "xmp"
)
// CodecAvc returns true if the video codec is AVC.
func (data Data) CodecAvc() bool {