kgmusic 0.1.0pre20160525 → 0.1.0pre20160530

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 026be473c388de1d6d9e78abf7725d84aa78ec2c
4
- data.tar.gz: 99d337aa7061c503f362a7917c3a28b3b633b7d8
3
+ metadata.gz: c7213f073068b90898fbc9663382ac7056f55775
4
+ data.tar.gz: ee0a1bc7822e5b0341dfaa883e83e79cbf2990de
5
5
  SHA512:
6
- metadata.gz: 3a8a3c1069986898c5fb5931304afef52c6704dcd0d3fac23b66925025fae44c10767010d62aef7b8002aec197f4baef86f550aef8fe1a4c02cb992ea9f787c0
7
- data.tar.gz: 85f128695eab5ae5416821b0a5f05f778773b415c3ef6f8e974b145e7a7979e1b9934fa312f71742588d72b9c46173ce8f96ac94bd7a95f7b90f81a16f3cf131
6
+ metadata.gz: d463a38f32b8a5a53244dd9d4da8709baa25ecbfcaa79a2af1a58b5216e0c6234ed9b43afd51eba4dafd0914ed7f03cd5398451171a88c9eb201295a6919b933
7
+ data.tar.gz: 241932016c5af72612812aba354f3f811d1dd9c2157524c4a6f8b5d12e38825f921220cae5994aef1a9bf96445feb555e99995028a0b67b5b09463b739d9bcc1
data/README.md CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
21
21
  ## Usage
22
22
  require 'kgmusic'
23
23
 
24
- Using API:
24
+ Using Client API:
25
25
 
26
26
  cli = KgMusic::Client.new
27
27
 
@@ -31,6 +31,10 @@ Or install it yourself as:
31
31
 
32
32
  all_genres = cli.all_genres
33
33
 
34
+ Using Artists API:
35
+
36
+ artists = KgMusic::Artists.show_info(146)
37
+
34
38
  Using Downloader:
35
39
 
36
40
  music = KgMusic::Downloader.new :artist => 'God Is An Astronaut', :album => 'God Is An Astronaut'
@@ -0,0 +1,59 @@
1
+ require "curl"
2
+ require "nokogiri"
3
+
4
+ module KgMusic
5
+
6
+ module API
7
+
8
+ class Artists
9
+
10
+ private_class_method :new
11
+
12
+ def initialize(url:)
13
+ c = Curl::Easy.new(url) do |c|
14
+ c.follow_location = true
15
+ c.perform
16
+ end
17
+
18
+ @@root = Nokogiri::HTML.parse(c.body_str)
19
+ last_page_uri_str = @@root.xpath("//div[@class='pager']//li[@class='last']/a/@href").text
20
+ @@pages = last_page_uri_str.scan(/\d+$/).sample.to_i
21
+ end
22
+
23
+ private
24
+
25
+ def self.get_info
26
+ @@root.xpath("//div[@class='artist-item']").reduce([]) do |out, artist|
27
+ out << {
28
+ :artist => artist.css('div.artist-info').at('a').text.strip,
29
+ :albums => artist.css('ul.artist-albums/li').reduce([]) { |albums, album| albums << album.at('img').attr('title') },
30
+ :tracks => artist.css('ul.artist-songs/li').reduce([]) { |tracks, track| tracks << track.css('a').text },
31
+ :all_albums => artist.css('div.albums-count').at('a').text.strip,
32
+ :all_tracks => artist.css('div.songs-count').at('a').text.strip
33
+ }
34
+
35
+ end
36
+ end
37
+
38
+ public
39
+
40
+ def self.show_info ( number )
41
+
42
+ new(url: 'kibergrad.fm/artists')
43
+
44
+ if number == 1
45
+ get_info
46
+ elsif number.between?( 1, @@pages )
47
+ new( url: "kibergrad.fm/artists?page=#{number}" )
48
+ get_info
49
+ else
50
+ raise RangeError
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -7,30 +7,30 @@ module KgMusic
7
7
 
8
8
  class Client
9
9
 
10
- def initialize(url: 'kibergrad.fm')
11
- c = Curl::Easy.new(url) do |curl|
12
- curl.follow_location = true
13
- curl.perform
10
+ def initialize
11
+ c = Curl::Easy.new('kibergrad.fm') do |c|
12
+ c.follow_location = true
13
+ c.perform
14
14
  end
15
15
  @@root = Nokogiri::HTML.parse(c.body_str)
16
16
  end
17
17
 
18
18
  def popular_artists
19
- list = @@root.xpath("//div[@class='popular-artists']//li/a")
20
- out = []; list.collect { |element| out << "#{element.children}" }
21
- out
19
+ @@root.xpath("//div[@class='popular-artists']//li/a").reduce([]) do |artists, element|
20
+ artists << element.text
21
+ end
22
22
  end
23
23
 
24
24
  def popular_genres
25
- list = @@root.xpath("//div/ul[@class='aim-menu css']/li/a")
26
- out = []; list.collect { |element| out << "#{element.text}" }
27
- out
25
+ @@root.xpath("//div//ul[@class='aim-menu css']/li/a").reduce([]) do |popular_genres, element|
26
+ popular_genres << element.text
27
+ end
28
28
  end
29
29
 
30
30
  def all_genres
31
- list = @@root.xpath("//div//ul[@class='aim-menu css']//li/a")
32
- out = []; list.collect { |element| out << "#{element.text}" }
33
- out
31
+ @@root.xpath("//div//ul[@class='aim-menu css']//li/a").reduce([]) do |all_genres, element|
32
+ all_genres << element.text
33
+ end
34
34
  end
35
35
 
36
36
  end
data/lib/kgmusic/api.rb CHANGED
@@ -1 +1,2 @@
1
1
  require 'kgmusic/api/client'
2
+ require 'kgmusic/api/artists'
@@ -1,3 +1,3 @@
1
1
  module KgMusic
2
- VERSION = "0.1.0pre20160525"
2
+ VERSION = "0.1.0pre20160530"
3
3
  end
data/lib/kgmusic.rb CHANGED
@@ -5,6 +5,8 @@ module KgMusic
5
5
 
6
6
  class Client < API::Client; end
7
7
 
8
+ class Artists < API::Artists; end
9
+
8
10
  class Downloader
9
11
 
10
12
  include BaseMod
@@ -54,13 +56,16 @@ module KgMusic
54
56
  curl.set(:resume_from, fsize) if fsize > 0
55
57
  curl.on_body { |body| f.write body }
56
58
  end
57
- puts "Please, wait ..."
59
+ c.on_progress do |dlt, dln, ult, uln|
60
+ printf("\r %i of %i MBytes received ...", (dln / 1_000_000), (dlt / 1_000_000))
61
+ true
62
+ end
58
63
  c.perform if content_length > fsize
59
64
  end
60
65
  rescue => ex
61
66
  puts ex.message
62
67
  end
63
- return File.size(outfile)
68
+ nil
64
69
  end
65
70
 
66
71
  public
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.0pre20160525
4
+ version: 0.1.0pre20160530
5
5
  platform: ruby
6
6
  authors:
7
7
  - vitvegl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
@@ -110,6 +110,7 @@ files:
110
110
  - kgmusic.gemspec
111
111
  - lib/kgmusic.rb
112
112
  - lib/kgmusic/api.rb
113
+ - lib/kgmusic/api/artists.rb
113
114
  - lib/kgmusic/api/client.rb
114
115
  - lib/kgmusic/base/basemod.rb
115
116
  - lib/kgmusic/basemod.rb