mirror of
https://github.com/photoprism/photoprism.git
synced 2025-12-12 08:44:04 +01:00
Meta: Add const, func, and struct comments for easier troubleshooting
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/rnd"
|
"github.com/photoprism/photoprism/pkg/rnd"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Extended image type constants extracted from vendor-specific metadata.
|
||||||
const (
|
const (
|
||||||
ImageTypeHDR = 3 // see https://exiftool.org/TagNames/Apple.html
|
ImageTypeHDR = 3 // see https://exiftool.org/TagNames/Apple.html
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package meta
|
package meta
|
||||||
|
|
||||||
|
// Docs lists external references for metadata standards PhotoPrism relies on.
|
||||||
var Docs = [][]string{
|
var Docs = [][]string{
|
||||||
{"Exiftool", "https://exiftool.org/TagNames/EXIF.html"},
|
{"Exiftool", "https://exiftool.org/TagNames/EXIF.html"},
|
||||||
{"Exiftool XMP", "https://exiftool.org/TagNames/XMP.html"},
|
{"Exiftool XMP", "https://exiftool.org/TagNames/XMP.html"},
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/fs"
|
"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) {
|
func RawExif(fileName string, fileFormat fs.Type, bruteForce bool) (rawExif []byte, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
|
|||||||
@@ -10,14 +10,18 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/clean"
|
"github.com/photoprism/photoprism/pkg/clean"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Latitude/Longitude bounds used when clamping map coordinates.
|
||||||
const (
|
const (
|
||||||
LatMax = 90
|
LatMax = 90
|
||||||
LngMax = 180
|
LngMax = 180
|
||||||
)
|
)
|
||||||
|
|
||||||
var GpsCoordsRegexp = regexp.MustCompile("[0-9\\.]+")
|
// Regular expressions used to extract GPS coordinate components from EXIF strings.
|
||||||
var GpsRefRegexp = regexp.MustCompile("[NSEW]+")
|
var (
|
||||||
var GpsFloatRegexp = regexp.MustCompile("[+\\-]?(?:(?:0|[1-9]\\d*)(?:\\.\\d*)?|\\.\\d+)")
|
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.
|
// GpsToLatLng returns the GPS latitude and longitude as float point number.
|
||||||
func GpsToLatLng(s string) (lat, lng float64) {
|
func GpsToLatLng(s string) (lat, lng float64) {
|
||||||
|
|||||||
@@ -21,8 +21,11 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/txt"
|
"github.com/photoprism/photoprism/pkg/txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MimeVideoMp4 = "video/mp4"
|
// Common MIME types used to detect video contexts in ExifTool sidecars.
|
||||||
const MimeQuicktime = "video/quicktime"
|
const (
|
||||||
|
MimeVideoMp4 = "video/mp4"
|
||||||
|
MimeQuicktime = "video/quicktime"
|
||||||
|
)
|
||||||
|
|
||||||
// Exiftool parses JSON sidecar data as created by Exiftool.
|
// Exiftool parses JSON sidecar data as created by Exiftool.
|
||||||
func (data *Data) Exiftool(jsonData []byte, originalName string) (err error) {
|
func (data *Data) Exiftool(jsonData []byte, originalName string) (err error) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/time/tz"
|
"github.com/photoprism/photoprism/pkg/time/tz"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GPhoto represents the photo-level fields exported by Google Photos JSON sidecars.
|
||||||
type GPhoto struct {
|
type GPhoto struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
@@ -19,18 +20,22 @@ type GPhoto struct {
|
|||||||
UpdatedAt GTime `json:"modificationTime"`
|
UpdatedAt GTime `json:"modificationTime"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetTitle returns the sanitized Google Photos title.
|
||||||
func (m GPhoto) GetTitle() string {
|
func (m GPhoto) GetTitle() string {
|
||||||
return SanitizeTitle(m.Title)
|
return SanitizeTitle(m.Title)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetCaption returns the sanitized Google Photos description.
|
||||||
func (m GPhoto) GetCaption() string {
|
func (m GPhoto) GetCaption() string {
|
||||||
return SanitizeCaption(m.Description)
|
return SanitizeCaption(m.Description)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GMeta wraps album metadata embedded in Google Photos sidecars.
|
||||||
type GMeta struct {
|
type GMeta struct {
|
||||||
Album GAlbum `json:"albumData"`
|
Album GAlbum `json:"albumData"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GAlbum contains album-level information from Google Photos exports.
|
||||||
type GAlbum struct {
|
type GAlbum struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
@@ -40,29 +45,35 @@ type GAlbum struct {
|
|||||||
Geo GGeo `json:"geoData"`
|
Geo GGeo `json:"geoData"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exists reports whether the album entry has meaningful data.
|
||||||
func (m GAlbum) Exists() bool {
|
func (m GAlbum) Exists() bool {
|
||||||
return m.Title != ""
|
return m.Title != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GGeo holds geolocation data provided by Google Photos.
|
||||||
type GGeo struct {
|
type GGeo struct {
|
||||||
Lat float64 `json:"latitude"`
|
Lat float64 `json:"latitude"`
|
||||||
Lng float64 `json:"longitude"`
|
Lng float64 `json:"longitude"`
|
||||||
Altitude float64 `json:"altitude"`
|
Altitude float64 `json:"altitude"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exists reports whether the geolocation entry has usable coordinates.
|
||||||
func (m GGeo) Exists() bool {
|
func (m GGeo) Exists() bool {
|
||||||
return m.Lat != 0.0 && m.Lng != 0.0
|
return m.Lat != 0.0 && m.Lng != 0.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GTime stores Unix timestamps used in Google Photos metadata.
|
||||||
type GTime struct {
|
type GTime struct {
|
||||||
Unix int64 `json:"timestamp,string"`
|
Unix int64 `json:"timestamp,string"`
|
||||||
Formatted string `json:"formatted"`
|
Formatted string `json:"formatted"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Exists reports whether the timestamp is set.
|
||||||
func (m GTime) Exists() bool {
|
func (m GTime) Exists() bool {
|
||||||
return m.Unix > 0
|
return m.Unix > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Time returns the timestamp as a UTC time.Time.
|
||||||
func (m GTime) Time() time.Time {
|
func (m GTime) Time() time.Time {
|
||||||
return time.Unix(m.Unix, 0).UTC()
|
return time.Unix(m.Unix, 0).UTC()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/txt"
|
"github.com/photoprism/photoprism/pkg/txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Built-in keyword slugs inferred from metadata.
|
||||||
const (
|
const (
|
||||||
KeywordFlash = "flash"
|
KeywordFlash = "flash"
|
||||||
KeywordHdr = "hdr"
|
KeywordHdr = "hdr"
|
||||||
@@ -24,6 +25,7 @@ func (w Keywords) String() string {
|
|||||||
return strings.Join(w, ", ")
|
return strings.Join(w, ", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AutoKeywords lists keywords we automatically infer from descriptions or EXIF flags.
|
||||||
var AutoKeywords = []string{KeywordHdr, KeywordBurst, KeywordPanorama, KeywordEquirectangular}
|
var AutoKeywords = []string{KeywordHdr, KeywordBurst, KeywordPanorama, KeywordEquirectangular}
|
||||||
|
|
||||||
// AddKeywords appends keywords.
|
// AddKeywords appends keywords.
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/txt"
|
"github.com/photoprism/photoprism/pkg/txt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// UnwantedStrings lists boilerplate captions we strip during import.
|
||||||
var UnwantedStrings = map[string]bool{
|
var UnwantedStrings = map[string]bool{
|
||||||
"Created by Imlib": true, // Apps
|
"Created by Imlib": true, // Apps
|
||||||
"iClarified": true,
|
"iClarified": true,
|
||||||
@@ -60,6 +61,7 @@ var UnwantedStrings = map[string]bool{
|
|||||||
"Digital Camera": true,
|
"Digital Camera": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LowerCaseRegexp matches lower-case tokens in generated filenames.
|
||||||
var LowerCaseRegexp = regexp.MustCompile("[a-z\\d_\\-]+")
|
var LowerCaseRegexp = regexp.MustCompile("[a-z\\d_\\-]+")
|
||||||
|
|
||||||
// SanitizeUnicode returns the string as valid Unicode with whitespace trimmed.
|
// SanitizeUnicode returns the string as valid Unicode with whitespace trimmed.
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ import (
|
|||||||
"github.com/photoprism/photoprism/pkg/media/video"
|
"github.com/photoprism/photoprism/pkg/media/video"
|
||||||
)
|
)
|
||||||
|
|
||||||
const CodecUnknown = ""
|
// Common codec labels encountered in metadata.
|
||||||
const CodecJpeg = "jpeg"
|
const (
|
||||||
const CodecHeic = "heic"
|
CodecUnknown = ""
|
||||||
const CodecXMP = "xmp"
|
CodecJpeg = "jpeg"
|
||||||
|
CodecHeic = "heic"
|
||||||
|
CodecXMP = "xmp"
|
||||||
|
)
|
||||||
|
|
||||||
// CodecAvc returns true if the video codec is AVC.
|
// CodecAvc returns true if the video codec is AVC.
|
||||||
func (data Data) CodecAvc() bool {
|
func (data Data) CodecAvc() bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user