Backend: Improve country estimate from folder name

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-08-14 15:36:48 +02:00
parent 7073dddadf
commit d43d3a22e0
4 changed files with 10 additions and 4 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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"))
}

View file

@ -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) {