mirror of
https://github.com/beetbox/beets.git
synced 2025-12-26 02:24:33 +01:00
importfeeds: write _feeds_dir global once, on reception of 'library_opened' event
This commit is contained in:
parent
86f513d4ab
commit
2c67f0f76e
1 changed files with 14 additions and 11 deletions
|
|
@ -31,15 +31,14 @@ class ImportFeedsPlugin(BeetsPlugin):
|
|||
|
||||
_feeds_formats = ui.config_val(config, 'importfeeds', 'feeds_formats',
|
||||
'').split()
|
||||
|
||||
_feeds_dir = ui.config_val(config, 'importfeeds', 'feeds_dir', None)
|
||||
_feeds_dir = os.path.expanduser(_feeds_dir)
|
||||
|
||||
_m3u_name = ui.config_val(config, 'importfeeds', 'm3u_name',
|
||||
M3U_DEFAULT_NAME)
|
||||
|
||||
if _feeds_dir and not os.path.exists(_feeds_dir):
|
||||
os.makedirs(_feeds_dir)
|
||||
_feeds_dir = ui.config_val(config, 'importfeeds', 'feeds_dir', None)
|
||||
|
||||
if _feeds_dir:
|
||||
_feeds_dir = os.path.expanduser(_feeds_dir)
|
||||
if not os.path.exists(_feeds_dir):
|
||||
os.makedirs(_feeds_dir)
|
||||
|
||||
def _get_feeds_dir(lib):
|
||||
"""Given a Library object, return the path to the feeds directory to be
|
||||
|
|
@ -73,10 +72,7 @@ def _write_m3u(m3u_path, items_paths):
|
|||
def _record_items(lib, basename, items):
|
||||
"""Records relative paths to the given items for each feed format
|
||||
"""
|
||||
global _feeds_dir
|
||||
if not _feeds_dir:
|
||||
_feeds_dir = _get_feeds_dir(lib)
|
||||
|
||||
|
||||
paths = []
|
||||
for item in items:
|
||||
paths.append(os.path.relpath(item.path, _feeds_dir))
|
||||
|
|
@ -93,9 +89,16 @@ def _record_items(lib, basename, items):
|
|||
for path in paths:
|
||||
os.symlink(path, os.path.join(_feeds_dir, os.path.basename(path)))
|
||||
|
||||
@ImportFeedsPlugin.listen('library_opened')
|
||||
def library_opened(lib):
|
||||
global _feeds_dir
|
||||
if not _feeds_dir:
|
||||
_feeds_dir = _get_feeds_dir(lib)
|
||||
|
||||
@ImportFeedsPlugin.listen('album_imported')
|
||||
def album_imported(lib, album, config):
|
||||
_record_items(lib, album.album, album.items())
|
||||
|
||||
@ImportFeedsPlugin.listen('item_imported')
|
||||
def item_imported(lib, item, config):
|
||||
_record_items(lib, item.title, [item])
|
||||
|
|
|
|||
Loading…
Reference in a new issue