MCPcopy
hub / github.com/beetbox/beets / _play_command

Method _play_command

beetsplug/play.py:112–173  ·  view source on GitHub ↗

The CLI command function for `beet play`. Create a list of paths from query, determine if tracks or albums are to be played.

(self, lib, opts, args)

Source from the content-addressed store, hash-verified

110 return [play_command]
111
112 def _play_command(self, lib, opts, args):
113 """The CLI command function for `beet play`. Create a list of paths
114 from query, determine if tracks or albums are to be played.
115 """
116 use_folders = config["play"]["use_folders"].get(bool)
117 relative_to = config["play"]["relative_to"].get()
118 if relative_to:
119 relative_to = util.normpath(relative_to)
120 # Perform search by album and add folders rather than tracks to
121 # playlist.
122 if opts.album:
123 selection = lib.albums(args)
124 paths = []
125
126 sort = lib.get_default_album_sort()
127 for album in selection:
128 if use_folders:
129 paths.append(album.item_dir())
130 else:
131 paths.extend(item.path for item in sort.sort(album.items()))
132 item_type = "album"
133
134 # Perform item query and add tracks to playlist.
135 else:
136 selection = lib.items(args)
137 paths = [item.path for item in selection]
138 item_type = "track"
139
140 if relative_to:
141 paths = [relpath(path, relative_to) for path in paths]
142
143 if not selection:
144 ui.print_(colorize("text_warning", f"No {item_type} to play."))
145 return
146
147 if opts.randomize:
148 random.shuffle(paths)
149
150 open_args = self._playlist_or_paths(paths)
151 open_args_str = [
152 p.decode("utf-8") for p in self._playlist_or_paths(paths)
153 ]
154 command_str = self._command_str(opts.args)
155
156 if PLS_MARKER in command_str:
157 if not config["play"]["raw"]:
158 command_str = command_str.replace(
159 PLS_MARKER, "".join(open_args_str)
160 )
161 self._log.debug(
162 "command altered by PLS_MARKER to: {}", command_str
163 )
164 open_args = []
165 else:
166 command_str = command_str.replace(PLS_MARKER, " ")
167
168 # Check if the selection exceeds configured threshold. If True,
169 # cancel, otherwise proceed with play command.

Callers

nothing calls this directly

Calls 14

_playlist_or_pathsMethod · 0.95
_command_strMethod · 0.95
_exceeds_thresholdMethod · 0.95
colorizeFunction · 0.90
playFunction · 0.85
item_dirMethod · 0.80
replaceMethod · 0.80
joinMethod · 0.80
getMethod · 0.45
albumsMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected