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

Embed option #60

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ alternatives:
paths:
default: $album/$title
formats: aac mp3
embed: true
query: "onplayer:true"
removable: true
```

The first two options determine the location of the external files and
correspond to the global [`directory`][config-directory] and
[`paths`][config-paths] settings. The `format` option specifies the
formats we transcode the files to (more on that below). Finally, the
`query` option tells the plugin which files you want to put in the
external location. The value is a [query string][] as used for the
beets command line. In our case we use a flexible attribute to make the
selection transparent.
[`paths`][config-paths] settings. The `formats` option specifies the
formats we transcode the files to (more on that below). The `embed`
option specifies that album art should be embedded in the transcoded
files. The `query` option tells the plugin which files you want
to put in the external location. The value is a [query string][] as used
for the beets command line. In our case we use a flexible attribute to
make the selection transparent. Finally, the `removable` option tells
the plugin that that target directory is on a removable storage (details
see below).

Let’s add some files to our selection by setting the flexible attribute
from the `query` option. (Since we use boolean values for the
Expand Down Expand Up @@ -104,7 +108,7 @@ $ beet modify composer="Johann Sebastian Bach" artist:Bach
$ beet alt update myplayer
```

After going for a run you mitght realize that Bach is probably not the
After going for a run you might realize that Bach is probably not the
right thing to work out to. So you decide to put Beethoven on your
player.

Expand Down Expand Up @@ -247,6 +251,14 @@ following settings.

By default no transcoding is done.

* **`embed`** If set to `true`, album art is embedded in the external
files. Updates to cover images in the main collection are synced. No
embedding takes place if `embed` is set to `false` (except if the
transcoder embeds the album art).

This option is optional and defaults to the value of the `embed`
option of the convert plugin (default: `true`)

* **`removable`** If this is `true` (the default) and `directory` does
not exist, the `update` command will ask you to confirm the creation
of the external collection. (optional)
Expand Down
13 changes: 8 additions & 5 deletions beetsplug/alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def __init__(self, log, name, lib, config):
self.name = name
self.lib = lib
self.path_key = u'alt.{0}'.format(name)
self.convert_plugin = convert.ConvertPlugin()
self.parse_config(config)

def parse_config(self, config):
Expand All @@ -174,6 +175,10 @@ def parse_config(self, config):
self.query, _ = parse_query_string(query, Item)

self.removable = config.get(dict).get('removable', True)
self._embed = config.get(dict).get(
'embed',
self.convert_plugin.config["embed"].get(bool)
)

if 'directory' in config:
dir = config['directory'].as_str()
Expand All @@ -196,9 +201,9 @@ def item_change_actions(self, item, path, dest):
item_mtime_alt = os.path.getmtime(syspath(path))
if (item_mtime_alt < os.path.getmtime(syspath(item.path))):
actions.append(self.WRITE)
album = item.get_album()

if album:
album = item.get_album()
if self._embed and album:
if (album.artpath and
os.path.isfile(syspath(album.artpath)) and
(item_mtime_alt
Expand Down Expand Up @@ -334,9 +339,7 @@ class ExternalConvert(External):

def __init__(self, log, name, formats, lib, config):
super(ExternalConvert, self).__init__(log, name, lib, config)
convert_plugin = convert.ConvertPlugin()
self._encode = convert_plugin.encode
self._embed = convert_plugin.config['embed'].get(bool)
self._encode = self.convert_plugin.encode
formats = [f.lower() for f in formats]
self.formats = [convert.ALIASES.get(f, f) for f in formats]
self.convert_cmd, self.ext = convert.get_format(self.formats[0])
Expand Down