From 5b0b3eee45c238c8a33f4e2a6cb6826208019738 Mon Sep 17 00:00:00 2001 From: robotanarchy Date: Sat, 13 Sep 2014 17:11:00 +0200 Subject: [PATCH 1/3] importfeeds: add new 'echo' type that writes to stdout --- beetsplug/importfeeds.py | 21 ++++++++++++++++----- docs/plugins/importfeeds.rst | 3 ++- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/beetsplug/importfeeds.py b/beetsplug/importfeeds.py index cf367fb5b..6c454e104 100644 --- a/beetsplug/importfeeds.py +++ b/beetsplug/importfeeds.py @@ -13,18 +13,20 @@ # included in all copies or substantial portions of the Software. """Write paths of imported files in various formats to ease later import in a -music player. +music player. Also allow printing the new file locations to stdout in case +one wants to manually add music to a player by its path. """ import datetime import os import re +import logging from beets.plugins import BeetsPlugin from beets.util import normpath, syspath, bytestring_path from beets import config M3U_DEFAULT_NAME = 'imported.m3u' - +log = logging.getLogger('beets') class ImportFeedsPlugin(BeetsPlugin): def __init__(self): @@ -80,11 +82,16 @@ def _build_m3u_filename(basename): def _write_m3u(m3u_path, items_paths): - """Append relative paths to items into m3u file. + """Append relative paths to items into m3u file, or write to stdout. """ - with open(syspath(m3u_path), 'a') as f: + if m3u_path == "stdout": + log.info("Location of imported music:") for path in items_paths: - f.write(path + '\n') + log.info(" " + path) + else: + with open(syspath(m3u_path), 'a') as f: + for path in items_paths: + f.write(path + '\n') def _record_items(lib, basename, items): @@ -126,6 +133,10 @@ def _record_items(lib, basename, items): if not os.path.exists(syspath(dest)): os.symlink(syspath(path), syspath(dest)) + if 'echo' in formats: + m3u_path = _build_m3u_filename(basename) + _write_m3u("stdout", paths) + @ImportFeedsPlugin.listen('library_opened') def library_opened(lib): diff --git a/docs/plugins/importfeeds.rst b/docs/plugins/importfeeds.rst index dcc2ae653..515295dca 100644 --- a/docs/plugins/importfeeds.rst +++ b/docs/plugins/importfeeds.rst @@ -18,12 +18,13 @@ root of your music library. The ``absolute_path`` configuration option can be set to use absolute paths instead of relative paths. Some applications may need this to work properly. -Three different types of outputs coexist, specify the ones you want to use by +Four different types of outputs coexist, specify the ones you want to use by setting the ``formats`` parameter: - ``m3u``: catalog the imports in a centralized playlist. By default, the playlist is named ``imported.m3u``. To use a different file, just set the ``m3u_name`` parameter inside the ``importfeeds`` config section. - ``m3u_multi``: create a new playlist for each import (uniquely named by appending the date and track/album name). - ``link``: create a symlink for each imported item. This is the recommended setting to propagate beets imports to your iTunes library: just drag and drop the ``dir`` folder on the iTunes dock icon. +- ``echo``: do not write a playlist file at all, but echo a list of new file paths to the terminal. Here's an example configuration for this plugin:: From 68eae9e683c6f4fc403b39b04d012985c9cb146e Mon Sep 17 00:00:00 2001 From: robotanarchy Date: Sat, 13 Sep 2014 17:25:10 +0200 Subject: [PATCH 2/3] didn't know about flake... --- beetsplug/importfeeds.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beetsplug/importfeeds.py b/beetsplug/importfeeds.py index 6c454e104..2985a8569 100644 --- a/beetsplug/importfeeds.py +++ b/beetsplug/importfeeds.py @@ -28,6 +28,7 @@ from beets import config M3U_DEFAULT_NAME = 'imported.m3u' log = logging.getLogger('beets') + class ImportFeedsPlugin(BeetsPlugin): def __init__(self): super(ImportFeedsPlugin, self).__init__() From 2039d2effe5882a733c321127c58f83138348195 Mon Sep 17 00:00:00 2001 From: robotanarchy Date: Sun, 14 Sep 2014 20:17:53 +0200 Subject: [PATCH 3/3] don't use the _write_m3u function for stdout stuff --- beetsplug/importfeeds.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/beetsplug/importfeeds.py b/beetsplug/importfeeds.py index 2985a8569..0f1cd11c8 100644 --- a/beetsplug/importfeeds.py +++ b/beetsplug/importfeeds.py @@ -83,16 +83,11 @@ def _build_m3u_filename(basename): def _write_m3u(m3u_path, items_paths): - """Append relative paths to items into m3u file, or write to stdout. + """Append relative paths to items into m3u file. """ - if m3u_path == "stdout": - log.info("Location of imported music:") + with open(syspath(m3u_path), 'a') as f: for path in items_paths: - log.info(" " + path) - else: - with open(syspath(m3u_path), 'a') as f: - for path in items_paths: - f.write(path + '\n') + f.write(path + '\n') def _record_items(lib, basename, items): @@ -135,8 +130,9 @@ def _record_items(lib, basename, items): os.symlink(syspath(path), syspath(dest)) if 'echo' in formats: - m3u_path = _build_m3u_filename(basename) - _write_m3u("stdout", paths) + log.info("Location of imported music:") + for path in paths: + log.info(" " + path) @ImportFeedsPlugin.listen('library_opened')