-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracting property cleanup into a separate cmd that runs on sync
- Loading branch information
1 parent
c5a661f
commit b6e476f
Showing
6 changed files
with
73 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/boggydigital/kevlar" | ||
"github.com/boggydigital/nod" | ||
"github.com/boggydigital/yet/data" | ||
"golang.org/x/exp/slices" | ||
"net/url" | ||
) | ||
|
||
var preserveVideoProperties = []string{ | ||
data.VideoTitleProperty, // required for history | ||
data.VideoOwnerChannelNameProperty, // required for cleanup (checking empty videos directories) | ||
data.VideoEndedDateProperty, // required for cleanup | ||
data.VideoEndedReasonProperty, // required for history | ||
data.VideoFavoriteProperty, // required for cleanup | ||
data.VideoDownloadCompletedProperty, // required for cleanup | ||
data.VideoDownloadCleanedUpProperty, // required for cleanup | ||
} | ||
|
||
func CleanupPropertiesHandler(u *url.URL) error { | ||
return CleanupProperties(nil) | ||
} | ||
|
||
func CleanupProperties(rdx kevlar.WriteableRedux) error { | ||
|
||
cpa := nod.NewProgress("cleaning up video properties...") | ||
defer cpa.End() | ||
|
||
var err error | ||
rdx, err = validateWritableRedux(rdx, data.VideoProperties()...) | ||
if err != nil { | ||
return cpa.EndWithError(err) | ||
} | ||
|
||
endedVideos := rdx.Keys(data.VideoEndedDateProperty) | ||
|
||
cpa.TotalInt(len(endedVideos)) | ||
|
||
for _, videoId := range endedVideos { | ||
|
||
for _, vp := range data.VideoProperties() { | ||
if slices.Contains(preserveVideoProperties, vp) { | ||
continue | ||
} | ||
|
||
if err := rdx.CutKeys(vp, videoId); err != nil { | ||
return cpa.EndWithError(err) | ||
} | ||
} | ||
|
||
cpa.Increment() | ||
} | ||
|
||
cpa.EndWithResult("done") | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters