MCPcopy Create free account
hub / github.com/cloudreve/cloudreve / Extract

Method Extract

pkg/mediameta/geocoding.go:47–88  ·  view source on GitHub ↗
(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc)

Source from the content-addressed store, hash-verified

45}
46
47func (e *geocodingExtractor) Extract(ctx context.Context, ext string, source entitysource.EntitySource, opts ...optionFunc) ([]driver.MediaMeta, error) {
48 option := &option{}
49 for _, opt := range opts {
50 opt.apply(option)
51 }
52
53 // Find GPS info from extracted
54 var latStr, lngStr string
55 for _, meta := range option.extracted {
56 if meta.Key == GpsLat {
57 latStr = meta.Value
58 }
59 if meta.Key == GpsLng {
60 lngStr = meta.Value
61 }
62 }
63
64 if latStr == "" || lngStr == "" {
65 return nil, nil
66 }
67
68 lat, err := strconv.ParseFloat(latStr, 64)
69 if err != nil {
70 return nil, fmt.Errorf("geocoding: failed to parse latitude: %w", err)
71 }
72
73 lng, err := strconv.ParseFloat(lngStr, 64)
74 if err != nil {
75 return nil, fmt.Errorf("geocoding: failed to parse longitude: %w", err)
76 }
77
78 metas, err := e.getGeocoding(ctx, lat, lng, option.language)
79 if err != nil {
80 return nil, fmt.Errorf("geocoding: failed to get geocoding: %w", err)
81 }
82
83 for i, _ := range metas {
84 metas[i].Type = driver.MetaTypeGeocoding
85 }
86
87 return metas, nil
88}
89
90func (e *geocodingExtractor) getGeocoding(ctx context.Context, lat, lng float64, language string) ([]driver.MediaMeta, error) {
91 values := url.Values{}

Callers

nothing calls this directly

Calls 2

getGeocodingMethod · 0.95
applyMethod · 0.65

Tested by

no test coverage detected