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 +4 -4
- data/lib/searchlink/config.rb +4 -3
- data/lib/searchlink/searches/lyrics.rb +33 -4
- data/lib/searchlink/searches.rb +8 -5
- data/lib/searchlink/string.rb +9 -1
- data/lib/searchlink/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fe46ed7fe6c7688ce62b32035592b22ada5ccfd918c39cb4efde42d40c328a4
|
4
|
+
data.tar.gz: 14c5b53c4b88f6fea15f729781fc8fb7bb21ecabc211e0d49fd7a3b2078d36b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 560cbfc23c8ebcb47ccd67d896e1168ce9acb9d58adccde348df1bd11cea3e8d5e9990d2565088a2367239e4b3799bd50effd856fb41836d8007d4ae3f42e4ea
|
7
|
+
data.tar.gz: debe843ab12a7abd1075f36456d789f38f7cb402af6bb717c7c53ffb59205626e3a925aa515a17dd40c0fb34b9e2950203fc368a33d28e4a4fcc6857a10a7446
|
data/lib/searchlink/config.rb
CHANGED
@@ -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
|
-
|
23
|
+
if File.exist?(old_style) && !File.exist?(new_style)
|
24
|
+
old_style
|
25
25
|
else
|
26
|
-
|
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
|
-
|
103
|
+
lyrics = CGI.unescape(lyrics).gsub(%r{<br/?>}, " \n").gsub(%r{</?.*?>}, '').gsub(/'/, "'")
|
104
|
+
"#{title}\n\n#{lyrics.code_indent}\n"
|
76
105
|
else
|
77
106
|
false
|
78
107
|
end
|
data/lib/searchlink/searches.rb
CHANGED
@@ -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
|
-
|
120
|
-
|
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
|
-
|
126
|
+
return unless File.directory?(new_plugins_folder)
|
124
127
|
|
125
|
-
Dir.glob(File.join(
|
128
|
+
Dir.glob(File.join(new_plugins_folder, '**/*.rb')).sort.each do |plugin|
|
126
129
|
require plugin
|
127
130
|
end
|
128
131
|
end
|
data/lib/searchlink/string.rb
CHANGED
@@ -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
|
data/lib/searchlink/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2023-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|