kgmusic 0.1.0pre3 → 0.1.0pre4
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/kgmusic/basemod.rb +51 -0
- data/lib/kgmusic/version.rb +1 -1
- data/lib/kgmusic.rb +7 -44
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffecb0c3212801f6e8c1ae897cd2e7f2c4d84065
|
4
|
+
data.tar.gz: 1a09a8b4ab6fbb7bc87bf0a4fcb84cb8c0d55abb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab437cc7d8f544f47fcd5c6054fa473f5e3cdedab5c8c71a1f43906148ab9153252c44a2b9e7d27a1f641d297530196a699620af0c7de36424d4ea3a1af01786
|
7
|
+
data.tar.gz: c72283cb0b640a93e4200d72a7dff0e3fcaa370209fec35f4dc973a9c75647a4b3dab1c2ac2a7d9758a0477b83d54e6bd223ef3604f9adc7fc6d6be7adcd44a6
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'kgmusic/version'
|
2
|
+
require 'unicode_utils/titlecase'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module KgMusic
|
7
|
+
module BaseMod
|
8
|
+
include UnicodeUtils
|
9
|
+
|
10
|
+
UNALLOWED_SYMBOLS = [
|
11
|
+
"`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", ",", "_", "=",
|
12
|
+
"+", "[", "{", "]", "}", "\\", "|", ";", ":", "\"", "<", ".", ">", "/", "?"
|
13
|
+
]
|
14
|
+
|
15
|
+
protected
|
16
|
+
def go_to(url, params={})
|
17
|
+
RestClient.get(url, params) do |response, request, result, &block|
|
18
|
+
if [301, 302, 307].include? response.code
|
19
|
+
response.follow_redirection(request, result, &block)
|
20
|
+
else
|
21
|
+
final_url = request.url
|
22
|
+
response.return!(request, result, &block)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def has_unallowed_symbols?(key)
|
28
|
+
counter = UNALLOWED_SYMBOLS.select {|s| key.include?(s)}
|
29
|
+
counter.size > 0 ? true : false
|
30
|
+
end
|
31
|
+
|
32
|
+
def strip_unallowed_symbols(key)
|
33
|
+
UNALLOWED_SYMBOLS.map {|s| key.delete!(s)}
|
34
|
+
key
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_html doc
|
38
|
+
Nokogiri::HTML.parse doc
|
39
|
+
end
|
40
|
+
|
41
|
+
def validate(key)
|
42
|
+
strip_unallowed_symbols(key) if has_unallowed_symbols?(key)
|
43
|
+
words = key.split
|
44
|
+
if words.size == 1
|
45
|
+
key[0] =~ /^[[:lower:]]$/ ? titlecase(key) : key
|
46
|
+
elsif words.size > 1
|
47
|
+
words.map {|w| titlecase(w) unless (w[0].ord === w[0])}.join(" ")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/kgmusic/version.rb
CHANGED
data/lib/kgmusic.rb
CHANGED
@@ -1,22 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require 'unicode_utils/titlecase'
|
3
|
-
require 'rest-client'
|
4
|
-
require 'nokogiri'
|
1
|
+
require "kgmusic/basemod"
|
5
2
|
|
6
3
|
module KgMusic
|
7
4
|
|
8
5
|
class Search
|
9
6
|
|
10
|
-
include
|
7
|
+
include BaseMod
|
11
8
|
|
12
9
|
attr_reader :artist, :album
|
13
10
|
attr_reader :doc, :info, :result, :download_page, :direct_link
|
14
11
|
|
15
|
-
UNALLOWED_SYMBOLS = [
|
16
|
-
"`", "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", ",", "_", "=",
|
17
|
-
"+", "[", "{", "]", "}", "\\", "|", ";", ":", "\"", "<", ".", ">", "/", "?"
|
18
|
-
]
|
19
|
-
|
20
12
|
def initialize(args)
|
21
13
|
begin
|
22
14
|
if args.include?(:artist) and args.include?(:album)
|
@@ -28,43 +20,13 @@ module KgMusic
|
|
28
20
|
end
|
29
21
|
|
30
22
|
protected
|
31
|
-
def has_unallowed_symbols?(key)
|
32
|
-
counter = UNALLOWED_SYMBOLS.select {|s| key.include?(s)}
|
33
|
-
counter.size > 0 ? true : false
|
34
|
-
end
|
35
|
-
|
36
|
-
def strip_unallowed_symbols(key)
|
37
|
-
UNALLOWED_SYMBOLS.map {|s| key.delete!(s)}
|
38
|
-
key
|
39
|
-
end
|
40
|
-
|
41
|
-
def validate(key)
|
42
|
-
strip_unallowed_symbols(key) if has_unallowed_symbols?(key)
|
43
|
-
words = key.split
|
44
|
-
if words.size == 1
|
45
|
-
key[0] =~ /^[[:lower:]]$/ ? titlecase(key) : key
|
46
|
-
elsif words.size > 1
|
47
|
-
words.map {|w| titlecase(w) unless (w[0].ord === w[0])}.join(" ")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def get_page(url, params={})
|
52
|
-
RestClient.get(url, params) do |response, request, result, &block|
|
53
|
-
if [301, 302, 307].include? response.code
|
54
|
-
response.follow_redirection(request, result, &block)
|
55
|
-
else
|
56
|
-
final_url = request.url
|
57
|
-
response.return!(request, result, &block)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
23
|
|
62
24
|
def run
|
63
25
|
url = 'kibergrad.fm/search'
|
64
26
|
params = {:q => "#{@artist} - #{@album}", :p => "albums"}
|
65
27
|
|
66
|
-
@page =
|
67
|
-
@doc =
|
28
|
+
@page = go_to(url, :params => params)
|
29
|
+
@doc = parse_html @page
|
68
30
|
|
69
31
|
if not @doc.css('div.album-info').empty?
|
70
32
|
begin
|
@@ -87,8 +49,8 @@ module KgMusic
|
|
87
49
|
end
|
88
50
|
|
89
51
|
def visit_download_page
|
90
|
-
|
91
|
-
data =
|
52
|
+
page = go_to @download_page
|
53
|
+
data = parse_html page
|
92
54
|
link = data.css('a.download-block').attr('href')
|
93
55
|
@direct_link = link.to_s
|
94
56
|
end
|
@@ -109,6 +71,7 @@ module KgMusic
|
|
109
71
|
end
|
110
72
|
|
111
73
|
public
|
74
|
+
|
112
75
|
def search
|
113
76
|
run
|
114
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kgmusic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.0pre4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vitvegl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_utils
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- bin/setup
|
124
124
|
- kgmusic.gemspec
|
125
125
|
- lib/kgmusic.rb
|
126
|
+
- lib/kgmusic/basemod.rb
|
126
127
|
- lib/kgmusic/version.rb
|
127
128
|
homepage: https://github.com/vitvegl/kgmusic.git
|
128
129
|
licenses:
|