From: Ben Beltran Date: Fri, 14 Nov 2014 00:01:50 +0000 (-0700) Subject: Adds -t / --title option to show header X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli.rb/commitdiff_plain/b2ac68932fa671151d3ab3115c565fa9ad06420c?ds=sidebyside Adds -t / --title option to show header --- diff --git a/bin/lrc b/bin/lrc index 3f71d87..19e5456 100755 --- a/bin/lrc +++ b/bin/lrc @@ -35,6 +35,10 @@ Options: exit end + opts.on("-t", "--title", "Shows the song title and artist") do + Lyricli.show_title + end + opts.on("-h", "--help", "Shows this message") do puts opts exit diff --git a/lib/lyricli.rb b/lib/lyricli.rb index 73c5811..e995c45 100755 --- a/lib/lyricli.rb +++ b/lib/lyricli.rb @@ -40,7 +40,7 @@ module Lyricli # @return [String] the fetched lyrics def self.lyrics @lyricli = Lyricli.new - @lyricli.get_lyrics + @lyricli.get_lyrics(@show_title) end # Returns the version of the library @@ -93,4 +93,9 @@ module Lyricli def self.root File.expand_path('../..',__FILE__) end + + # Sets the show_title instance variable so it requests the title + def self.show_title + @show_title = true + end end diff --git a/lib/lyricli/lyricli.rb b/lib/lyricli/lyricli.rb index c3e1fae..dfb627c 100644 --- a/lib/lyricli/lyricli.rb +++ b/lib/lyricli/lyricli.rb @@ -21,7 +21,7 @@ module Lyricli # LyricsEngine # # @return [String] the found lyrics, or a string indicating none were found - def get_lyrics + def get_lyrics(show_title=false) begin set_current_track @@ -33,7 +33,14 @@ module Lyricli engine = LyricsEngine.new(@current_track[:artist], @current_track[:song]) begin - return engine.get_lyrics + lyrics_output = engine.get_lyrics + + if show_title + lyrics_title = "#{@current_track[:artist]} - #{@current_track[:song]}" + lyrics_output = "#{lyrics_title}\n\n#{lyrics_output}" + end + + return lyrics_output rescue Exceptions::LyricsNotFoundError return "Lyrics not found :(" end