kgmusic 0.1.0pre20160530 → 0.1.0pre20160614

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: c7213f073068b90898fbc9663382ac7056f55775
4
- data.tar.gz: ee0a1bc7822e5b0341dfaa883e83e79cbf2990de
3
+ metadata.gz: c5ca7c38be623e5e6c561330d317ea53d87e9104
4
+ data.tar.gz: e4db947176a1c349b99ae3600178027d8f7e6a12
5
5
  SHA512:
6
- metadata.gz: d463a38f32b8a5a53244dd9d4da8709baa25ecbfcaa79a2af1a58b5216e0c6234ed9b43afd51eba4dafd0914ed7f03cd5398451171a88c9eb201295a6919b933
7
- data.tar.gz: 241932016c5af72612812aba354f3f811d1dd9c2157524c4a6f8b5d12e38825f921220cae5994aef1a9bf96445feb555e99995028a0b67b5b09463b739d9bcc1
6
+ metadata.gz: bf1836cd6d83458cbf7385131ac3ce79e7dd8fa89127bf511bcaeaf828e20f1cc0e9e8802f92acddbf85f2e21975f5bce242e421395f8f55958068cf598d22e8
7
+ data.tar.gz: a6efea97a95056f55930cea606d6495d59118c2ebe38f02836a398626b8f8133a575c76c85322c4bda5c71f030ed65dc2de707b6fefaa4193f464e8bda326b68
data/Gemfile CHANGED
@@ -1,7 +1,13 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'rake', '~> 10.0'
3
4
  #gem 'unicode_utils', '1.4.0'
4
5
  #gem 'rest-client', '~> 1.8', '>= 1.8.0'
5
6
  gem 'curb', '~> 0.9', '>= 0.9.3'
6
7
  gem 'nokogiri', '~> 1.6', '>= 1.6.0'
7
8
  #gem 'progressbar', '0.21.0'
9
+ #gem 'sqlite3', '~> 1.3'
10
+
11
+ group :test do
12
+ gem 'rspec', '~> 3.4.0'
13
+ end
data/lib/kgmusic.rb CHANGED
@@ -7,16 +7,21 @@ module KgMusic
7
7
 
8
8
  class Artists < API::Artists; end
9
9
 
10
+ class Albums < API::Albums; end
11
+
12
+ class Collection < API::Collection::Generator; end
13
+
10
14
  class Downloader
11
15
 
12
16
  include BaseMod
13
17
 
14
- attr_reader :artist, :album
18
+ attr_reader :artist, :album, :work_dir
15
19
  attr_reader :direct_link
16
20
 
17
21
  def initialize(artist:, album:)
18
22
  @artist = validate(artist)
19
23
  @album = validate(album)
24
+ create_work_dir
20
25
  end
21
26
 
22
27
  protected
@@ -42,11 +47,9 @@ module KgMusic
42
47
  end
43
48
 
44
49
  def get_album
45
-
46
- app_root = File.join(ENV['HOME'], 'kgmusic')
47
50
  url = obtain_final_url @direct_link
48
- Dir.mkdir(app_root, 0700) unless Dir.exist?(app_root)
49
- outfile = File.join(app_root, "#{self.artist} - #{self.album}.zip")
51
+ create_work_dir
52
+ outfile = File.join(@work_dir, "#{self.artist} - #{self.album}.zip")
50
53
  content_length = get_content_length url
51
54
 
52
55
  begin
data/lib/kgmusic/api.rb CHANGED
@@ -1,2 +1,4 @@
1
1
  require 'kgmusic/api/client'
2
2
  require 'kgmusic/api/artists'
3
+ require 'kgmusic/api/albums'
4
+ require 'kgmusic/api/collection'
@@ -0,0 +1,49 @@
1
+ require 'curl'
2
+ require 'nokogiri'
3
+
4
+ module KgMusic
5
+ module API
6
+ class Albums
7
+ private_class_method :new
8
+
9
+ def initialize(url)
10
+ c = Curl::Easy.new(url) do |c|
11
+ c.follow_location = true
12
+ c.perform
13
+ end
14
+
15
+ @@root = Nokogiri::HTML.parse(c.body_str)
16
+ last_album_uri_str = @@root.xpath("//div[@class='pager']//li[@class='last']/a/@href").text
17
+ @@pages = last_album_uri_str.scan(/\d+$/).sample.to_i
18
+ end
19
+
20
+ private
21
+
22
+ def self.get_info
23
+ @@root.xpath("//div[@class='album-item clearfix']").reduce([]) do |out, list|
24
+ out << {
25
+ :artist => list.css('.album-desc/tr/td')[1].text.strip,
26
+ :album => list.css('.album-info/h3').text.strip,
27
+ :link => list.css('.album-info/h3/a/@href').children.to_s,
28
+ :year => list.css('.album-desc/tr/td')[3].text.strip,
29
+ :tags => list.css('.album-desc/tr/td')[5].text.strip
30
+ }
31
+ end
32
+ end
33
+
34
+ public
35
+
36
+ def self.show_info( number )
37
+ new("kibergrad.fm/albums")
38
+ if number == 1
39
+ get_info
40
+ elsif number.between?(1, @@pages)
41
+ new("kibergrad.fm/albums?page=#{number}"); get_info
42
+ else
43
+ raise RangeError
44
+ end
45
+ end
46
+
47
+ end # class Albums
48
+ end # module API
49
+ end # module KgMusic
@@ -9,7 +9,7 @@ module KgMusic
9
9
 
