mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 04:55:10 +01:00
Merge pull request #3612 from ybnd/master
Fix item == None issues when writing lyrics ReST (issue #2805)
This commit is contained in:
commit
93c14ea66d
2 changed files with 24 additions and 16 deletions
|
|
@ -770,7 +770,8 @@ class LyricsPlugin(plugins.BeetsPlugin):
|
|||
write = ui.should_write()
|
||||
if opts.writerest:
|
||||
self.writerest_indexes(opts.writerest)
|
||||
for item in lib.items(ui.decargs(args)):
|
||||
items = lib.items(ui.decargs(args))
|
||||
for item in items:
|
||||
if not opts.local_only and not self.config['local']:
|
||||
self.fetch_item_lyrics(
|
||||
lib, item, write,
|
||||
|
|
@ -780,10 +781,10 @@ class LyricsPlugin(plugins.BeetsPlugin):
|
|||
if opts.printlyr:
|
||||
ui.print_(item.lyrics)
|
||||
if opts.writerest:
|
||||
self.writerest(opts.writerest, item)
|
||||
if opts.writerest:
|
||||
# flush last artist
|
||||
self.writerest(opts.writerest, None)
|
||||
self.appendrest(opts.writerest, item)
|
||||
if opts.writerest and items:
|
||||
# flush last artist & write to ReST
|
||||
self.writerest(opts.writerest)
|
||||
ui.print_(u'ReST files generated. to build, use one of:')
|
||||
ui.print_(u' sphinx-build -b html %s _build/html'
|
||||
% opts.writerest)
|
||||
|
|
@ -795,26 +796,21 @@ class LyricsPlugin(plugins.BeetsPlugin):
|
|||
cmd.func = func
|
||||
return [cmd]
|
||||
|
||||
def writerest(self, directory, item):
|
||||
"""Write the item to an ReST file
|
||||
def appendrest(self, directory, item):
|
||||
"""Append the item to an ReST file
|
||||
|
||||
This will keep state (in the `rest` variable) in order to avoid
|
||||
writing continuously to the same files.
|
||||
"""
|
||||
|
||||
if item is None or slug(self.artist) != slug(item.albumartist):
|
||||
if self.rest is not None:
|
||||
path = os.path.join(directory, 'artists',
|
||||
slug(self.artist) + u'.rst')
|
||||
with open(path, 'wb') as output:
|
||||
output.write(self.rest.encode('utf-8'))
|
||||
self.rest = None
|
||||
if item is None:
|
||||
return
|
||||
if slug(self.artist) != slug(item.albumartist):
|
||||
# Write current file and start a new one ~ item.albumartist
|
||||
self.writerest(directory)
|
||||
self.artist = item.albumartist.strip()
|
||||
self.rest = u"%s\n%s\n\n.. contents::\n :local:\n\n" \
|
||||
% (self.artist,
|
||||
u'=' * len(self.artist))
|
||||
|
||||
if self.album != item.album:
|
||||
tmpalbum = self.album = item.album.strip()
|
||||
if self.album == '':
|
||||
|
|
@ -826,6 +822,15 @@ class LyricsPlugin(plugins.BeetsPlugin):
|
|||
u'~' * len(title_str),
|
||||
block)
|
||||
|
||||
def writerest(self, directory):
|
||||
"""Write self.rest to a ReST file
|
||||
"""
|
||||
if self.rest is not None and self.artist is not None:
|
||||
path = os.path.join(directory, 'artists',
|
||||
slug(self.artist) + u'.rst')
|
||||
with open(path, 'wb') as output:
|
||||
output.write(self.rest.encode('utf-8'))
|
||||
|
||||
def writerest_indexes(self, directory):
|
||||
"""Write conf.py and index.rst files necessary for Sphinx
|
||||
|
||||
|
|
|
|||
|
|
@ -207,6 +207,9 @@ Fixes:
|
|||
* :doc:`/plugins/lyrics`: Adapt the Genius backend to changes in markup to
|
||||
reduce the scraping failure rate.
|
||||
:bug:`3535` :bug:`3594`
|
||||
* :doc:`/plugins/lyrics`: Fix crash when writing ReST files for a query without
|
||||
results or fetched lyrics
|
||||
:bug:`2805`
|
||||
|
||||
For plugin developers:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue