searchlink 2.3.62 → 2.3.63

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 20591719c33fd31a48e40072d839ea484f13fec80789fccee1417108e0e4f9f4
4
- data.tar.gz: ff92074f65ad60d2bb52016169f9cb5d61d4ef3696130195f8ef1dfeb8b0635b
3
+ metadata.gz: 4fe46ed7fe6c7688ce62b32035592b22ada5ccfd918c39cb4efde42d40c328a4
4
+ data.tar.gz: 14c5b53c4b88f6fea15f729781fc8fb7bb21ecabc211e0d49fd7a3b2078d36b0
5
5
  SHA512:
6
- metadata.gz: 06fd6071642386fed86432d1b18ccac1d7ebad0dbdcdfb8c8e5e244431d7e190039b6b53e2ce75654bef4512c28b67ba5f7d4d56c6f728bd7387bb7d74eeb5e9
7
- data.tar.gz: 6d7e73ece33947326e6ff610af6c71cf8f7d113650c447bb2d97409095d780b54c3ebc5b3a6cb2da4a075e03684e02d1ff0bef1a301a8f4576576a8329b4e4db
6
+ metadata.gz: 560cbfc23c8ebcb47ccd67d896e1168ce9acb9d58adccde348df1bd11cea3e8d5e9990d2565088a2367239e4b3799bd50effd856fb41836d8007d4ae3f42e4ea
7
+ data.tar.gz: debe843ab12a7abd1075f36456d789f38f7cb402af6bb717c7c53ffb59205626e3a925aa515a17dd40c0fb34b9e2950203fc368a33d28e4a4fcc6857a10a7446
@@ -9,14 +9,15 @@ module SL
9
9
  # `trigger` is A regular expression that will trigger this plugin
10
10
  # when used with a bang. The one below will trigger on !lyrics or
11
11
  # !lyricse.
12
- trigger: 'lyrics?e?',
12
+ trigger: 'lyrics?(e|e?js)?',
13
13
  # Every search that the plugin should execute should be individually
14
14
  # listed and described in the searches array. This is used for
15
15
  # completion and help generation. Do not include the bang (!) in the
16
16
  # search keyword.
17
17
  searches: [
18
18
  ['lyric', 'Song Lyrics Search'],
19
- ['lyrice', 'Song Lyrics Embed']
19
+ ['lyrice', 'Song Lyrics Embed'],
20
+ ['lyricjs', 'Song Lyrics JS Embed']
20
21
  ]
21
22
  }
22
23
  end
@@ -45,6 +46,15 @@ module SL
45
46
  SL.add_error('No lyrics found', "Song lyrics for #{search_terms} not found")
46
47
  false
47
48
  end
49
+ when /js$/
50
+ url, title = SL.ddg("site:genius.com #{search_terms}", link_text)
51
+ if url
52
+ title = js_embed(url)
53
+ title ? ['embed', title, link_text] : false
54
+ else
55
+ SL.add_error('No lyrics found', "Song lyrics for #{search_terms} not found")
56
+ false
57
+ end
48
58
  else
49
59
  # You can perform a DuckDuckGo search using SL#ddg, passing the
50
60
  # search terms and link_text. It will return url, title, and
@@ -59,6 +69,24 @@ module SL
59
69
  end
60
70
  end
61
71
 
72
+ def js_embed(url)
73
+ if SL::URL.valid_link?(url)
74
+ body = Curl::Html.new(url).body
75
+ api_path = body.match(%r{\\"apiPath\\":\\"(/songs/.*?)\\"})[1]
76
+ id = api_path.sub(/.*?(\d+)$/, '\1')
77
+ title = body.match(/_sf_async_config.title = '(.*?) \| Genius Lyrics'/)[1]
78
+
79
+ <<~EOEMBED
80
+ <div id='rg_embed_link_#{id}' class='rg_embed_link' data-song-id='#{id}'>
81
+ Read <a href='#{url}'>#{title}</a> on Genius
82
+ </div>
83
+ <script crossorigin src='//genius.com#{api_path}/embed.js'></script>
84
+ EOEMBED
85
+ else
86
+ false
87
+ end
88
+ end
89
+
62
90
  # Any additional helper methods can be defined after #search
63
91
  def get_lyrics(url)
64
92
  if SL::URL.valid_link?(url)
@@ -66,13 +94,14 @@ module SL
66
94
  # `curl -SsL` is faster and easier. Curl::Html.new(url) returns a
67
95
  # new object containing :body
68
96
  body = Curl::Html.new(url).body
69
-
97
+ title = body.match(/_sf_async_config.title = '(.*?) \| Genius Lyrics'/)[1].gsub(/\\/, '').sub(/ Lyrics$/, '')
70
98
  matches = body.scan(%r{class="Lyrics__Container-.*?>(.*?)</div><div class="LyricsFooter})
71
99
 
72
100
  lyrics = matches.join("\n")
73
101
 
74
102
  if lyrics
75
- "```\n#{CGI.unescape(lyrics).gsub(%r{<br/?>}, " \n").gsub(%r{</?.*?>}, '').gsub(/&#x27;/, "'")}\n```"
103
+ lyrics = CGI.unescape(lyrics).gsub(%r{<br/?>}, " \n").gsub(%r{</?.*?>}, '').gsub(/&#x27;/, "'")
104
+ "#{title}\n\n#{lyrics.code_indent}\n"
76
105
  else
77
106
  false
78
107
  end
@@ -70,7 +70,7 @@ module SL
70
70
 
71
71
  def best_search_match(term)
72
72
  searches = all_possible_searches.dup
73
- searches.select { |s| s.matches_score(term, separator: '', start_word: false) > 8 }
73
+ searches.flatten.select { |s| s.matches_score(term, separator: '', start_word: false) > 8 }
74
74
  end
75
75
 
76
76
  def all_possible_searches
@@ -2,7 +2,7 @@
2
2
  class ::String
3
3
  # Scrub invalid characters from string
4
4
  def scrub
5
- encode('utf-16', invalid: :replace).encode('utf-8')
5
+ encode('utf-16', invalid: :replace).encode('utf-8').gsub(/\u00A0/, ' ')
6
6
  end
7
7
 
8
8
  # @see #scrub
@@ -476,4 +476,12 @@ class ::String
476
476
  str = gsub(/(#{separator})+/, separator)
477
477
  str.split(/#{separator}/).map { |arg| /#{bound}#{arg.gsub(/[^a-z0-9]/i, '.?')}/i }
478
478
  end
479
+
480
+ ##
481
+ ## Indent each line of string with 4 spaces
482
+ ##
483
+ ## @return [String] indented string
484
+ def code_indent
485
+ split(/\n/).map { |l| " #{l}" }.join("\n")
486
+ end
479
487
  end
@@ -1,5 +1,5 @@
1
1
  module SL
2
- VERSION = '2.3.62'
2
+ VERSION = '2.3.63'
3
3
  end
4
4
 
5
5
  module SL
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searchlink
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.62
4
+ version: 2.3.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-25 00:00:00.000000000 Z
11
+ date: 2023-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler