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

Album filter support - needs work #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

HenrikHoyer
Copy link

❓ What

Added an Album_filter configuration option to download only a subset of all albums.

This is my first time using Go, and I therefore need assistance for improving/completing this PR.

I have jut used strings.HasPrefix() for the match, was is the preferred way for filtering?
I haven't made any tests for the code, is it needed?

Copy link
Owner

@tommyblue tommyblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HenrikHoyer thanks for the contribution. Overall it is correct, I just added some comments. However, I'd put the filter in the func (w *Worker) albums() function, so that you're filtering out the albums before adding them to the worker pipeline. What do you think?

Using the prefix is a good start, although a more powerful tool are the regular expressions. It can be challenging for the users to write them, but they can solve problems that are impossible to solve with just the prefix. In case you want to give it a try, take a look at Regexp.Match

@@ -115,6 +116,7 @@ func (w *Worker) saveImage(image albumImage, folder string) error {
return errors.New("unable to find valid image filename, skipping")
}
dest := fmt.Sprintf("%s/%s", folder, image.Name())
dest = strings.Replace(dest, "?", "_", -1)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not related to the current PR. It is, instead, related to #62
It's better to split the work, so that each one can have its own discussion

@@ -224,6 +231,13 @@ func (w *Worker) albumWorker(id int) {
log.Debugf("Quitting albumWorker %d", id)
return
}

filter := w.cfg.AlbumFilter
if len(filter) > 0 && !strings.HasPrefix(strings.ToLower(album.URLPath), strings.ToLower(filter)) { // Improve: use a real 'mathces' function instead of just HasPrefix
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since filter is a string, maybe using if string != "" is a bit more clear

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using lowercase here makes the strong assumption that the user wants a case-insensitive filter. Maybe this is the correct thing, maybe not. Using a regexp match can be more powerful here, although a little bit more expensive

@tommyblue
Copy link
Owner

Ah, I forgot to mention tests: they're definitely useful if you're not expert with go and/or regexp, I'd add a couple of them to ensure you're filtering out the correct strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants