Skip to content

Commit

Permalink
Fix importfeeds plugin on Python 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
djl committed Aug 12, 2017
1 parent 598c965 commit f909f09
Showing 1 changed file with 9 additions and 29 deletions.
38 changes: 9 additions & 29 deletions beetsplug/importfeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,6 @@
M3U_DEFAULT_NAME = 'imported.m3u'


def _get_feeds_dir(lib):
"""Given a Library object, return the path to the feeds directory to be
used (either in the library directory or an explicitly configured
path). Ensures that the directory exists.
"""
# Inside library directory.
dirpath = lib.directory

# Ensure directory exists.
if not os.path.exists(syspath(dirpath)):
os.makedirs(syspath(dirpath))
return dirpath


def _build_m3u_filename(basename):
"""Builds unique m3u filename by appending given basename to current
date."""
Expand Down Expand Up @@ -78,30 +64,28 @@ def __init__(self):
'absolute_path': False,
})

feeds_dir = self.config['dir'].get()
if feeds_dir:
feeds_dir = os.path.expanduser(bytestring_path(feeds_dir))
self.config['dir'] = feeds_dir
if not os.path.exists(syspath(feeds_dir)):
os.makedirs(syspath(feeds_dir))

relative_to = self.config['relative_to'].get()
if relative_to:
self.config['relative_to'] = normpath(relative_to)
else:
self.config['relative_to'] = feeds_dir
self.config['relative_to'] = self.get_feeds_dir()

self.register_listener('library_opened', self.library_opened)
self.register_listener('album_imported', self.album_imported)
self.register_listener('item_imported', self.item_imported)

def get_feeds_dir(self):
feeds_dir = self.config['dir'].get()
if feeds_dir:
return os.path.expanduser(bytestring_path(feeds_dir))
return config['directory'].as_filename()

def _record_items(self, lib, basename, items):
"""Records relative paths to the given items for each feed format
"""
feedsdir = bytestring_path(self.config['dir'].as_filename())
feedsdir = bytestring_path(self.get_feeds_dir())
formats = self.config['formats'].as_str_seq()
relative_to = self.config['relative_to'].get() \
or self.config['dir'].as_filename()
or self.get_feeds_dir()
relative_to = bytestring_path(relative_to)

paths = []
Expand Down Expand Up @@ -138,10 +122,6 @@ def _record_items(self, lib, basename, items):
for path in paths:
self._log.info(u" {0}", path)

def library_opened(self, lib):
if self.config['dir'].get() is None:
self.config['dir'] = _get_feeds_dir(lib)

def album_imported(self, lib, album):
self._record_items(lib, album.album, album.items())

Expand Down

0 comments on commit f909f09

Please sign in to comment.