searchlink 2.3.62 → 2.3.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/searchlink/curl/html.rb +3 -4
- data/lib/searchlink/searches/lyrics.rb +33 -4
- data/lib/searchlink/searches.rb +1 -1
- data/lib/searchlink/string.rb +9 -1
- data/lib/searchlink/version.rb +10 -5
- data/lib/tokens.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: c19b349c222ba84795f47cc03fc5039efb3ea3f0c7ae305ad1e125c2763d33e3
|
|
4
|
+
data.tar.gz: 7be23e30bcee8c3dd2dbffe05dc06c345ffa7d65f64b20cf10e33b6a57f1b6fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e27d21134df20d7b7721375899a62fedcd0fa0f9ac7378a2c3bf8e54dbd1f302bdc899b4d1edc89e25d2652229a980639ffe8a906e687848fbbdd60ca5129771
|
|
7
|
+
data.tar.gz: fd1f793c0031421d5525c78ae7b173119eb45b203ca7966db09e3991d420ab078f81a92c51280cd369a1fe5ee66a75c77df2bb4f99c9c1eeb73fc2e5c65ccbf8
|
data/lib/searchlink/curl/html.rb
CHANGED
|
@@ -107,6 +107,7 @@ module Curl
|
|
|
107
107
|
## @param tag The tag
|
|
108
108
|
## @param source [Boolean] Return full tag instead of contents
|
|
109
109
|
##
|
|
110
|
+
## @return [Array] array of tag matches/contents
|
|
110
111
|
def extract_tag_contents(tag, source: false)
|
|
111
112
|
return @body.scan(%r{<#{tag}.*?>(?:.*?</#{tag}>)?}) if source
|
|
112
113
|
|
|
@@ -452,13 +453,11 @@ module Curl
|
|
|
452
453
|
end
|
|
453
454
|
|
|
454
455
|
# look for a charset in a content-encoding header
|
|
455
|
-
if content_type
|
|
456
|
-
encoding ||= content_type[/charset=["']?(.*?)($|["';\s])/i, 1]
|
|
457
|
-
end
|
|
456
|
+
encoding ||= content_type[/charset=["']?(.*?)($|["';\s])/i, 1] if content_type
|
|
458
457
|
|
|
459
458
|
# look for a charset in a meta tag in the first 1024 bytes
|
|
460
459
|
unless encoding
|
|
461
|
-
data = body[0..1023].gsub(/<!--.*?(-->|\Z)/m,
|
|
460
|
+
data = body[0..1023].gsub(/<!--.*?(-->|\Z)/m, '')
|
|
462
461
|
data.scan(/<meta.*?>/im).each do |meta|
|
|
463
462
|
encoding ||= meta[/charset=["']?([^>]*?)($|["'\s>])/im, 1]
|
|
464
463
|
end
|
|
@@ -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
|
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
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module SL
|
|
2
|
-
VERSION = '2.3.
|
|
2
|
+
VERSION = '2.3.64'
|
|
3
3
|
end
|
|
4
4
|
|
|
5
5
|
module SL
|
|
6
6
|
class << self
|
|
7
7
|
def version_check
|
|
8
|
-
cachefile = File.expand_path('~/.
|
|
8
|
+
cachefile = File.expand_path('~/.config/cache/update.txt')
|
|
9
9
|
if File.exist?(cachefile)
|
|
10
10
|
last_check, latest_tag = IO.read(cachefile).strip.split(/\|/)
|
|
11
11
|
last_time = Time.parse(last_check)
|
|
@@ -22,12 +22,12 @@ module SL
|
|
|
22
22
|
latest_tag ||= SL::VERSION
|
|
23
23
|
latest = SemVer.new(latest_tag)
|
|
24
24
|
current = SemVer.new(SL::VERSION)
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
File.open(cachefile, 'w') { |f| f.puts("#{last_time.strftime('%c')}|#{latest.to_s}") }
|
|
27
27
|
|
|
28
|
-
return "SearchLink v#{current
|
|
28
|
+
return "SearchLink v#{current}, #{latest} available. Run 'update' to download." if latest_tag && current.older_than(latest)
|
|
29
29
|
|
|
30
|
-
"SearchLink v#{current
|
|
30
|
+
"SearchLink v#{current}"
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
# Check for a newer version than local copy using GitHub release tag
|
|
@@ -63,6 +63,11 @@ module SL
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def update_searchlink
|
|
66
|
+
if %x{uname}.strip !~ /Darwin/
|
|
67
|
+
add_output('Auto updating only available on macOS')
|
|
68
|
+
return
|
|
69
|
+
end
|
|
70
|
+
|
|
66
71
|
new_version = SL.new_version?
|
|
67
72
|
if new_version
|
|
68
73
|
folder = File.expand_path('~/Downloads')
|
data/lib/tokens.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.64
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Brett Terpstra
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-01-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|