From 0fbfa1feae1397affc388743d56c49879970f502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Fri, 14 Jul 2017 17:34:51 -0400 Subject: [PATCH] render RST instead of HTML ReStructuredText has the advantage over HTML that it can be rendered easily to multiple formats (HTML, ePUB, PDF) and it supports indexes. the output needs to be fed into a file and integrated into an existing Sphinx document, of course. --- beetsplug/lyrics.py | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/beetsplug/lyrics.py b/beetsplug/lyrics.py index f90159708..3c0afab46 100644 --- a/beetsplug/lyrics.py +++ b/beetsplug/lyrics.py @@ -659,6 +659,11 @@ class LyricsPlugin(plugins.BeetsPlugin): action='store_true', default=False, help=u'print lyrics to console', ) + cmd.parser.add_option( + u'-r', u'--print-rst', dest='printrst', + action='store_true', default=False, + help=u'print lyrics to console as RST text', + ) cmd.parser.add_option( u'-f', u'--force', dest='force_refetch', action='store_true', default=False, @@ -682,15 +687,27 @@ class LyricsPlugin(plugins.BeetsPlugin): lib, item, write, opts.force_refetch or self.config['force'], ) - if opts.printlyr and item.lyrics: - if artist != item.artist: - artist = item.artist - ui.print_('

' + artist + '

') - if album != item.album: - album = item.album - ui.print_('

' + artist + '

') - ui.print_('

' + item.title + '

') - ui.print_('
' + item.lyrics + '
') + if item.lyrics: + if opts.printlyr: + ui.print_(item.lyrics) + if opts.printrst: + if artist != item.artist: + artist = item.artist + ui.print_(artist) + ui.print_(u'=' * len(artist)) + ui.print_() + if album != item.album: + album = item.album + ui.print_(album) + ui.print_(u'-' * len(album)) + ui.print_() + title_str = u':index:`' + item.title + u'`' + ui.print_(title_str) + ui.print_(u'~' * len(title_str)) + ui.print_() + # turn lyrics into a line block + ui.print_(u'| ' + item.lyrics.replace(u'\n', u'\n| ')) + ui.print_() cmd.func = func return [cmd]