searchlink 2.3.61 → 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: cff5bedf7ccbc233a648654e9f3c7bf41981a451c11ddfb6b1fd90741ae6ae2a
4
- data.tar.gz: 41e05ed7af669c38d093eb5f109489a786e5bef29575caade95c8328332abf06
3
+ metadata.gz: 4fe46ed7fe6c7688ce62b32035592b22ada5ccfd918c39cb4efde42d40c328a4
4
+ data.tar.gz: 14c5b53c4b88f6fea15f729781fc8fb7bb21ecabc211e0d49fd7a3b2078d36b0
5
5
  SHA512:
6
- metadata.gz: 1fcb8a00815275b8263805029d47d50d8fd5d934de2880dcfb32c41384652c5791a0c2415e5cead7b2649c348b5374f050d2a4f74b817b8399e25efd5bc72912
7
- data.tar.gz: c65f32af3fdeca3ea36306b92babcaa09cfb4c1aee01c5569a1dcf8132821d9b94a05e9f186961a2e67990db6ec409b22562b12e73ef7ca4517036263a8bc642
6
+ metadata.gz: 560cbfc23c8ebcb47ccd67d896e1168ce9acb9d58adccde348df1bd11cea3e8d5e9990d2565088a2367239e4b3799bd50effd856fb41836d8007d4ae3f42e4ea
7
+ data.tar.gz: debe843ab12a7abd1075f36456d789f38f7cb402af6bb717c7c53ffb59205626e3a925aa515a17dd40c0fb34b9e2950203fc368a33d28e4a4fcc6857a10a7446
@@ -20,10 +20,11 @@ module SL
20
20
  def config_file
21
21
  old_style = File.expand_path('~/.searchlink')
22
22
  new_style = File.expand_path('~/.config/searchlink/config.yaml')
23
- if File.exist?(old_style)
24
- return old_style
23
+ if File.exist?(old_style) && !File.exist?(new_style)
24
+ old_style
25
25
  else
26
- return new_style
26
+ FileUtils.mkdir_p(File.dirname(new_style))
27
+ new_style
27
28
  end
28
29
  end
29
30
 
@@ -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
@@ -115,14 +115,17 @@ module SL
115
115
 
116
116
  def load_custom
117
117
  plugins_folder = File.expand_path('~/.local/searchlink/plugins')
118
+ new_plugins_folder = File.expand_path('~/.config/searchlink/plugins')
118
119
 
119
- Dir.glob(File.join(plugins_folder, '**/*.rb')).sort.each do |plugin|
120
- require plugin
120
+ if File.directory?(plugins_folder) && !File.directory?(new_plugins_folder)
121
+ Dir.glob(File.join(plugins_folder, '**/*.rb')).sort.each do |plugin|
122
+ require plugin
123
+ end
121
124
  end
122
125
 
123
- plugins_folder = File.expand_path('~/.config/searchlink/plugins')
126
+ return unless File.directory?(new_plugins_folder)
124
127
 
125
- Dir.glob(File.join(plugins_folder, '**/*.rb')).sort.each do |plugin|
128
+ Dir.glob(File.join(new_plugins_folder, '**/*.rb')).sort.each do |plugin|
126
129
  require plugin
127
130
  end
128
131
  end
@@ -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.61'
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.61
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