Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set bar to completed if file exists #97

Merged
merged 8 commits into from
Feb 7, 2023
10 changes: 9 additions & 1 deletion pkg/dji/dji.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange
}

wg.Add(1)
bar := utils.GetNewBar(progressBar, int64(info.Size()), de.Name(), utils.IoTX)
bar := utils.GetNewBar(progressBar, info.Size(), de.Name(), utils.IoTX)

dayFolder := utils.GetOrder(sortOptions, locationService, osPathname, out, mediaDate, cameraName)
switch ftype.Type {
Expand All @@ -166,6 +166,8 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange
defer wg.Done()
err = utils.CopyFile(osPathname, filepath.Join(dayFolder, "photos", filename), bufferSize, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -184,6 +186,8 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange
defer wg.Done()
err = utils.CopyFile(osPathname, filepath.Join(dayFolder, "videos", filename), bufferSize, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -208,6 +212,8 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange
defer wg.Done()
err = utils.CopyFile(osPathname, filepath.Join(dayFolder, "videos", extraPath, filename), bufferSize, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -225,6 +231,8 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange
defer wg.Done()
err = utils.CopyFile(osPathname, filepath.Join(dayFolder, "photos/raw", filename), bufferSize, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down
19 changes: 14 additions & 5 deletions pkg/gopro/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
switch fileTypeMatch.Type {
case Video, ChapteredVideo:

go func(in, folder, origFilename, unsorted string, lrvSize int, bar *mpb.Bar, result utils.Result) {
go func(in, folder, origFilename, unsorted string, origSize int64, lrvSize int, bar *mpb.Bar, result utils.Result) {
defer wg.Done()
x := origFilename
filename := origFilename
Expand All @@ -233,6 +233,8 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
fmt.Sprintf("http://%s:8080/videos/DCIM/%s/%s", in, folder, origFilename),
bar)
if err != nil {
bar.EwmaSetCurrent(origSize, 1*time.Millisecond)
bar.EwmaIncrInt64(origSize, 1*time.Millisecond)
inlineCounter.SetFailure(err, origFilename)
return
}
Expand Down Expand Up @@ -286,6 +288,8 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
fmt.Sprintf("http://%s:8080/videos/DCIM/%s/%s", in, folder, proxyVideoName),
proxyVideoBar)
if err != nil {
proxyVideoBar.EwmaSetCurrent(int64(lrvSize), 1*time.Millisecond)
proxyVideoBar.EwmaIncrInt64(int64(lrvSize), 1*time.Millisecond)
inlineCounter.SetFailure(err, origFilename)
return
}
Expand All @@ -301,7 +305,7 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
}
inlineCounter.SetSuccess()
}
}(in, folder.D, goprofile.N, unsorted, goprofile.Glrv, bar, result)
}(in, folder.D, goprofile.N, unsorted, goprofile.S, goprofile.Glrv, bar, result)

case Photo:
type photo struct {
Expand Down Expand Up @@ -335,6 +339,7 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
Folder: folder.D,
IsRaw: true,
Bar: rawPhotoBar,
Size: rawPhotoTotal,
})
}

