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

play: Add prompt choice to importer #2360

Merged
merged 4 commits into from
Jan 7, 2017
Merged

Conversation

diomekes
Copy link

This is for #2008.

I hope my refactoring isn't way out of line.

@ghost
Copy link

ghost commented Dec 31, 2016

I fixed the appveyor issue. Can you rebase this on masterand push again?

@sampsyo
Copy link
Member

sampsyo commented Dec 31, 2016

This is a cool idea; thanks! Any chance you could add some documentation on the feature?

The refactoring also looks fine on first glance (I haven't done a full review yet). Anything in particular I should be looking for? (Or perhaps you can just give a brief overview of what needed changing?)

fix line number

add comments
@diomekes
Copy link
Author

Yes, I forgot about adding documentation, I'll do that.

I just defined separate methods/functions so that the CLI and event listener could access them. I did have to change the way the command is called for the importer prompt since the plugin originally would exit once the command was executed, but I needed it to return to beets. All my tests had it working fine.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

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

Hi! Here are a few scattered suggestions from a full code review.

"""Returns either the raw paths of items or a playlist of the items.
"""
raw = config['play']['raw'].get(bool)
if raw:
Copy link
Member

Choose a reason for hiding this comment

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

This can be shortened to:

if config['play']['raw']:


def _print_info(self, selection, command_str, open_args,
item_type='track'):
"""Prompts user whether to continue if playlist exceeds threshold.
Copy link
Member

Choose a reason for hiding this comment

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

I know this is minor, but docstrings should typically be written in the imperative voice—here, "Prompt" rather than "Prompts."

Copy link
Member

Choose a reason for hiding this comment

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

Also, this docstring should probably explain what the return value means. Here, if I understand correctly, it returns true if the operation should be aborted (i.e., it returns false if the operation should actually happen, which is a little counterintuitive).

open_args = paths
else:
open_args = [self._create_tmp_playlist(paths)]

self._log.debug(u'executing command: {} {!r}', command_str, open_args)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe these logging messages should go in the method that actually plays the music?

if warning_threshold and len(selection) > warning_threshold:
ui.print_(ui.colorize(
'text_warning',
u'You are about to queue {0} {1}.'.format(
len(selection), item_type)))

if ui.input_options((u'Continue', u'Abort')) == 'a':
return
return True
Copy link
Member

Choose a reason for hiding this comment

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

The method should explicitly return False at the end (when it doesn't return True).

@@ -155,3 +190,21 @@ def _create_tmp_playlist(self, paths_list):
m3u.write(item + b'\n')
m3u.close()
return m3u.name

def before_choose_candidate_listener(self, session, task):
Copy link
Member

Choose a reason for hiding this comment

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

Argh; I wish we had chosen a better name than before_choose_candidate. 😱 But that's hardly your fault.

adds a `plaY` option to the prompt, so pressing `y` will execute the configured
command and play the items currently being imported.

Once you exit your configured player, you will be returned to the import
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps more accurately, "once the configured command exists, …"

if not cancel:
play(command_str, paths, open_args)

def _create_command_str(self, args=None):
Copy link
Member

Choose a reason for hiding this comment

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

This can probably be called just _command_str.

"""
try:
if keep_open:
command = command_str.split()
Copy link
Member

Choose a reason for hiding this comment

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

I'd recommend using beets.util.shlex_split instead of str.split for more predictable command spitting behavior.

@diomekes
Copy link
Author

diomekes commented Jan 4, 2017

Thanks for the thorough review, I think I addressed all the issues and hopefully the warning_threshold configuration option handling is a little more sophisticated.

@sampsyo
Copy link
Member

sampsyo commented Jan 7, 2017

This looks great; thank you! I don't know why the 3.6 test failed the most recent time around, but I'm going to merge this now. To simplify things, I may remove that old, backwards-compatible misspelling…

@sampsyo sampsyo merged commit 8d61342 into beetbox:master Jan 7, 2017
sampsyo added a commit that referenced this pull request Jan 7, 2017
play: Add prompt choice to importer
sampsyo added a commit that referenced this pull request Jan 7, 2017
@diomekes diomekes deleted the importer-play branch January 7, 2017 22:37
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.

3 participants