10
10
  private_class_method :new
11
11
 
12
- def initialize(url:)
12
+ def initialize(url)
13
13
  c = Curl::Easy.new(url) do |c|
14
14
  c.follow_location = true
15
15
  c.perform
@@ -38,13 +38,11 @@ module KgMusic
38
38
  public
39
39
 
40
40
  def self.show_info ( number )
41
-
42
- new(url: 'kibergrad.fm/artists')
43
-
41
+ new("kibergrad.fm/artists")
44
42
  if number == 1
45
43
  get_info
46
44
  elsif number.between?( 1, @@pages )
47
- new( url: "kibergrad.fm/artists?page=#{number}" )
45
+ new("kibergrad.fm/artists?page=#{number}")
48
46
  get_info
49
47
  else
50
48
  raise RangeError
@@ -0,0 +1 @@
1
+ require 'kgmusic/api/collection/generator'
@@ -0,0 +1,75 @@
1
+ require 'curl'
2
+ require 'nokogiri'
3
+
4
+ module KgMusic
5
+
6
+ module API
7
+
8
+ module Collection
9
+
10
+ class Generator
11
+
12
+ private_class_method :new
13
+
14
+ def initialize(url)
15
+ c = Curl::Easy.new(url) { |c| c.follow_location = true; c.perform }
16
+ root = Nokogiri::HTML.parse(c.body_str)
17
+ last_page_uri_str = root.xpath("//div[@class='pager']//li[@class='last']/a/@href").text
18
+ @@pages = last_page_uri_str.scan(/\d+$/).sample.to_i
19
+ end
20
+
21
+ def self.artists
22
+ new('kibergrad.fm/artists')
23
+ Fiber.new do
24
+ (1..@@pages).map do |page|
25
+ c = Curl::Easy.new("kibergrad.fm/artists?page=#{page}") do |c|
26
+ c.follow_location = true
27
+ c.perform
28
+ end
29
+ root = Nokogiri::HTML.parse(c.body_str)
30
+ result = root.xpath("//div[@class='artist-item']").reduce([]) do |out, artist|
31
+ out << {
32
+ :artist => artist.css('div.artist-info').at('a').text.strip,
33
+ :albums => artist.css('ul.artist-albums/li').reduce([]) { |albums, album| albums << album.at('img').attr('title') },
34
+ :tracks => artist.css('ul.artist-songs/li').reduce([]) { |tracks, track| tracks << track.css('a').text },
35
+ :all_albums => artist.css('div.albums-count').at('a').text.strip,
36
+ :all_tracks => artist.css('div.songs-count').at('a').text.strip
37
+ }
38
+ end
39
+ Fiber.yield result
40
+ end
41
+ end
42
+ end
43
+
44
+ def self.albums
45
+ new('kibergrad.fm/albums')
46
+
47
+ Fiber.new do
48
+ (1..@@pages).map do |page|
49
+ c = Curl::Easy.new("kibergrad.fm/albums?page=#{page}") do |c|
50
+ c.follow_location = true
51
+ c.perform
52
+ end
53
+
54
+ root = Nokogiri::HTML.parse(c.body_str)
55
+ result = root.xpath("//div[@class='album-item clearfix']").reduce([]) do |out, list|
56
+ out << {
57
+ :artist => list.css('.album-desc/tr/td')[1].text.strip,
58
+ :album => list.css('.album-info/h3').text.strip,
59
+ :link => list.css('.album-info/h3/a/@href').children.to_s,
60
+ :year => list.css('.album-desc/tr/td')[3].text.strip,
61
+ :tags => list.css('.album-desc/tr/td')[5].text.strip
62
+ }
63
+ end
64
+ Fiber.yield result
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -15,6 +15,11 @@ module KgMusic
15
15
  ]
16
16
 
17
17
  protected
18
+ def create_work_dir
19
+ @work_dir = File.join(ENV['HOME'], 'kgmusic')
20
+ Dir.mkdir(@work_dir, 0700) unless Dir.exist?(@work_dir)
21
+ end
22
+
18
23
  def go_to(url, params = {})
19
24
  __url = Curl.urlalize(url, params)
20
25
  c = Curl::Easy.new(__url) { |c| c.follow_location = true }
@@ -1,3 +1,3 @@
1
1
  module KgMusic
2
- VERSION = "0.1.0pre20160530"
2
+ VERSION = "0.1.0pre20160614"
3
3
  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.0pre20160530
4
+ version: 0.1.0pre20160614
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-30 00:00:00.000000000 Z
11
+ date: 2016-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
@@ -110,8 +110,11 @@ files:
110
110
  - kgmusic.gemspec
111
111
  - lib/kgmusic.rb
112
112
  - lib/kgmusic/api.rb
113
+ - lib/kgmusic/api/albums.rb
113
114
  - lib/kgmusic/api/artists.rb
114
115
  - lib/kgmusic/api/client.rb
116
+ - lib/kgmusic/api/collection.rb
117
+ - lib/kgmusic/api/collection/generator.rb
115
118
  - lib/kgmusic/base/basemod.rb
116
119
  - lib/kgmusic/basemod.rb
117
120
  - lib/kgmusic/version.rb