Expand All @@ -348,6 +353,8 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
nowPhoto.Bar,
)
if err != nil {
nowPhoto.Bar.EwmaSetCurrent(int64(nowPhoto.Size), 1*time.Millisecond)
nowPhoto.Bar.EwmaIncrInt64(int64(nowPhoto.Size), 1*time.Millisecond)
inlineCounter.SetFailure(err, nowPhoto.Name)
} else {
inlineCounter.SetSuccess()
Expand Down Expand Up @@ -387,9 +394,9 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
if err != nil {
log.Fatal(err.Error())
}
multiShotBar := utils.GetNewBar(progressBar, int64(gpFileInfo.S), filename, utils.IoTX)
multiShotBar := utils.GetNewBar(progressBar, gpFileInfo.S, filename, utils.IoTX)

go func(in, folder, origFilename, unsorted string, result utils.Result) {
go func(in, folder, origFilename, unsorted string, origSize int64, result utils.Result) {
defer wg.Done()

err := utils.DownloadFile(
Expand All @@ -398,6 +405,8 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
multiShotBar,
)
if err != nil {
bar.EwmaSetCurrent(origSize, 1*time.Millisecond)
bar.EwmaIncrInt64(origSize, 1*time.Millisecond)
inlineCounter.SetFailure(err, origFilename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -414,7 +423,7 @@ func ImportConnect(in, out string, sortOptions utils.SortOptions) (*utils.Result
return
}
}
}(in, folder.D, filename, unsorted, result)
}(in, folder.D, filename, unsorted, gpFileInfo.S, result)
}

default:
Expand Down
24 changes: 22 additions & 2 deletions pkg/gopro/gopro.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func importFromGoProV2(root string, output string, sortoptions utils.SortOptions
dayFolder := utils.GetOrder(sortoptions, locationService, osPathname, output, mediaDate, cameraName)

wg.Add(1)
bar := utils.GetNewBar(progressBar, int64(info.Size()), de.Name(), utils.IoTX)
bar := utils.GetNewBar(progressBar, info.Size(), de.Name(), utils.IoTX)

switch ftype.Type {
case Video:
Expand All @@ -261,6 +261,8 @@ func importFromGoProV2(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down Expand Up @@ -296,6 +298,8 @@ func importFromGoProV2(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -312,6 +316,8 @@ func importFromGoProV2(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -324,6 +330,8 @@ func importFromGoProV2(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down Expand Up @@ -407,7 +415,7 @@ func importFromGoProV1(root string, output string, sortoptions utils.SortOptions
}

wg.Add(1)
bar := utils.GetNewBar(progressBar, int64(info.Size()), de.Name(), utils.IoTX)
bar := utils.GetNewBar(progressBar, info.Size(), de.Name(), utils.IoTX)

dayFolder := utils.GetOrder(sortoptions, locationService, osPathname, output, mediaDate, cameraName)

Expand Down Expand Up @@ -439,6 +447,8 @@ func importFromGoProV1(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down Expand Up @@ -486,6 +496,8 @@ func importFromGoProV1(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down Expand Up @@ -515,6 +527,8 @@ func importFromGoProV1(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -530,6 +544,8 @@ func importFromGoProV1(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -542,6 +558,8 @@ func importFromGoProV1(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand All @@ -554,6 +572,8 @@ func importFromGoProV1(root string, output string, sortoptions utils.SortOptions
defer wg.Done()
err := parse(folder, filename, osPathname, sortoptions, result, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down
6 changes: 5 additions & 1 deletion pkg/insta360/insta360.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange
}

wg.Add(1)
bar := utils.GetNewBar(progressBar, int64(info.Size()), de.Name(), utils.IoTX)
bar := utils.GetNewBar(progressBar, info.Size(), de.Name(), utils.IoTX)
dayFolder := utils.GetOrder(sortOptions, nil, osPathname, out, mediaDate, cameraName)

x := de.Name()
Expand All @@ -168,6 +168,8 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange

err = utils.CopyFile(osPathname, filepath.Join(dayFolder, "photos", id, x), bufferSize, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down Expand Up @@ -204,6 +206,8 @@ func Import(in, out, dateFormat string, bufferSize int, prefix string, dateRange

err = utils.CopyFile(osPathname, filepath.Join(dayFolder, slug, id, x), bufferSize, bar)
if err != nil {
bar.EwmaSetCurrent(info.Size(), 1*time.Millisecond)
bar.EwmaIncrInt64(info.Size(), 1*time.Millisecond)
inlineCounter.SetFailure(err, filename)
} else {
inlineCounter.SetSuccess()
Expand Down
10 changes: 9 additions & 1 deletion pkg/utils/reversegeo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"strings"

"github.com/codingsince1985/geo-golang"
"github.com/codingsince1985/geo-golang/openstreetmap"
Expand All @@ -14,6 +15,8 @@ type Location struct {
}

func formatFromConfig() int {
key := "location.format"
viper.SetDefault(key, 1)
return viper.GetInt("location.format")
}

Expand All @@ -33,6 +36,11 @@ type locationFormat interface {
format(*geo.Address) string
}

func cleanup(input string) string {
repl := strings.NewReplacer("/", "_", ":", "_", "\\", "_", ".", "_")
return repl.Replace(strings.TrimSpace(input))
}

type format1 struct{}

func (format1) format(address *geo.Address) string {
Expand All @@ -49,7 +57,7 @@ func (format2) format(address *geo.Address) string {
}

func getPrettyAddress(format locationFormat, address *geo.Address) string {
return format.format(address)
return cleanup(format.format(address))
}

func ReverseLocation(location Location) (string, error) {
Expand Down
47 changes: 47 additions & 0 deletions pkg/utils/reversegeo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package utils

import (
"fmt"
"testing"

"github.com/codingsince1985/geo-golang/openstreetmap"
"github.com/stretchr/testify/require"
)

type pair struct {
Address Location
Result []string
}

func TestPrettyAddress(t *testing.T) {
expected := []pair{
{
Address: Location{
Latitude: -39.6375091,
Longitude: 175.2222849,
},
Result: []string{"Manawatū-Whanganui New Zealand _ Aotearoa", "New Zealand _ Aotearoa"},
},
{
Address: Location{
Latitude: 52.547567,
Longitude: 13.385176,
},
Result: []string{"Berlin Deutschland", "Deutschland"},
},
}

for valueIndex, value := range expected {
t.Run(fmt.Sprintf("Pair %d", valueIndex), func(t *testing.T) {
service := openstreetmap.Geocoder()
address, err := service.ReverseGeocode(value.Address.Latitude, value.Address.Longitude)
require.NoError(t, err)

resp := getPrettyAddress(format1{}, address)
require.Equal(t, value.Result[0], resp)

resp = getPrettyAddress(format2{}, address)
require.Equal(t, value.Result[1], resp)
})
}
}