Backend: Improve country estimate from folder name
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
7073dddadf
commit
d43d3a22e0
4 changed files with 10 additions and 4 deletions
|
@ -25,8 +25,8 @@ func (m *Photo) EstimateCountry() {
|
|||
countryCode = code
|
||||
}
|
||||
|
||||
if countryCode == unknown && !fs.IsGenerated(m.PhotoName) {
|
||||
if code := txt.CountryCode(m.PhotoName); code != unknown {
|
||||
if countryCode == unknown {
|
||||
if code := txt.CountryCode(m.PhotoName); code != unknown && !fs.IsGenerated(m.PhotoName) {
|
||||
countryCode = code
|
||||
} else if code := txt.CountryCode(m.PhotoPath); code != unknown {
|
||||
countryCode = code
|
||||
|
|
|
@ -21,8 +21,8 @@ func TestPhoto_EstimateCountry(t *testing.T) {
|
|||
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
||||
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
||||
m.EstimateCountry()
|
||||
assert.Equal(t, UnknownCountry.ID, m.CountryCode())
|
||||
assert.Equal(t, UnknownCountry.CountryName, m.CountryName())
|
||||
assert.Equal(t, "de", m.CountryCode())
|
||||
assert.Equal(t, "Germany", m.CountryName())
|
||||
})
|
||||
|
||||
t.Run("de", func(t *testing.T) {
|
||||
|
|
|
@ -122,4 +122,5 @@ func TestIsGenerated(t *testing.T) {
|
|||
assert.True(t, IsGenerated("2013-06-06_DMC-LX5_P1080235.JPG"))
|
||||
assert.False(t, IsGenerated("The quick brown fox jumps over the lazy dog"))
|
||||
assert.False(t, IsGenerated("QUICK BROWN FOX"))
|
||||
assert.True(t, IsGenerated("_MG_9831-112.jpg"))
|
||||
}
|
||||
|
|
|
@ -366,6 +366,11 @@ func TestCountryCode(t *testing.T) {
|
|||
result := CountryCode("zz")
|
||||
assert.Equal(t, "zz", result)
|
||||
})
|
||||
|
||||
t.Run("2018/Oktober 2018/1.-7. Oktober 2018 Berlin/_MG_9831-112.jpg", func(t *testing.T) {
|
||||
result := CountryCode("2018/Oktober 2018/1.-7. Oktober 2018 Berlin/_MG_9831-112.jpg")
|
||||
assert.Equal(t, "de", result)
|
||||
})
|
||||
}
|
||||
|
||||
func TestYear(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue